-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔖 release chopper_generator v7.1.1 (#563)
- Loading branch information
Showing
4 changed files
with
62 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,61 @@ | ||
import 'package:build/build.dart'; | ||
import 'package:chopper/chopper.dart' show ChopperApi; | ||
import 'package:source_gen/source_gen.dart'; | ||
import 'package:yaml/yaml.dart'; | ||
|
||
import 'generator.dart'; | ||
|
||
/// Creates a [PartBuilder] used to generate code for [ChopperApi] annotated | ||
/// classes. The [options] are provided by Dart's build system and read from the | ||
/// `build.yaml` file. | ||
Builder chopperGeneratorFactory(BuilderOptions options) => PartBuilder( | ||
Builder chopperGeneratorFactory(BuilderOptions options) { | ||
final String buildExtension = _getBuildExtension(options); | ||
|
||
return PartBuilder( | ||
[const ChopperGenerator()], | ||
buildExtension, | ||
header: options.config['header'], | ||
formatOutput: PartBuilder( | ||
[const ChopperGenerator()], | ||
'.chopper.dart', | ||
header: options.config['header'], | ||
formatOutput: | ||
PartBuilder([const ChopperGenerator()], '.chopper.dart').formatOutput, | ||
options: !options.config.containsKey('build_extensions') | ||
? options.overrideWith( | ||
BuilderOptions({ | ||
'build_extensions': {'.dart': '.chopper.dart'}, | ||
}), | ||
) | ||
: options, | ||
); | ||
buildExtension, | ||
).formatOutput, | ||
options: !options.config.containsKey('build_extensions') | ||
? options.overrideWith( | ||
BuilderOptions({ | ||
'build_extensions': { | ||
'.dart': [buildExtension] | ||
}, | ||
}), | ||
) | ||
: options, | ||
); | ||
} | ||
|
||
/// Returns the build extension for the generated file. | ||
/// | ||
/// If the `build.yaml` file contains a `build_extensions` key, it will be used | ||
/// to determine the extension. Otherwise, the default extension `.chopper.dart` | ||
/// will be used. | ||
/// | ||
/// Example `build.yaml`: | ||
/// | ||
/// ```yaml | ||
/// targets: | ||
/// $default: | ||
/// builders: | ||
/// chopper_generator: | ||
/// options: | ||
/// build_extensions: {".dart": [".chopper.g.dart"]} | ||
/// ``` | ||
String _getBuildExtension(BuilderOptions options) { | ||
if (options.config.containsKey('build_extensions')) { | ||
final YamlMap buildExtensions = options.config['build_extensions']; | ||
if (buildExtensions.containsKey('.dart')) { | ||
final YamlList dartBuildExtensions = buildExtensions['.dart']; | ||
if (dartBuildExtensions.isNotEmpty) { | ||
return dartBuildExtensions.first; | ||
} | ||
} | ||
} | ||
return '.chopper.dart'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters