Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add preamble for dart generated files #1949

Merged
merged 9 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frb_codegen/src/binary/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ pub(crate) struct GenerateCommandArgsPrimary {
#[arg(long)]
pub dart_format_line_length: Option<u32>,

/// Raw header of output generated Dart code, pasted as-it-is.
#[arg(long)]
pub dart_preamble: Option<String>,

/// The generated Dart enums will not have their variant names camelCased.
#[arg(long)]
pub no_dart_enums_style: bool,
Expand Down
1 change: 1 addition & 0 deletions frb_codegen/src/binary/commands_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fn compute_codegen_config_from_naive_command_args(
rust_output: args.rust_output,
dart_entrypoint_class_name: args.dart_entrypoint_class_name,
dart_format_line_length: args.dart_format_line_length,
dart_preamble: args.dart_preamble,
dart_enums_style: Some(!args.no_dart_enums_style),
add_mod_to_lib: Some(!args.no_add_mod_to_lib),
llvm_path: args.llvm_path,
Expand Down
1 change: 1 addition & 0 deletions frb_codegen/src/library/codegen/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Config {
pub rust_output: Option<String>,
pub dart_entrypoint_class_name: Option<String>,
pub dart_format_line_length: Option<u32>,
pub dart_preamble: Option<String>,
pub dart_enums_style: Option<bool>,
pub add_mod_to_lib: Option<bool>,
pub llvm_path: Option<Vec<String>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl InternalConfig {
dart_entrypoint_class_name: dart_output_class_name_pack
.entrypoint_class_name
.clone(),
dart_preamble: config.dart_preamble.clone().unwrap_or_default(),
},
wire: GeneratorWireInternalConfig {
dart: GeneratorWireDartInternalConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub(crate) struct GeneratorApiDartInternalConfig {
pub dart3: bool,
pub dart_decl_base_output_path: PathBuf,
pub dart_entrypoint_class_name: String,
pub dart_preamble: String,
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ fn generate_boilerplate(
..
} = &context.config.dart_output_class_name_pack;

let dart_preamble = &context.api_dart_config.dart_preamble.as_str();
let file_top = generate_code_header()
+ if !dart_preamble.is_empty() {"\n\n"} else {""} + dart_preamble
+ "\n\n// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field\n";

let mut universal_imports = generate_import_dart_api_layer(
Expand Down
Loading