Skip to content

Commit

Permalink
🔖 release chopper_generator v7.1.1 (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse authored Jan 22, 2024
1 parent 165d361 commit 56c1ce0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
target-branch: "develop"
- package-ecosystem: "pub"
directory: "/chopper"
schedule:
Expand Down
4 changes: 4 additions & 0 deletions chopper_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 7.1.1

- Add option to override build_extension via build.yaml ([#562](https://github.com/lejard-h/chopper/pull/562))

## 7.1.0

- Add ability to omit `Response` in service ([#545](https://github.com/lejard-h/chopper/pull/545))
Expand Down
64 changes: 51 additions & 13 deletions chopper_generator/lib/src/builder_factory.dart
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';
}
3 changes: 2 additions & 1 deletion chopper_generator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: chopper_generator
description: Chopper is an http client generator using source_gen, inspired by Retrofit
version: 7.1.0
version: 7.1.1
documentation: https://hadrien-lejard.gitbook.io/chopper
repository: https://github.com/lejard-h/chopper

Expand All @@ -17,6 +17,7 @@ dependencies:
logging: ^1.2.0
meta: ^1.9.1
source_gen: ^1.4.0
yaml: ^3.1.2

dev_dependencies:
build_runner: ^2.4.6
Expand Down

0 comments on commit 56c1ce0

Please sign in to comment.