From b4795e52ed8652f860ce419b60a2f667de013dc0 Mon Sep 17 00:00:00 2001 From: Mao Date: Tue, 2 Feb 2021 09:36:12 +0900 Subject: [PATCH 01/14] Raw impl --- _internal/build.yaml | 17 ++ _internal/lib/src/example.dart | 142 ++++++++++++ _internal/pubspec.lock | 411 +++++++++++++++++++++++++++++++++ _internal/pubspec.yaml | 16 ++ build.yaml | 16 ++ 5 files changed, 602 insertions(+) create mode 100644 _internal/build.yaml create mode 100644 _internal/lib/src/example.dart create mode 100644 _internal/pubspec.lock create mode 100644 _internal/pubspec.yaml diff --git a/_internal/build.yaml b/_internal/build.yaml new file mode 100644 index 00000000..dd37496b --- /dev/null +++ b/_internal/build.yaml @@ -0,0 +1,17 @@ +targets: + $default: + builders: + json_serializable: + options: + any_map: true + checked: true + create_factory: true + create_to_json: true + disallow_unrecognized_keys: false + explicit_to_json: false + field_rename: none + generic_argument_factories: false + ignore_unannotated: false + include_if_null: true + nullable: true + diff --git a/_internal/lib/src/example.dart b/_internal/lib/src/example.dart new file mode 100644 index 00000000..e4bea3a2 --- /dev/null +++ b/_internal/lib/src/example.dart @@ -0,0 +1,142 @@ +import 'dart:io'; + +import 'package:json_annotation/json_annotation.dart'; + +part 'example.g.dart'; + +@JsonSerializable() +class PubSpec { + PubSpec({this.flutterGen, this.flutter}); + + @JsonKey(name: 'flutter_gen', required: true) + final FlutterGen flutterGen; + + @JsonKey(name: 'flutter') + final Flutter flutter; + + factory PubSpec.fromJson(Map json) => _$PubSpecFromJson(json); + + Map toJson() => _$PubSpecToJson(this); +} + +@JsonSerializable() +class Flutter { + Flutter({this.assets, this.fonts}) { + if (assets.isEmpty) { + throw ArgumentError.value(assets, 'assets', 'Cannot be empty'); + } + } + + @JsonKey(name: 'assets') + final List assets; + + @JsonKey(name: 'fonts') + final List fonts; + + factory Flutter.fromJson(Map json) => _$FlutterFromJson(json); + + Map toJson() => _$FlutterToJson(this); +} + +@JsonSerializable() +class FlutterFonts { + FlutterFonts({this.family}) { + if (family.isEmpty) { + throw ArgumentError.value(family, 'family', 'Cannot be empty'); + } + } + + @JsonKey(name: 'family', required: true) + final String family; + + factory FlutterFonts.fromJson(Map json) => _$FlutterFontsFromJson(json); + + Map toJson() => _$FlutterFontsToJson(this); +} + +@JsonSerializable() +class FlutterGen { + FlutterGen({output, this.lineLength, this.assets}) + : output = output ?? Config.defaultOutput { + if (!FileSystemEntity.isDirectorySync(output)) { + throw ArgumentError.value(output, 'output', 'Must be a valid directory.'); + } + } + + @JsonKey(name: 'output') + final String output; + + @JsonKey(name: 'lineLength', defaultValue: 80) + final int lineLength; + + @JsonKey(name: 'assets') + final FlutterGenAssets assets; + + factory FlutterGen.fromJson(Map json) => _$FlutterGenFromJson(json); + + Map toJson() => _$FlutterGenToJson(this); +} + +@JsonSerializable() +class FlutterGenColors { + FlutterGenColors({this.inputs}) { + if (inputs.isEmpty) { + throw ArgumentError.value(inputs, 'inputs', 'Cannot be empty.'); + } + } + + @JsonKey(name: 'inputs', required: true) + final List inputs; + + bool get hasInputs => inputs != null && inputs.isNotEmpty; + + factory FlutterGenColors.fromJson(Map json) => + _$FlutterGenColorsFromJson(json); + + Map toJson() => _$FlutterGenColorsToJson(this); +} + +@JsonSerializable() +class FlutterGenAssets { + static const String dotDelimiterStyle = 'dot-delimiter'; + static const String snakeCaseStyle = 'snake-case'; + static const String camelCaseStyle = 'camel-case'; + + FlutterGenAssets({this.style}) { + if (style != dotDelimiterStyle || + style != snakeCaseStyle || + style != camelCaseStyle) { + throw ArgumentError.value(style, 'style', 'Invalid style.'); + } + } + + @JsonKey(name: 'style', defaultValue: dotDelimiterStyle) + final String style; + + bool get isDotDelimiterStyle => style == dotDelimiterStyle; + + bool get isSnakeCaseStyle => style == snakeCaseStyle; + + bool get isCamelCaseStyle => style == camelCaseStyle; + + factory FlutterGenAssets.fromJson(Map json) => + _$FlutterGenAssetsFromJson(json); + + Map toJson() => _$FlutterGenAssetsToJson(this); +} + +@JsonSerializable() +class FlutterGenIntegrations { + FlutterGenIntegrations({this.flutterSvg, this.flareFlutter}); + + @JsonKey(name: 'flutter_svg', defaultValue: false) + final bool flutterSvg; + + @JsonKey(name: 'flare_flutter', defaultValue: false) + final bool flareFlutter; + + factory FlutterGenIntegrations.fromJson(Map json) => + _$FlutterGenIntegrationsFromJson(json); + + Map toJson() => _$FlutterGenIntegrationsToJson(this); +} diff --git a/_internal/pubspec.lock b/_internal/pubspec.lock new file mode 100644 index 00000000..f9e36385 --- /dev/null +++ b/_internal/pubspec.lock @@ -0,0 +1,411 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "14.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + url: "https://pub.dartlang.org" + source: hosted + version: "0.41.2" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.0" + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.2" + build: + dependency: transitive + description: + name: build + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.2" + build_config: + dependency: transitive + description: + name: build_config + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.5" + build_daemon: + dependency: transitive + description: + name: build_daemon + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.7" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.3" + build_runner: + dependency: "direct dev" + description: + name: build_runner + url: "https://pub.dartlang.org" + source: hosted + version: "1.11.1" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.7" + built_collection: + dependency: transitive + description: + name: built_collection + url: "https://pub.dartlang.org" + source: hosted + version: "4.3.2" + built_value: + dependency: transitive + description: + name: built_value + url: "https://pub.dartlang.org" + source: hosted + version: "7.1.0" + charcode: + dependency: transitive + description: + name: charcode + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.3" + checked_yaml: + dependency: "direct dev" + description: + name: checked_yaml + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + cli_util: + dependency: transitive + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" + code_builder: + dependency: transitive + description: + name: code_builder + url: "https://pub.dartlang.org" + source: hosted + version: "3.6.0" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.14.13" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.5" + dart_style: + dependency: transitive + description: + name: dart_style + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.11" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "5.2.1" + fixnum: + dependency: transitive + description: + name: fixnum + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.11" + glob: + dependency: transitive + description: + name: glob + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + graphs: + dependency: transitive + description: + name: graphs + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.4" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" + io: + dependency: transitive + description: + name: io + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.4" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.2" + json_annotation: + dependency: "direct main" + description: + name: json_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.1" + json_serializable: + dependency: "direct dev" + description: + name: json_serializable + url: "https://pub.dartlang.org" + source: hosted + version: "3.5.1" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.dartlang.org" + source: hosted + version: "0.11.4" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.9" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.4" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.7" + node_interop: + dependency: transitive + description: + name: node_interop + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + node_io: + dependency: transitive + description: + name: node_io + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.3" + path: + dependency: "direct main" + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.7.0" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.2" + pool: + dependency: transitive + description: + name: pool + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.0" + pub_semver: + dependency: transitive + description: + name: pub_semver + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.4" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.7" + quiver: + dependency: transitive + description: + name: quiver + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.5" + shelf: + dependency: transitive + description: + name: shelf + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.9" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.4" + source_gen: + dependency: transitive + description: + name: source_gen + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.10+1" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.7.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.6" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + stream_transform: + dependency: transitive + description: + name: stream_transform + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.5" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + timing: + dependency: transitive + description: + name: timing + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.1+3" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + watcher: + dependency: transitive + description: + name: watcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.7+15" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + yaml: + dependency: transitive + description: + name: yaml + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" +sdks: + dart: ">=2.10.0 <3.0.0" diff --git a/_internal/pubspec.yaml b/_internal/pubspec.yaml new file mode 100644 index 00000000..3b9cc225 --- /dev/null +++ b/_internal/pubspec.yaml @@ -0,0 +1,16 @@ +name: _internal +description: A starting point for Dart libraries or applications. +# version: 1.0.0 +# homepage: https://www.example.com + +environment: + sdk: '>=2.8.1 <3.0.0' + +dependencies: + path: ^1.7.0 + json_annotation: ^3.1.1 + +dev_dependencies: + build_runner: + json_serializable: ^3.5.1 + checked_yaml: ^1.0.4 diff --git a/build.yaml b/build.yaml index 972bd7d0..c67b5bd9 100644 --- a/build.yaml +++ b/build.yaml @@ -3,6 +3,22 @@ targets: builders: flutter_gen: enabled: true +# flutter_gen:json: +# builders: +# json_serializable: +# options: +# any_map: true +# checked: true +# create_factory: true +# create_to_json: true +# disallow_unrecognized_keys: false +# explicit_to_json: false +# field_rename: none +# generic_argument_factories: false +# ignore_unannotated: false +# include_if_null: true +# nullable: true + builders: flutter_gen: From 1cc114f2dce585accfce4ac8adf0a358c9a1a573 Mon Sep 17 00:00:00 2001 From: Mao Date: Tue, 2 Feb 2021 10:01:54 +0900 Subject: [PATCH 02/14] Refactor pubspec --- Makefile | 4 + .../lib/src/{example.dart => pubspec.dart} | 41 ++--- _internal/lib/src/pubspec.g.dart | 138 +++++++++++++++++ lib/src/settings/pubspec.dart | 143 ++++++++++++++++++ lib/src/settings/pubspec.g.dart | 138 +++++++++++++++++ 5 files changed, 444 insertions(+), 20 deletions(-) rename _internal/lib/src/{example.dart => pubspec.dart} (78%) create mode 100644 _internal/lib/src/pubspec.g.dart create mode 100644 lib/src/settings/pubspec.dart create mode 100644 lib/src/settings/pubspec.g.dart diff --git a/Makefile b/Makefile index f812ad35..8bb99d93 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,10 @@ format: build: cd example && flutter build apk && cd .. +generate-config-model: + cd _internal && dart pub run build_runner build && cd .. + cp _internal/lib/src/* lib/src/settings + generate-with-command: dart bin/flutter_gen_command.dart --config example/pubspec.yaml diff --git a/_internal/lib/src/example.dart b/_internal/lib/src/pubspec.dart similarity index 78% rename from _internal/lib/src/example.dart rename to _internal/lib/src/pubspec.dart index e4bea3a2..e5026e04 100644 --- a/_internal/lib/src/example.dart +++ b/_internal/lib/src/pubspec.dart @@ -1,22 +1,24 @@ import 'dart:io'; import 'package:json_annotation/json_annotation.dart'; +import 'package:path/path.dart'; -part 'example.g.dart'; +part 'pubspec.g.dart'; + +final String _defaultOutput = 'lib${separator}gen$separator'; +const int _defaultLineLength = 80; @JsonSerializable() class PubSpec { PubSpec({this.flutterGen, this.flutter}); - @JsonKey(name: 'flutter_gen', required: true) + @JsonKey(name: 'flutter_gen') final FlutterGen flutterGen; @JsonKey(name: 'flutter') final Flutter flutter; factory PubSpec.fromJson(Map json) => _$PubSpecFromJson(json); - - Map toJson() => _$PubSpecToJson(this); } @JsonSerializable() @@ -25,6 +27,9 @@ class Flutter { if (assets.isEmpty) { throw ArgumentError.value(assets, 'assets', 'Cannot be empty'); } + if (fonts.isEmpty) { + throw ArgumentError.value(assets, 'fonts', 'Cannot be empty'); + } } @JsonKey(name: 'assets') @@ -34,8 +39,6 @@ class Flutter { final List fonts; factory Flutter.fromJson(Map json) => _$FlutterFromJson(json); - - Map toJson() => _$FlutterToJson(this); } @JsonSerializable() @@ -50,31 +53,35 @@ class FlutterFonts { final String family; factory FlutterFonts.fromJson(Map json) => _$FlutterFontsFromJson(json); - - Map toJson() => _$FlutterFontsToJson(this); } @JsonSerializable() class FlutterGen { - FlutterGen({output, this.lineLength, this.assets}) - : output = output ?? Config.defaultOutput { - if (!FileSystemEntity.isDirectorySync(output)) { + FlutterGen({output, lineLength, this.deprecatedLineLength, this.assets}) + : output = output ?? _defaultOutput, + lineLength = lineLength ?? deprecatedLineLength ?? _defaultLineLength { + if (!FileSystemEntity.isDirectorySync(this.output)) { throw ArgumentError.value(output, 'output', 'Must be a valid directory.'); } + if (deprecatedLineLength != null) { + print('Warning: key lineLength is deprecated, use line_length instead.'); + } } @JsonKey(name: 'output') final String output; - @JsonKey(name: 'lineLength', defaultValue: 80) + @JsonKey(name: 'line_length', defaultValue: _defaultLineLength) final int lineLength; + @deprecated + @JsonKey(name: 'lineLength') + final int deprecatedLineLength; + @JsonKey(name: 'assets') final FlutterGenAssets assets; factory FlutterGen.fromJson(Map json) => _$FlutterGenFromJson(json); - - Map toJson() => _$FlutterGenToJson(this); } @JsonSerializable() @@ -92,8 +99,6 @@ class FlutterGenColors { factory FlutterGenColors.fromJson(Map json) => _$FlutterGenColorsFromJson(json); - - Map toJson() => _$FlutterGenColorsToJson(this); } @JsonSerializable() @@ -121,8 +126,6 @@ class FlutterGenAssets { factory FlutterGenAssets.fromJson(Map json) => _$FlutterGenAssetsFromJson(json); - - Map toJson() => _$FlutterGenAssetsToJson(this); } @JsonSerializable() @@ -137,6 +140,4 @@ class FlutterGenIntegrations { factory FlutterGenIntegrations.fromJson(Map json) => _$FlutterGenIntegrationsFromJson(json); - - Map toJson() => _$FlutterGenIntegrationsToJson(this); } diff --git a/_internal/lib/src/pubspec.g.dart b/_internal/lib/src/pubspec.g.dart new file mode 100644 index 00000000..40341fdc --- /dev/null +++ b/_internal/lib/src/pubspec.g.dart @@ -0,0 +1,138 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'pubspec.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PubSpec _$PubSpecFromJson(Map json) { + return $checkedNew('PubSpec', json, () { + final val = PubSpec( + flutterGen: $checkedConvert(json, 'flutter_gen', + (v) => v == null ? null : FlutterGen.fromJson(v as Map)), + flutter: $checkedConvert(json, 'flutter', + (v) => v == null ? null : Flutter.fromJson(v as Map)), + ); + return val; + }, fieldKeyMap: const {'flutterGen': 'flutter_gen'}); +} + +Map _$PubSpecToJson(PubSpec instance) => { + 'flutter_gen': instance.flutterGen, + 'flutter': instance.flutter, + }; + +Flutter _$FlutterFromJson(Map json) { + return $checkedNew('Flutter', json, () { + final val = Flutter( + assets: $checkedConvert(json, 'assets', + (v) => (v as List)?.map((e) => e as String)?.toList()), + fonts: $checkedConvert( + json, + 'fonts', + (v) => (v as List) + ?.map((e) => e == null ? null : FlutterFonts.fromJson(e as Map)) + ?.toList()), + ); + return val; + }); +} + +Map _$FlutterToJson(Flutter instance) => { + 'assets': instance.assets, + 'fonts': instance.fonts, + }; + +FlutterFonts _$FlutterFontsFromJson(Map json) { + return $checkedNew('FlutterFonts', json, () { + $checkKeys(json, requiredKeys: const ['family']); + final val = FlutterFonts( + family: $checkedConvert(json, 'family', (v) => v as String), + ); + return val; + }); +} + +Map _$FlutterFontsToJson(FlutterFonts instance) => + { + 'family': instance.family, + }; + +FlutterGen _$FlutterGenFromJson(Map json) { + return $checkedNew('FlutterGen', json, () { + final val = FlutterGen( + output: $checkedConvert(json, 'output', (v) => v), + lineLength: $checkedConvert(json, 'line_length', (v) => v) ?? 80, + deprecatedLineLength: + $checkedConvert(json, 'lineLength', (v) => v as int), + assets: $checkedConvert(json, 'assets', + (v) => v == null ? null : FlutterGenAssets.fromJson(v as Map)), + ); + return val; + }, fieldKeyMap: const { + 'lineLength': 'line_length', + 'deprecatedLineLength': 'lineLength' + }); +} + +Map _$FlutterGenToJson(FlutterGen instance) => + { + 'output': instance.output, + 'line_length': instance.lineLength, + 'lineLength': instance.deprecatedLineLength, + 'assets': instance.assets, + }; + +FlutterGenColors _$FlutterGenColorsFromJson(Map json) { + return $checkedNew('FlutterGenColors', json, () { + $checkKeys(json, requiredKeys: const ['inputs']); + final val = FlutterGenColors( + inputs: $checkedConvert(json, 'inputs', + (v) => (v as List)?.map((e) => e as String)?.toList()), + ); + return val; + }); +} + +Map _$FlutterGenColorsToJson(FlutterGenColors instance) => + { + 'inputs': instance.inputs, + }; + +FlutterGenAssets _$FlutterGenAssetsFromJson(Map json) { + return $checkedNew('FlutterGenAssets', json, () { + final val = FlutterGenAssets( + style: + $checkedConvert(json, 'style', (v) => v as String) ?? 'dot-delimiter', + ); + return val; + }); +} + +Map _$FlutterGenAssetsToJson(FlutterGenAssets instance) => + { + 'style': instance.style, + }; + +FlutterGenIntegrations _$FlutterGenIntegrationsFromJson(Map json) { + return $checkedNew('FlutterGenIntegrations', json, () { + final val = FlutterGenIntegrations( + flutterSvg: + $checkedConvert(json, 'flutter_svg', (v) => v as bool) ?? false, + flareFlutter: + $checkedConvert(json, 'flare_flutter', (v) => v as bool) ?? false, + ); + return val; + }, fieldKeyMap: const { + 'flutterSvg': 'flutter_svg', + 'flareFlutter': 'flare_flutter' + }); +} + +Map _$FlutterGenIntegrationsToJson( + FlutterGenIntegrations instance) => + { + 'flutter_svg': instance.flutterSvg, + 'flare_flutter': instance.flareFlutter, + }; diff --git a/lib/src/settings/pubspec.dart b/lib/src/settings/pubspec.dart new file mode 100644 index 00000000..e5026e04 --- /dev/null +++ b/lib/src/settings/pubspec.dart @@ -0,0 +1,143 @@ +import 'dart:io'; + +import 'package:json_annotation/json_annotation.dart'; +import 'package:path/path.dart'; + +part 'pubspec.g.dart'; + +final String _defaultOutput = 'lib${separator}gen$separator'; +const int _defaultLineLength = 80; + +@JsonSerializable() +class PubSpec { + PubSpec({this.flutterGen, this.flutter}); + + @JsonKey(name: 'flutter_gen') + final FlutterGen flutterGen; + + @JsonKey(name: 'flutter') + final Flutter flutter; + + factory PubSpec.fromJson(Map json) => _$PubSpecFromJson(json); +} + +@JsonSerializable() +class Flutter { + Flutter({this.assets, this.fonts}) { + if (assets.isEmpty) { + throw ArgumentError.value(assets, 'assets', 'Cannot be empty'); + } + if (fonts.isEmpty) { + throw ArgumentError.value(assets, 'fonts', 'Cannot be empty'); + } + } + + @JsonKey(name: 'assets') + final List assets; + + @JsonKey(name: 'fonts') + final List fonts; + + factory Flutter.fromJson(Map json) => _$FlutterFromJson(json); +} + +@JsonSerializable() +class FlutterFonts { + FlutterFonts({this.family}) { + if (family.isEmpty) { + throw ArgumentError.value(family, 'family', 'Cannot be empty'); + } + } + + @JsonKey(name: 'family', required: true) + final String family; + + factory FlutterFonts.fromJson(Map json) => _$FlutterFontsFromJson(json); +} + +@JsonSerializable() +class FlutterGen { + FlutterGen({output, lineLength, this.deprecatedLineLength, this.assets}) + : output = output ?? _defaultOutput, + lineLength = lineLength ?? deprecatedLineLength ?? _defaultLineLength { + if (!FileSystemEntity.isDirectorySync(this.output)) { + throw ArgumentError.value(output, 'output', 'Must be a valid directory.'); + } + if (deprecatedLineLength != null) { + print('Warning: key lineLength is deprecated, use line_length instead.'); + } + } + + @JsonKey(name: 'output') + final String output; + + @JsonKey(name: 'line_length', defaultValue: _defaultLineLength) + final int lineLength; + + @deprecated + @JsonKey(name: 'lineLength') + final int deprecatedLineLength; + + @JsonKey(name: 'assets') + final FlutterGenAssets assets; + + factory FlutterGen.fromJson(Map json) => _$FlutterGenFromJson(json); +} + +@JsonSerializable() +class FlutterGenColors { + FlutterGenColors({this.inputs}) { + if (inputs.isEmpty) { + throw ArgumentError.value(inputs, 'inputs', 'Cannot be empty.'); + } + } + + @JsonKey(name: 'inputs', required: true) + final List inputs; + + bool get hasInputs => inputs != null && inputs.isNotEmpty; + + factory FlutterGenColors.fromJson(Map json) => + _$FlutterGenColorsFromJson(json); +} + +@JsonSerializable() +class FlutterGenAssets { + static const String dotDelimiterStyle = 'dot-delimiter'; + static const String snakeCaseStyle = 'snake-case'; + static const String camelCaseStyle = 'camel-case'; + + FlutterGenAssets({this.style}) { + if (style != dotDelimiterStyle || + style != snakeCaseStyle || + style != camelCaseStyle) { + throw ArgumentError.value(style, 'style', 'Invalid style.'); + } + } + + @JsonKey(name: 'style', defaultValue: dotDelimiterStyle) + final String style; + + bool get isDotDelimiterStyle => style == dotDelimiterStyle; + + bool get isSnakeCaseStyle => style == snakeCaseStyle; + + bool get isCamelCaseStyle => style == camelCaseStyle; + + factory FlutterGenAssets.fromJson(Map json) => + _$FlutterGenAssetsFromJson(json); +} + +@JsonSerializable() +class FlutterGenIntegrations { + FlutterGenIntegrations({this.flutterSvg, this.flareFlutter}); + + @JsonKey(name: 'flutter_svg', defaultValue: false) + final bool flutterSvg; + + @JsonKey(name: 'flare_flutter', defaultValue: false) + final bool flareFlutter; + + factory FlutterGenIntegrations.fromJson(Map json) => + _$FlutterGenIntegrationsFromJson(json); +} diff --git a/lib/src/settings/pubspec.g.dart b/lib/src/settings/pubspec.g.dart new file mode 100644 index 00000000..40341fdc --- /dev/null +++ b/lib/src/settings/pubspec.g.dart @@ -0,0 +1,138 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'pubspec.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PubSpec _$PubSpecFromJson(Map json) { + return $checkedNew('PubSpec', json, () { + final val = PubSpec( + flutterGen: $checkedConvert(json, 'flutter_gen', + (v) => v == null ? null : FlutterGen.fromJson(v as Map)), + flutter: $checkedConvert(json, 'flutter', + (v) => v == null ? null : Flutter.fromJson(v as Map)), + ); + return val; + }, fieldKeyMap: const {'flutterGen': 'flutter_gen'}); +} + +Map _$PubSpecToJson(PubSpec instance) => { + 'flutter_gen': instance.flutterGen, + 'flutter': instance.flutter, + }; + +Flutter _$FlutterFromJson(Map json) { + return $checkedNew('Flutter', json, () { + final val = Flutter( + assets: $checkedConvert(json, 'assets', + (v) => (v as List)?.map((e) => e as String)?.toList()), + fonts: $checkedConvert( + json, + 'fonts', + (v) => (v as List) + ?.map((e) => e == null ? null : FlutterFonts.fromJson(e as Map)) + ?.toList()), + ); + return val; + }); +} + +Map _$FlutterToJson(Flutter instance) => { + 'assets': instance.assets, + 'fonts': instance.fonts, + }; + +FlutterFonts _$FlutterFontsFromJson(Map json) { + return $checkedNew('FlutterFonts', json, () { + $checkKeys(json, requiredKeys: const ['family']); + final val = FlutterFonts( + family: $checkedConvert(json, 'family', (v) => v as String), + ); + return val; + }); +} + +Map _$FlutterFontsToJson(FlutterFonts instance) => + { + 'family': instance.family, + }; + +FlutterGen _$FlutterGenFromJson(Map json) { + return $checkedNew('FlutterGen', json, () { + final val = FlutterGen( + output: $checkedConvert(json, 'output', (v) => v), + lineLength: $checkedConvert(json, 'line_length', (v) => v) ?? 80, + deprecatedLineLength: + $checkedConvert(json, 'lineLength', (v) => v as int), + assets: $checkedConvert(json, 'assets', + (v) => v == null ? null : FlutterGenAssets.fromJson(v as Map)), + ); + return val; + }, fieldKeyMap: const { + 'lineLength': 'line_length', + 'deprecatedLineLength': 'lineLength' + }); +} + +Map _$FlutterGenToJson(FlutterGen instance) => + { + 'output': instance.output, + 'line_length': instance.lineLength, + 'lineLength': instance.deprecatedLineLength, + 'assets': instance.assets, + }; + +FlutterGenColors _$FlutterGenColorsFromJson(Map json) { + return $checkedNew('FlutterGenColors', json, () { + $checkKeys(json, requiredKeys: const ['inputs']); + final val = FlutterGenColors( + inputs: $checkedConvert(json, 'inputs', + (v) => (v as List)?.map((e) => e as String)?.toList()), + ); + return val; + }); +} + +Map _$FlutterGenColorsToJson(FlutterGenColors instance) => + { + 'inputs': instance.inputs, + }; + +FlutterGenAssets _$FlutterGenAssetsFromJson(Map json) { + return $checkedNew('FlutterGenAssets', json, () { + final val = FlutterGenAssets( + style: + $checkedConvert(json, 'style', (v) => v as String) ?? 'dot-delimiter', + ); + return val; + }); +} + +Map _$FlutterGenAssetsToJson(FlutterGenAssets instance) => + { + 'style': instance.style, + }; + +FlutterGenIntegrations _$FlutterGenIntegrationsFromJson(Map json) { + return $checkedNew('FlutterGenIntegrations', json, () { + final val = FlutterGenIntegrations( + flutterSvg: + $checkedConvert(json, 'flutter_svg', (v) => v as bool) ?? false, + flareFlutter: + $checkedConvert(json, 'flare_flutter', (v) => v as bool) ?? false, + ); + return val; + }, fieldKeyMap: const { + 'flutterSvg': 'flutter_svg', + 'flareFlutter': 'flare_flutter' + }); +} + +Map _$FlutterGenIntegrationsToJson( + FlutterGenIntegrations instance) => + { + 'flutter_svg': instance.flutterSvg, + 'flare_flutter': instance.flareFlutter, + }; From 4d233e9d338a669d0103d93b045dafecdbf62501 Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 6 Feb 2021 12:33:36 +0900 Subject: [PATCH 03/14] Update config definition --- _internal/lib/src/pubspec.dart | 76 ++++++++++++++------------------ _internal/lib/src/pubspec.g.dart | 31 +++++++++---- _internal/pubspec.lock | 2 +- _internal/pubspec.yaml | 1 - 4 files changed, 57 insertions(+), 53 deletions(-) diff --git a/_internal/lib/src/pubspec.dart b/_internal/lib/src/pubspec.dart index e5026e04..81f2be3a 100644 --- a/_internal/lib/src/pubspec.dart +++ b/_internal/lib/src/pubspec.dart @@ -1,21 +1,17 @@ import 'dart:io'; import 'package:json_annotation/json_annotation.dart'; -import 'package:path/path.dart'; part 'pubspec.g.dart'; -final String _defaultOutput = 'lib${separator}gen$separator'; -const int _defaultLineLength = 80; - @JsonSerializable() class PubSpec { PubSpec({this.flutterGen, this.flutter}); - @JsonKey(name: 'flutter_gen') + @JsonKey(name: 'flutter_gen', required: true) final FlutterGen flutterGen; - @JsonKey(name: 'flutter') + @JsonKey(name: 'flutter', required: true) final Flutter flutter; factory PubSpec.fromJson(Map json) => _$PubSpecFromJson(json); @@ -23,19 +19,12 @@ class PubSpec { @JsonSerializable() class Flutter { - Flutter({this.assets, this.fonts}) { - if (assets.isEmpty) { - throw ArgumentError.value(assets, 'assets', 'Cannot be empty'); - } - if (fonts.isEmpty) { - throw ArgumentError.value(assets, 'fonts', 'Cannot be empty'); - } - } + Flutter({this.assets, this.fonts}); - @JsonKey(name: 'assets') + @JsonKey(name: 'assets', required: true) final List assets; - @JsonKey(name: 'fonts') + @JsonKey(name: 'fonts', required: true) final List fonts; factory Flutter.fromJson(Map json) => _$FlutterFromJson(json); @@ -43,11 +32,7 @@ class Flutter { @JsonSerializable() class FlutterFonts { - FlutterFonts({this.family}) { - if (family.isEmpty) { - throw ArgumentError.value(family, 'family', 'Cannot be empty'); - } - } + FlutterFonts({this.family}); @JsonKey(name: 'family', required: true) final String family; @@ -57,46 +42,51 @@ class FlutterFonts { @JsonSerializable() class FlutterGen { - FlutterGen({output, lineLength, this.deprecatedLineLength, this.assets}) - : output = output ?? _defaultOutput, - lineLength = lineLength ?? deprecatedLineLength ?? _defaultLineLength { - if (!FileSystemEntity.isDirectorySync(this.output)) { - throw ArgumentError.value(output, 'output', 'Must be a valid directory.'); + FlutterGen({ + this.output, + this.lineLength, + this.deprecatedLineLength, + this.assets, + this.integrations, + this.colors, + }) { + if (!FileSystemEntity.isDirectorySync(output)) { + throw ArgumentError.value(output, 'output'); } if (deprecatedLineLength != null) { print('Warning: key lineLength is deprecated, use line_length instead.'); } } - @JsonKey(name: 'output') + @JsonKey(name: 'output', required: true) final String output; - @JsonKey(name: 'line_length', defaultValue: _defaultLineLength) + @JsonKey(name: 'line_length', required: true) final int lineLength; @deprecated - @JsonKey(name: 'lineLength') + @JsonKey(name: 'lineLength', required: true) final int deprecatedLineLength; - @JsonKey(name: 'assets') + @JsonKey(name: 'assets', required: true) final FlutterGenAssets assets; + @JsonKey(name: 'integrations', required: true) + final FlutterGenIntegrations integrations; + + @JsonKey(name: 'colors', required: true) + final FlutterGenColors colors; + factory FlutterGen.fromJson(Map json) => _$FlutterGenFromJson(json); } @JsonSerializable() class FlutterGenColors { - FlutterGenColors({this.inputs}) { - if (inputs.isEmpty) { - throw ArgumentError.value(inputs, 'inputs', 'Cannot be empty.'); - } - } + FlutterGenColors({this.inputs}); @JsonKey(name: 'inputs', required: true) final List inputs; - bool get hasInputs => inputs != null && inputs.isNotEmpty; - factory FlutterGenColors.fromJson(Map json) => _$FlutterGenColorsFromJson(json); } @@ -108,14 +98,14 @@ class FlutterGenAssets { static const String camelCaseStyle = 'camel-case'; FlutterGenAssets({this.style}) { - if (style != dotDelimiterStyle || - style != snakeCaseStyle || + if (style != dotDelimiterStyle && + style != snakeCaseStyle && style != camelCaseStyle) { - throw ArgumentError.value(style, 'style', 'Invalid style.'); + throw ArgumentError.value(style, 'style'); } } - @JsonKey(name: 'style', defaultValue: dotDelimiterStyle) + @JsonKey(name: 'style', required: true) final String style; bool get isDotDelimiterStyle => style == dotDelimiterStyle; @@ -132,10 +122,10 @@ class FlutterGenAssets { class FlutterGenIntegrations { FlutterGenIntegrations({this.flutterSvg, this.flareFlutter}); - @JsonKey(name: 'flutter_svg', defaultValue: false) + @JsonKey(name: 'flutter_svg', required: true) final bool flutterSvg; - @JsonKey(name: 'flare_flutter', defaultValue: false) + @JsonKey(name: 'flare_flutter', required: true) final bool flareFlutter; factory FlutterGenIntegrations.fromJson(Map json) => diff --git a/_internal/lib/src/pubspec.g.dart b/_internal/lib/src/pubspec.g.dart index 40341fdc..ef506607 100644 --- a/_internal/lib/src/pubspec.g.dart +++ b/_internal/lib/src/pubspec.g.dart @@ -8,6 +8,7 @@ part of 'pubspec.dart'; PubSpec _$PubSpecFromJson(Map json) { return $checkedNew('PubSpec', json, () { + $checkKeys(json, requiredKeys: const ['flutter_gen', 'flutter']); final val = PubSpec( flutterGen: $checkedConvert(json, 'flutter_gen', (v) => v == null ? null : FlutterGen.fromJson(v as Map)), @@ -25,6 +26,7 @@ Map _$PubSpecToJson(PubSpec instance) => { Flutter _$FlutterFromJson(Map json) { return $checkedNew('Flutter', json, () { + $checkKeys(json, requiredKeys: const ['assets', 'fonts']); final val = Flutter( assets: $checkedConvert(json, 'assets', (v) => (v as List)?.map((e) => e as String)?.toList()), @@ -61,13 +63,25 @@ Map _$FlutterFontsToJson(FlutterFonts instance) => FlutterGen _$FlutterGenFromJson(Map json) { return $checkedNew('FlutterGen', json, () { + $checkKeys(json, requiredKeys: const [ + 'output', + 'line_length', + 'lineLength', + 'assets', + 'integrations', + 'colors' + ]); final val = FlutterGen( - output: $checkedConvert(json, 'output', (v) => v), - lineLength: $checkedConvert(json, 'line_length', (v) => v) ?? 80, + output: $checkedConvert(json, 'output', (v) => v as String), + lineLength: $checkedConvert(json, 'line_length', (v) => v as int), deprecatedLineLength: $checkedConvert(json, 'lineLength', (v) => v as int), assets: $checkedConvert(json, 'assets', (v) => v == null ? null : FlutterGenAssets.fromJson(v as Map)), + integrations: $checkedConvert(json, 'integrations', + (v) => v == null ? null : FlutterGenIntegrations.fromJson(v as Map)), + colors: $checkedConvert(json, 'colors', + (v) => v == null ? null : FlutterGenColors.fromJson(v as Map)), ); return val; }, fieldKeyMap: const { @@ -82,6 +96,8 @@ Map _$FlutterGenToJson(FlutterGen instance) => 'line_length': instance.lineLength, 'lineLength': instance.deprecatedLineLength, 'assets': instance.assets, + 'integrations': instance.integrations, + 'colors': instance.colors, }; FlutterGenColors _$FlutterGenColorsFromJson(Map json) { @@ -102,9 +118,9 @@ Map _$FlutterGenColorsToJson(FlutterGenColors instance) => FlutterGenAssets _$FlutterGenAssetsFromJson(Map json) { return $checkedNew('FlutterGenAssets', json, () { + $checkKeys(json, requiredKeys: const ['style']); final val = FlutterGenAssets( - style: - $checkedConvert(json, 'style', (v) => v as String) ?? 'dot-delimiter', + style: $checkedConvert(json, 'style', (v) => v as String), ); return val; }); @@ -117,11 +133,10 @@ Map _$FlutterGenAssetsToJson(FlutterGenAssets instance) => FlutterGenIntegrations _$FlutterGenIntegrationsFromJson(Map json) { return $checkedNew('FlutterGenIntegrations', json, () { + $checkKeys(json, requiredKeys: const ['flutter_svg', 'flare_flutter']); final val = FlutterGenIntegrations( - flutterSvg: - $checkedConvert(json, 'flutter_svg', (v) => v as bool) ?? false, - flareFlutter: - $checkedConvert(json, 'flare_flutter', (v) => v as bool) ?? false, + flutterSvg: $checkedConvert(json, 'flutter_svg', (v) => v as bool), + flareFlutter: $checkedConvert(json, 'flare_flutter', (v) => v as bool), ); return val; }, fieldKeyMap: const { diff --git a/_internal/pubspec.lock b/_internal/pubspec.lock index f9e36385..d0b5d7fa 100644 --- a/_internal/pubspec.lock +++ b/_internal/pubspec.lock @@ -93,7 +93,7 @@ packages: source: hosted version: "1.1.3" checked_yaml: - dependency: "direct dev" + dependency: transitive description: name: checked_yaml url: "https://pub.dartlang.org" diff --git a/_internal/pubspec.yaml b/_internal/pubspec.yaml index 3b9cc225..87bc9087 100644 --- a/_internal/pubspec.yaml +++ b/_internal/pubspec.yaml @@ -13,4 +13,3 @@ dependencies: dev_dependencies: build_runner: json_serializable: ^3.5.1 - checked_yaml: ^1.0.4 From 139bda37f01ca5115e9e6d93c0cc874bbc1f3b33 Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 6 Feb 2021 12:50:52 +0900 Subject: [PATCH 04/14] Refactor generator --- _internal/lib/src/pubspec.dart | 3 - lib/src/flutter_generator.dart | 65 ++++++++-------- lib/src/generators/assets_generator.dart | 41 ++++------ lib/src/generators/colors_generator.dart | 14 ++-- lib/src/generators/fonts_generator.dart | 22 ++---- lib/src/settings/config.dart | 94 +++++++++++------------ lib/src/settings/flutter.dart | 48 ------------ lib/src/settings/flutter_gen.dart | 98 ------------------------ lib/src/settings/pubspec.dart | 75 ++++++++---------- lib/src/settings/pubspec.g.dart | 31 ++++++-- pubspec.lock | 9 ++- pubspec.yaml | 1 + 12 files changed, 165 insertions(+), 336 deletions(-) delete mode 100644 lib/src/settings/flutter.dart delete mode 100644 lib/src/settings/flutter_gen.dart diff --git a/_internal/lib/src/pubspec.dart b/_internal/lib/src/pubspec.dart index 81f2be3a..9d221371 100644 --- a/_internal/lib/src/pubspec.dart +++ b/_internal/lib/src/pubspec.dart @@ -50,9 +50,6 @@ class FlutterGen { this.integrations, this.colors, }) { - if (!FileSystemEntity.isDirectorySync(output)) { - throw ArgumentError.value(output, 'output'); - } if (deprecatedLineLength != null) { print('Warning: key lineLength is deprecated, use line_length instead.'); } diff --git a/lib/src/flutter_generator.dart b/lib/src/flutter_generator.dart index 8198d0fe..eb2d9ddf 100644 --- a/lib/src/flutter_generator.dart +++ b/lib/src/flutter_generator.dart @@ -24,9 +24,9 @@ class FlutterGenerator { final String fontsName; Future build() async { - final config = Config(pubspecFile); + Config config; try { - await config.load(); + config = await loadPubspecConfig(pubspecFile); } on InvalidSettingsException catch (e) { stderr.writeln(e.message); return; @@ -35,43 +35,40 @@ class FlutterGenerator { return; } - var output = Config.defaultOutput; - var lineLength = Config.defaultLineLength; + final output = config.flutterGen.output; + final lineLength = config.flutterGen.lineLength; + final formatter = DartFormatter(pageWidth: lineLength, lineEnding: '\n'); - if (config.hasFlutterGen) { - output = config.flutterGen.output; - lineLength = config.flutterGen.lineLength; - final formatter = DartFormatter(pageWidth: lineLength, lineEnding: '\n'); - - if (config.flutterGen.hasColors) { - final generated = - generateColors(pubspecFile, formatter, config.flutterGen.colors); - final colors = - File(normalize(join(pubspecFile.parent.path, output, colorsName))); - writeAsString(generated, file: colors); - print('Generated: ${colors.absolute.path}'); - } + final absoluteOutput = + Directory(normalize(join(pubspecFile.parent.path, output))); + if (!absoluteOutput.existsSync()) { + absoluteOutput.createSync(recursive: true); } - if (config.hasFlutter) { - final formatter = DartFormatter(pageWidth: lineLength, lineEnding: '\n'); + if (config.flutterGen.colors.inputs.isNotEmpty) { + final generated = + generateColors(pubspecFile, formatter, config.flutterGen.colors); + final colors = + File(normalize(join(pubspecFile.parent.path, output, colorsName))); + writeAsString(generated, file: colors); + print('Generated: ${colors.absolute.path}'); + } - if (config.flutter.hasAssets) { - final generated = generateAssets( - pubspecFile, formatter, config.flutterGen, config.flutter.assets); - final assets = - File(normalize(join(pubspecFile.parent.path, output, assetsName))); - writeAsString(generated, file: assets); - print('Generated: ${assets.absolute.path}'); - } + if (config.flutter.assets.isNotEmpty) { + final generated = generateAssets( + pubspecFile, formatter, config.flutterGen, config.flutter.assets); + final assets = + File(normalize(join(pubspecFile.parent.path, output, assetsName))); + writeAsString(generated, file: assets); + print('Generated: ${assets.absolute.path}'); + } - if (config.flutter.hasFonts) { - final generated = generateFonts(formatter, config.flutter.fonts); - final fonts = - File(normalize(join(pubspecFile.parent.path, output, fontsName))); - writeAsString(generated, file: fonts); - print('Generated: ${fonts.absolute.path}'); - } + if (config.flutter.fonts.isNotEmpty) { + final generated = generateFonts(formatter, config.flutter.fonts); + final fonts = + File(normalize(join(pubspecFile.parent.path, output, fontsName))); + writeAsString(generated, file: fonts); + print('Generated: ${fonts.absolute.path}'); } print('FlutterGen finished.'); diff --git a/lib/src/generators/assets_generator.dart b/lib/src/generators/assets_generator.dart index 358096d3..c6664b0e 100644 --- a/lib/src/generators/assets_generator.dart +++ b/lib/src/generators/assets_generator.dart @@ -6,9 +6,7 @@ import 'package:dartx/dartx.dart'; import 'package:path/path.dart'; import '../settings/asset_type.dart'; -import '../settings/flutter.dart'; -import '../settings/flutter_gen.dart'; -import '../utils/error.dart'; +import '../settings/pubspec.dart'; import '../utils/string.dart'; import 'generator_helper.dart'; import 'integrations/flare_integration.dart'; @@ -19,30 +17,17 @@ String generateAssets( File pubspecFile, DartFormatter formatter, FlutterGen flutterGen, - FlutterAssets assets, + List assets, ) { - if (assets == null || !assets.hasAssets) { - throw InvalidSettingsException( - 'The value of "flutter/assets:" is incorrect.'); - } - final importsBuffer = StringBuffer(); final classesBuffer = StringBuffer(); - final integrations = []; - if (flutterGen != null && flutterGen.hasIntegrations) { - if (flutterGen.integrations.flutterSvg) { - integrations.add(SvgIntegration()); - } - - if (flutterGen.integrations.flareFlutter) { - integrations.add(FlareIntegration()); - } - } + final integrations = [ + if (flutterGen.integrations.flutterSvg) SvgIntegration(), + if (flutterGen.integrations.flareFlutter) FlareIntegration(), + ]; - if (flutterGen == null || - !flutterGen.hasAssets || - flutterGen.assets.isDefaultStyle) { + if (flutterGen.assets.isDotDelimiterStyle) { classesBuffer.writeln( _dotDelimiterStyleDefinition(pubspecFile, assets, integrations)); } else if (flutterGen.assets.isSnakeCaseStyle) { @@ -77,10 +62,10 @@ String generateAssets( List _getAssetRelativePathList( File pubspecFile, - FlutterAssets assets, + List assets, ) { final assetRelativePathList = []; - for (final assetName in assets.assets) { + for (final assetName in assets) { final assetAbsolutePath = join(pubspecFile.parent.path, assetName); if (FileSystemEntity.isDirectorySync(assetAbsolutePath)) { assetRelativePathList.addAll(Directory(assetAbsolutePath) @@ -170,7 +155,7 @@ _Statement _createAssetTypeStatement( /// Generate style like Assets.foo.bar String _dotDelimiterStyleDefinition( File pubspecFile, - FlutterAssets assets, + List assets, List integrations, ) { final buffer = StringBuffer(); @@ -224,7 +209,7 @@ String _dotDelimiterStyleDefinition( /// Generate style like Assets.fooBar String _camelCaseStyleDefinition( File pubspecFile, - FlutterAssets assets, + List assets, List integrations, ) { return _flatStyleDefinition( @@ -240,7 +225,7 @@ String _camelCaseStyleDefinition( /// Generate style like Assets.foo_bar String _snakeCaseStyleDefinition( File pubspecFile, - FlutterAssets assets, + List assets, List integrations, ) { return _flatStyleDefinition( @@ -255,7 +240,7 @@ String _snakeCaseStyleDefinition( String _flatStyleDefinition( File pubspecFile, - FlutterAssets assets, + List assets, List integrations, String Function(AssetType) createName, ) { diff --git a/lib/src/generators/colors_generator.dart b/lib/src/generators/colors_generator.dart index 8fdf968d..37b5fabe 100644 --- a/lib/src/generators/colors_generator.dart +++ b/lib/src/generators/colors_generator.dart @@ -6,19 +6,16 @@ import 'package:path/path.dart'; import 'package:xml/xml.dart'; import '../settings/color_path.dart'; -import '../settings/flutter_gen.dart'; +import '../settings/pubspec.dart'; import '../utils/color.dart'; -import '../utils/error.dart'; import '../utils/string.dart'; import 'generator_helper.dart'; String generateColors( - File pubspecFile, DartFormatter formatter, FlutterGenColors colors) { - if (colors == null || !colors.hasInputs) { - throw InvalidSettingsException( - 'The value of "flutter_gen/colors:" is incorrect.'); - } - + File pubspecFile, + DartFormatter formatter, + FlutterGenColors colors, +) { final buffer = StringBuffer(); buffer.writeln(header); buffer.writeln("import 'package:flutter/painting.dart';"); @@ -30,7 +27,6 @@ String generateColors( final colorList = <_Color>[]; colors.inputs - .cast() .map((file) => ColorPath(join(pubspecFile.parent.path, file))) .forEach((colorFile) { final data = colorFile.file.readAsStringSync(); diff --git a/lib/src/generators/fonts_generator.dart b/lib/src/generators/fonts_generator.dart index b587e500..e36a4c80 100644 --- a/lib/src/generators/fonts_generator.dart +++ b/lib/src/generators/fonts_generator.dart @@ -1,31 +1,21 @@ import 'package:dart_style/dart_style.dart'; import 'package:dartx/dartx.dart'; -import 'package:yaml/yaml.dart'; -import '../settings/flutter.dart'; -import '../utils/cast.dart'; -import '../utils/error.dart'; +import '../settings/pubspec.dart'; import '../utils/string.dart'; import 'generator_helper.dart'; -String generateFonts(DartFormatter formatter, FlutterFonts fonts) { - if (fonts == null || !fonts.hasFonts) { - throw InvalidSettingsException( - 'The value of "flutter/fonts:" is incorrect.'); - } - +String generateFonts( + DartFormatter formatter, + List fonts, +) { final buffer = StringBuffer(); buffer.writeln(header); buffer.writeln('class FontFamily {'); buffer.writeln(' FontFamily._();'); buffer.writeln(); - fonts.fonts - .cast() - .map((element) => safeCast(element['family'])) - .distinct() - .sorted() - .forEach((family) { + fonts.map((element) => element.family).distinct().sorted().forEach((family) { buffer .writeln(" static const String ${family.camelCase()} = \'$family\';"); }); diff --git a/lib/src/settings/config.dart b/lib/src/settings/config.dart index ccafbea3..59c656e2 100644 --- a/lib/src/settings/config.dart +++ b/lib/src/settings/config.dart @@ -1,55 +1,55 @@ import 'dart:io'; +import 'package:merge_map/merge_map.dart'; import 'package:path/path.dart'; import 'package:yaml/yaml.dart'; -import '../utils/cast.dart'; -import '../utils/error.dart'; -import 'flutter.dart'; -import 'flutter_gen.dart'; +import 'pubspec.dart'; class Config { - Config(this.pubspecFile); - - static final String defaultOutput = 'lib${separator}gen$separator'; - static const int defaultLineLength = 80; - - final File pubspecFile; - Flutter flutter; - FlutterGen flutterGen; - - Future load() async { - print('FlutterGen Loading ... ' - '${normalize(join( - basename(pubspecFile.parent.path), - basename(pubspecFile.path), - ))}'); - final pubspec = - await pubspecFile.readAsString().catchError((dynamic error) { - throw FileSystemException( - 'Cannot open pubspec.yaml: ${pubspecFile.absolute}'); - }); - if (pubspec.isEmpty) { - throw const InvalidSettingsException('pubspec.yaml is empty'); - } - - final properties = safeCast(loadYaml(pubspec)); - - if (properties.containsKey('flutter')) { - flutter = Flutter(safeCast(properties['flutter'])); - } - if (properties.containsKey('flutter_gen')) { - flutterGen = FlutterGen(safeCast(properties['flutter_gen'])); - } - - if (!hasFlutter && !hasFlutterGen) { - throw const InvalidSettingsException('FlutterGen settings not founded.'); - } - - return this; - } - - bool get hasFlutterGen => flutterGen != null; - - bool get hasFlutter => flutter != null; + Config._({this.pubSpec}); + + final PubSpec pubSpec; + + FlutterGen get flutterGen => pubSpec.flutterGen; + + Flutter get flutter => pubSpec.flutter; +} + +Future loadPubspecConfig(File pubSpecFile) async { + print('FlutterGen Loading ... ' + '${normalize(join( + basename(pubSpecFile.parent.path), + basename(pubSpecFile.path), + ))}'); + final content = await pubSpecFile.readAsString().catchError((dynamic error) { + throw FileSystemException( + 'Cannot open pubspec.yaml: ${pubSpecFile.absolute}'); + }); + final userMap = loadYaml(content) as Map; + final defaultMap = loadYaml(_defaultConfig) as Map; + final mergedMap = mergeMap([defaultMap, userMap]); + final pubSpec = PubSpec.fromJson(mergedMap); + return Config._(pubSpec: pubSpec); } + +const _defaultConfig = ''' +flutter_gen: + output: lib/gen/ + lineLength: 80 + line_length: 80 + + integrations: + flutter_svg: false + flare_flutter: false + + assets: + style: dot-delimiter + + colors: + inputs: [] + +flutter: + assets: [] + fonts: [] +'''; diff --git a/lib/src/settings/flutter.dart b/lib/src/settings/flutter.dart deleted file mode 100644 index 3ee5dc28..00000000 --- a/lib/src/settings/flutter.dart +++ /dev/null @@ -1,48 +0,0 @@ -import 'package:yaml/yaml.dart'; - -import '../utils/cast.dart'; - -class Flutter { - Flutter(YamlMap flutterMap) { - if (flutterMap != null) { - if (flutterMap.containsKey('assets')) { - assets = FlutterAssets(safeCast(flutterMap['assets'])); - } - if (flutterMap.containsKey('fonts')) { - fonts = FlutterFonts(safeCast(flutterMap['fonts'])); - } - } - } - - FlutterAssets assets; - - FlutterFonts fonts; - - bool get hasAssets => assets != null && assets.hasAssets; - - bool get hasFonts => fonts != null && fonts.hasFonts; -} - -class FlutterAssets { - FlutterAssets(YamlList assets) { - if (assets != null) { - this.assets = assets.cast(); - } - } - - List assets; - - bool get hasAssets => assets != null && assets.isNotEmpty; -} - -class FlutterFonts { - FlutterFonts(YamlList fonts) { - if (fonts != null) { - this.fonts = fonts.cast(); - } - } - - List fonts; - - bool get hasFonts => fonts != null && fonts.isNotEmpty; -} diff --git a/lib/src/settings/flutter_gen.dart b/lib/src/settings/flutter_gen.dart deleted file mode 100644 index 92a9f372..00000000 --- a/lib/src/settings/flutter_gen.dart +++ /dev/null @@ -1,98 +0,0 @@ -import 'dart:io'; - -import 'package:yaml/yaml.dart'; - -import '../utils/cast.dart'; -import 'config.dart'; - -class FlutterGen { - FlutterGen(YamlMap flutterGenMap) { - if (flutterGenMap != null) { - _output = safeCast(flutterGenMap['output']); - if (_output != null && !Directory(_output).existsSync()) { - Directory(_output).createSync(recursive: true); - } - - if (flutterGenMap.containsKey('integrations')) { - integrations = FlutterGenIntegrations( - safeCast(flutterGenMap['integrations'])); - } - if (flutterGenMap.containsKey('assets')) { - assets = FlutterGenAssets(safeCast(flutterGenMap['assets'])); - } - _lineLength = safeCast(flutterGenMap['lineLength']); - if (flutterGenMap.containsKey('colors')) { - colors = FlutterGenColors(safeCast(flutterGenMap['colors'])); - } - } - } - - String _output; - - String get output => - _output != null && FileSystemEntity.isDirectorySync(_output) - ? _output - : Config.defaultOutput; - - int _lineLength; - - int get lineLength => _lineLength ?? Config.defaultLineLength; - - FlutterGenIntegrations integrations; - - bool get hasIntegrations => integrations != null; - - FlutterGenAssets assets; - - bool get hasAssets => assets != null; - - FlutterGenColors colors; - - bool get hasColors => colors != null && colors.hasInputs; -} - -class FlutterGenColors { - FlutterGenColors(YamlMap flutterGenMap) { - if (flutterGenMap != null) { - inputs = safeCast(flutterGenMap['inputs']); - } - } - - YamlList inputs; - - bool get hasInputs => inputs != null && inputs.isNotEmpty; -} - -class FlutterGenAssets { - FlutterGenAssets(YamlMap flutterGenMap) { - if (flutterGenMap != null) { - style = safeCast(flutterGenMap['style']); - } - } - - String style; - - bool get isDefaultStyle => style == null || isDotDelimiterStyle; - - bool get isDotDelimiterStyle => style == 'dot-delimiter'; - - bool get isSnakeCaseStyle => style == 'snake-case'; - - bool get isCamelCaseStyle => style == 'camel-case'; -} - -class FlutterGenIntegrations { - FlutterGenIntegrations(YamlMap flutterGenMap) { - if (flutterGenMap != null) { - _flutterSvg = safeCast(flutterGenMap['flutter_svg']); - _flareFlutter = safeCast(flutterGenMap['flare_flutter']); - } - } - - bool _flutterSvg; - bool _flareFlutter; - - bool get flutterSvg => _flutterSvg ?? false; - - bool get flareFlutter => _flareFlutter ?? false; -} diff --git a/lib/src/settings/pubspec.dart b/lib/src/settings/pubspec.dart index e5026e04..9d221371 100644 --- a/lib/src/settings/pubspec.dart +++ b/lib/src/settings/pubspec.dart @@ -1,21 +1,17 @@ import 'dart:io'; import 'package:json_annotation/json_annotation.dart'; -import 'package:path/path.dart'; part 'pubspec.g.dart'; -final String _defaultOutput = 'lib${separator}gen$separator'; -const int _defaultLineLength = 80; - @JsonSerializable() class PubSpec { PubSpec({this.flutterGen, this.flutter}); - @JsonKey(name: 'flutter_gen') + @JsonKey(name: 'flutter_gen', required: true) final FlutterGen flutterGen; - @JsonKey(name: 'flutter') + @JsonKey(name: 'flutter', required: true) final Flutter flutter; factory PubSpec.fromJson(Map json) => _$PubSpecFromJson(json); @@ -23,19 +19,12 @@ class PubSpec { @JsonSerializable() class Flutter { - Flutter({this.assets, this.fonts}) { - if (assets.isEmpty) { - throw ArgumentError.value(assets, 'assets', 'Cannot be empty'); - } - if (fonts.isEmpty) { - throw ArgumentError.value(assets, 'fonts', 'Cannot be empty'); - } - } + Flutter({this.assets, this.fonts}); - @JsonKey(name: 'assets') + @JsonKey(name: 'assets', required: true) final List assets; - @JsonKey(name: 'fonts') + @JsonKey(name: 'fonts', required: true) final List fonts; factory Flutter.fromJson(Map json) => _$FlutterFromJson(json); @@ -43,11 +32,7 @@ class Flutter { @JsonSerializable() class FlutterFonts { - FlutterFonts({this.family}) { - if (family.isEmpty) { - throw ArgumentError.value(family, 'family', 'Cannot be empty'); - } - } + FlutterFonts({this.family}); @JsonKey(name: 'family', required: true) final String family; @@ -57,46 +42,48 @@ class FlutterFonts { @JsonSerializable() class FlutterGen { - FlutterGen({output, lineLength, this.deprecatedLineLength, this.assets}) - : output = output ?? _defaultOutput, - lineLength = lineLength ?? deprecatedLineLength ?? _defaultLineLength { - if (!FileSystemEntity.isDirectorySync(this.output)) { - throw ArgumentError.value(output, 'output', 'Must be a valid directory.'); - } + FlutterGen({ + this.output, + this.lineLength, + this.deprecatedLineLength, + this.assets, + this.integrations, + this.colors, + }) { if (deprecatedLineLength != null) { print('Warning: key lineLength is deprecated, use line_length instead.'); } } - @JsonKey(name: 'output') + @JsonKey(name: 'output', required: true) final String output; - @JsonKey(name: 'line_length', defaultValue: _defaultLineLength) + @JsonKey(name: 'line_length', required: true) final int lineLength; @deprecated - @JsonKey(name: 'lineLength') + @JsonKey(name: 'lineLength', required: true) final int deprecatedLineLength; - @JsonKey(name: 'assets') + @JsonKey(name: 'assets', required: true) final FlutterGenAssets assets; + @JsonKey(name: 'integrations', required: true) + final FlutterGenIntegrations integrations; + + @JsonKey(name: 'colors', required: true) + final FlutterGenColors colors; + factory FlutterGen.fromJson(Map json) => _$FlutterGenFromJson(json); } @JsonSerializable() class FlutterGenColors { - FlutterGenColors({this.inputs}) { - if (inputs.isEmpty) { - throw ArgumentError.value(inputs, 'inputs', 'Cannot be empty.'); - } - } + FlutterGenColors({this.inputs}); @JsonKey(name: 'inputs', required: true) final List inputs; - bool get hasInputs => inputs != null && inputs.isNotEmpty; - factory FlutterGenColors.fromJson(Map json) => _$FlutterGenColorsFromJson(json); } @@ -108,14 +95,14 @@ class FlutterGenAssets { static const String camelCaseStyle = 'camel-case'; FlutterGenAssets({this.style}) { - if (style != dotDelimiterStyle || - style != snakeCaseStyle || + if (style != dotDelimiterStyle && + style != snakeCaseStyle && style != camelCaseStyle) { - throw ArgumentError.value(style, 'style', 'Invalid style.'); + throw ArgumentError.value(style, 'style'); } } - @JsonKey(name: 'style', defaultValue: dotDelimiterStyle) + @JsonKey(name: 'style', required: true) final String style; bool get isDotDelimiterStyle => style == dotDelimiterStyle; @@ -132,10 +119,10 @@ class FlutterGenAssets { class FlutterGenIntegrations { FlutterGenIntegrations({this.flutterSvg, this.flareFlutter}); - @JsonKey(name: 'flutter_svg', defaultValue: false) + @JsonKey(name: 'flutter_svg', required: true) final bool flutterSvg; - @JsonKey(name: 'flare_flutter', defaultValue: false) + @JsonKey(name: 'flare_flutter', required: true) final bool flareFlutter; factory FlutterGenIntegrations.fromJson(Map json) => diff --git a/lib/src/settings/pubspec.g.dart b/lib/src/settings/pubspec.g.dart index 40341fdc..ef506607 100644 --- a/lib/src/settings/pubspec.g.dart +++ b/lib/src/settings/pubspec.g.dart @@ -8,6 +8,7 @@ part of 'pubspec.dart'; PubSpec _$PubSpecFromJson(Map json) { return $checkedNew('PubSpec', json, () { + $checkKeys(json, requiredKeys: const ['flutter_gen', 'flutter']); final val = PubSpec( flutterGen: $checkedConvert(json, 'flutter_gen', (v) => v == null ? null : FlutterGen.fromJson(v as Map)), @@ -25,6 +26,7 @@ Map _$PubSpecToJson(PubSpec instance) => { Flutter _$FlutterFromJson(Map json) { return $checkedNew('Flutter', json, () { + $checkKeys(json, requiredKeys: const ['assets', 'fonts']); final val = Flutter( assets: $checkedConvert(json, 'assets', (v) => (v as List)?.map((e) => e as String)?.toList()), @@ -61,13 +63,25 @@ Map _$FlutterFontsToJson(FlutterFonts instance) => FlutterGen _$FlutterGenFromJson(Map json) { return $checkedNew('FlutterGen', json, () { + $checkKeys(json, requiredKeys: const [ + 'output', + 'line_length', + 'lineLength', + 'assets', + 'integrations', + 'colors' + ]); final val = FlutterGen( - output: $checkedConvert(json, 'output', (v) => v), - lineLength: $checkedConvert(json, 'line_length', (v) => v) ?? 80, + output: $checkedConvert(json, 'output', (v) => v as String), + lineLength: $checkedConvert(json, 'line_length', (v) => v as int), deprecatedLineLength: $checkedConvert(json, 'lineLength', (v) => v as int), assets: $checkedConvert(json, 'assets', (v) => v == null ? null : FlutterGenAssets.fromJson(v as Map)), + integrations: $checkedConvert(json, 'integrations', + (v) => v == null ? null : FlutterGenIntegrations.fromJson(v as Map)), + colors: $checkedConvert(json, 'colors', + (v) => v == null ? null : FlutterGenColors.fromJson(v as Map)), ); return val; }, fieldKeyMap: const { @@ -82,6 +96,8 @@ Map _$FlutterGenToJson(FlutterGen instance) => 'line_length': instance.lineLength, 'lineLength': instance.deprecatedLineLength, 'assets': instance.assets, + 'integrations': instance.integrations, + 'colors': instance.colors, }; FlutterGenColors _$FlutterGenColorsFromJson(Map json) { @@ -102,9 +118,9 @@ Map _$FlutterGenColorsToJson(FlutterGenColors instance) => FlutterGenAssets _$FlutterGenAssetsFromJson(Map json) { return $checkedNew('FlutterGenAssets', json, () { + $checkKeys(json, requiredKeys: const ['style']); final val = FlutterGenAssets( - style: - $checkedConvert(json, 'style', (v) => v as String) ?? 'dot-delimiter', + style: $checkedConvert(json, 'style', (v) => v as String), ); return val; }); @@ -117,11 +133,10 @@ Map _$FlutterGenAssetsToJson(FlutterGenAssets instance) => FlutterGenIntegrations _$FlutterGenIntegrationsFromJson(Map json) { return $checkedNew('FlutterGenIntegrations', json, () { + $checkKeys(json, requiredKeys: const ['flutter_svg', 'flare_flutter']); final val = FlutterGenIntegrations( - flutterSvg: - $checkedConvert(json, 'flutter_svg', (v) => v as bool) ?? false, - flareFlutter: - $checkedConvert(json, 'flare_flutter', (v) => v as bool) ?? false, + flutterSvg: $checkedConvert(json, 'flutter_svg', (v) => v as bool), + flareFlutter: $checkedConvert(json, 'flare_flutter', (v) => v as bool), ); return val; }, fieldKeyMap: const { diff --git a/pubspec.lock b/pubspec.lock index dbeb0b84..687d612c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -84,7 +84,7 @@ packages: name: checked_yaml url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.0.4" cli_util: dependency: transitive description: @@ -253,6 +253,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.9" + merge_map: + dependency: "direct main" + description: + name: merge_map + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" meta: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 012b3240..c05f4728 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,6 +25,7 @@ dependencies: dart_style: ^1.3.6 dartx: ^0.5.0 color: ^2.1.1 + merge_map: ^1.0.2 dev_dependencies: test: From a1160e35f07afad6a92cb36843bf328cf2da41e2 Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 6 Feb 2021 12:56:21 +0900 Subject: [PATCH 05/14] Rename pubSpec to pubspec --- _internal/lib/src/pubspec.dart | 8 +++----- _internal/lib/src/pubspec.g.dart | 8 ++++---- lib/src/settings/config.dart | 22 +++++++++++----------- lib/src/settings/pubspec.dart | 8 +++----- lib/src/settings/pubspec.g.dart | 8 ++++---- 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/_internal/lib/src/pubspec.dart b/_internal/lib/src/pubspec.dart index 9d221371..38ffd5e9 100644 --- a/_internal/lib/src/pubspec.dart +++ b/_internal/lib/src/pubspec.dart @@ -1,12 +1,10 @@ -import 'dart:io'; - import 'package:json_annotation/json_annotation.dart'; part 'pubspec.g.dart'; @JsonSerializable() -class PubSpec { - PubSpec({this.flutterGen, this.flutter}); +class Pubspec { + Pubspec({this.flutterGen, this.flutter}); @JsonKey(name: 'flutter_gen', required: true) final FlutterGen flutterGen; @@ -14,7 +12,7 @@ class PubSpec { @JsonKey(name: 'flutter', required: true) final Flutter flutter; - factory PubSpec.fromJson(Map json) => _$PubSpecFromJson(json); + factory Pubspec.fromJson(Map json) => _$PubspecFromJson(json); } @JsonSerializable() diff --git a/_internal/lib/src/pubspec.g.dart b/_internal/lib/src/pubspec.g.dart index ef506607..7b6dfc67 100644 --- a/_internal/lib/src/pubspec.g.dart +++ b/_internal/lib/src/pubspec.g.dart @@ -6,10 +6,10 @@ part of 'pubspec.dart'; // JsonSerializableGenerator // ************************************************************************** -PubSpec _$PubSpecFromJson(Map json) { - return $checkedNew('PubSpec', json, () { +Pubspec _$PubspecFromJson(Map json) { + return $checkedNew('Pubspec', json, () { $checkKeys(json, requiredKeys: const ['flutter_gen', 'flutter']); - final val = PubSpec( + final val = Pubspec( flutterGen: $checkedConvert(json, 'flutter_gen', (v) => v == null ? null : FlutterGen.fromJson(v as Map)), flutter: $checkedConvert(json, 'flutter', @@ -19,7 +19,7 @@ PubSpec _$PubSpecFromJson(Map json) { }, fieldKeyMap: const {'flutterGen': 'flutter_gen'}); } -Map _$PubSpecToJson(PubSpec instance) => { +Map _$PubspecToJson(Pubspec instance) => { 'flutter_gen': instance.flutterGen, 'flutter': instance.flutter, }; diff --git a/lib/src/settings/config.dart b/lib/src/settings/config.dart index 59c656e2..165f5523 100644 --- a/lib/src/settings/config.dart +++ b/lib/src/settings/config.dart @@ -7,30 +7,30 @@ import 'package:yaml/yaml.dart'; import 'pubspec.dart'; class Config { - Config._({this.pubSpec}); + Config._({this.pubspec}); - final PubSpec pubSpec; + final Pubspec pubspec; - FlutterGen get flutterGen => pubSpec.flutterGen; + FlutterGen get flutterGen => pubspec.flutterGen; - Flutter get flutter => pubSpec.flutter; + Flutter get flutter => pubspec.flutter; } -Future loadPubspecConfig(File pubSpecFile) async { +Future loadPubspecConfig(File pubspecFile) async { print('FlutterGen Loading ... ' '${normalize(join( - basename(pubSpecFile.parent.path), - basename(pubSpecFile.path), + basename(pubspecFile.parent.path), + basename(pubspecFile.path), ))}'); - final content = await pubSpecFile.readAsString().catchError((dynamic error) { + final content = await pubspecFile.readAsString().catchError((dynamic error) { throw FileSystemException( - 'Cannot open pubspec.yaml: ${pubSpecFile.absolute}'); + 'Cannot open pubspec.yaml: ${pubspecFile.absolute}'); }); final userMap = loadYaml(content) as Map; final defaultMap = loadYaml(_defaultConfig) as Map; final mergedMap = mergeMap([defaultMap, userMap]); - final pubSpec = PubSpec.fromJson(mergedMap); - return Config._(pubSpec: pubSpec); + final pubspec = Pubspec.fromJson(mergedMap); + return Config._(pubspec: pubspec); } const _defaultConfig = ''' diff --git a/lib/src/settings/pubspec.dart b/lib/src/settings/pubspec.dart index 9d221371..38ffd5e9 100644 --- a/lib/src/settings/pubspec.dart +++ b/lib/src/settings/pubspec.dart @@ -1,12 +1,10 @@ -import 'dart:io'; - import 'package:json_annotation/json_annotation.dart'; part 'pubspec.g.dart'; @JsonSerializable() -class PubSpec { - PubSpec({this.flutterGen, this.flutter}); +class Pubspec { + Pubspec({this.flutterGen, this.flutter}); @JsonKey(name: 'flutter_gen', required: true) final FlutterGen flutterGen; @@ -14,7 +12,7 @@ class PubSpec { @JsonKey(name: 'flutter', required: true) final Flutter flutter; - factory PubSpec.fromJson(Map json) => _$PubSpecFromJson(json); + factory Pubspec.fromJson(Map json) => _$PubspecFromJson(json); } @JsonSerializable() diff --git a/lib/src/settings/pubspec.g.dart b/lib/src/settings/pubspec.g.dart index ef506607..7b6dfc67 100644 --- a/lib/src/settings/pubspec.g.dart +++ b/lib/src/settings/pubspec.g.dart @@ -6,10 +6,10 @@ part of 'pubspec.dart'; // JsonSerializableGenerator // ************************************************************************** -PubSpec _$PubSpecFromJson(Map json) { - return $checkedNew('PubSpec', json, () { +Pubspec _$PubspecFromJson(Map json) { + return $checkedNew('Pubspec', json, () { $checkKeys(json, requiredKeys: const ['flutter_gen', 'flutter']); - final val = PubSpec( + final val = Pubspec( flutterGen: $checkedConvert(json, 'flutter_gen', (v) => v == null ? null : FlutterGen.fromJson(v as Map)), flutter: $checkedConvert(json, 'flutter', @@ -19,7 +19,7 @@ PubSpec _$PubSpecFromJson(Map json) { }, fieldKeyMap: const {'flutterGen': 'flutter_gen'}); } -Map _$PubSpecToJson(PubSpec instance) => { +Map _$PubspecToJson(Pubspec instance) => { 'flutter_gen': instance.flutterGen, 'flutter': instance.flutter, }; From e2008676d32a88d37b6e2805da8a2b0e57ab671f Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 6 Feb 2021 13:13:21 +0900 Subject: [PATCH 06/14] Fix lineLength handling --- _internal/build.yaml | 4 +- _internal/lib/src/pubspec.dart | 21 +++++--- _internal/lib/src/pubspec.g.dart | 82 ++++++++------------------------ lib/src/flutter_generator.dart | 3 -- lib/src/settings/config.dart | 3 +- lib/src/settings/pubspec.dart | 21 +++++--- lib/src/settings/pubspec.g.dart | 82 ++++++++------------------------ 7 files changed, 72 insertions(+), 144 deletions(-) diff --git a/_internal/build.yaml b/_internal/build.yaml index dd37496b..156baf6f 100644 --- a/_internal/build.yaml +++ b/_internal/build.yaml @@ -6,12 +6,12 @@ targets: any_map: true checked: true create_factory: true - create_to_json: true + create_to_json: false disallow_unrecognized_keys: false explicit_to_json: false field_rename: none generic_argument_factories: false ignore_unannotated: false include_if_null: true - nullable: true + nullable: false diff --git a/_internal/lib/src/pubspec.dart b/_internal/lib/src/pubspec.dart index 38ffd5e9..346ec46a 100644 --- a/_internal/lib/src/pubspec.dart +++ b/_internal/lib/src/pubspec.dart @@ -42,13 +42,19 @@ class FlutterFonts { class FlutterGen { FlutterGen({ this.output, - this.lineLength, - this.deprecatedLineLength, + this.lineLength1, + this.lineLength0, this.assets, this.integrations, this.colors, }) { - if (deprecatedLineLength != null) { + if (lineLength1 <= 0 && lineLength0 <= 0) { + throw ArgumentError.value( + lineLength1 <= 0 ? lineLength1 : lineLength0, + lineLength1 <= 0 ? 'line_length' : 'lineLength', + ); + } + if (lineLength0 > 0) { print('Warning: key lineLength is deprecated, use line_length instead.'); } } @@ -57,11 +63,11 @@ class FlutterGen { final String output; @JsonKey(name: 'line_length', required: true) - final int lineLength; + final int lineLength1; @deprecated - @JsonKey(name: 'lineLength', required: true) - final int deprecatedLineLength; + @JsonKey(name: 'lineLength', required: true, nullable: true) + final int lineLength0; @JsonKey(name: 'assets', required: true) final FlutterGenAssets assets; @@ -72,6 +78,9 @@ class FlutterGen { @JsonKey(name: 'colors', required: true) final FlutterGenColors colors; + // Backwards compatible + int get lineLength => lineLength0 > 0 ? lineLength0 : lineLength1; + factory FlutterGen.fromJson(Map json) => _$FlutterGenFromJson(json); } diff --git a/_internal/lib/src/pubspec.g.dart b/_internal/lib/src/pubspec.g.dart index 7b6dfc67..24844ccd 100644 --- a/_internal/lib/src/pubspec.g.dart +++ b/_internal/lib/src/pubspec.g.dart @@ -10,42 +10,31 @@ Pubspec _$PubspecFromJson(Map json) { return $checkedNew('Pubspec', json, () { $checkKeys(json, requiredKeys: const ['flutter_gen', 'flutter']); final val = Pubspec( - flutterGen: $checkedConvert(json, 'flutter_gen', - (v) => v == null ? null : FlutterGen.fromJson(v as Map)), - flutter: $checkedConvert(json, 'flutter', - (v) => v == null ? null : Flutter.fromJson(v as Map)), + flutterGen: $checkedConvert( + json, 'flutter_gen', (v) => FlutterGen.fromJson(v as Map)), + flutter: + $checkedConvert(json, 'flutter', (v) => Flutter.fromJson(v as Map)), ); return val; }, fieldKeyMap: const {'flutterGen': 'flutter_gen'}); } -Map _$PubspecToJson(Pubspec instance) => { - 'flutter_gen': instance.flutterGen, - 'flutter': instance.flutter, - }; - Flutter _$FlutterFromJson(Map json) { return $checkedNew('Flutter', json, () { $checkKeys(json, requiredKeys: const ['assets', 'fonts']); final val = Flutter( - assets: $checkedConvert(json, 'assets', - (v) => (v as List)?.map((e) => e as String)?.toList()), + assets: $checkedConvert( + json, 'assets', (v) => (v as List).map((e) => e as String).toList()), fonts: $checkedConvert( json, 'fonts', - (v) => (v as List) - ?.map((e) => e == null ? null : FlutterFonts.fromJson(e as Map)) - ?.toList()), + (v) => + (v as List).map((e) => FlutterFonts.fromJson(e as Map)).toList()), ); return val; }); } -Map _$FlutterToJson(Flutter instance) => { - 'assets': instance.assets, - 'fonts': instance.fonts, - }; - FlutterFonts _$FlutterFontsFromJson(Map json) { return $checkedNew('FlutterFonts', json, () { $checkKeys(json, requiredKeys: const ['family']); @@ -56,11 +45,6 @@ FlutterFonts _$FlutterFontsFromJson(Map json) { }); } -Map _$FlutterFontsToJson(FlutterFonts instance) => - { - 'family': instance.family, - }; - FlutterGen _$FlutterGenFromJson(Map json) { return $checkedNew('FlutterGen', json, () { $checkKeys(json, requiredKeys: const [ @@ -73,49 +57,33 @@ FlutterGen _$FlutterGenFromJson(Map json) { ]); final val = FlutterGen( output: $checkedConvert(json, 'output', (v) => v as String), - lineLength: $checkedConvert(json, 'line_length', (v) => v as int), - deprecatedLineLength: - $checkedConvert(json, 'lineLength', (v) => v as int), - assets: $checkedConvert(json, 'assets', - (v) => v == null ? null : FlutterGenAssets.fromJson(v as Map)), + lineLength1: $checkedConvert(json, 'line_length', (v) => v as int), + lineLength0: $checkedConvert(json, 'lineLength', (v) => v as int), + assets: $checkedConvert( + json, 'assets', (v) => FlutterGenAssets.fromJson(v as Map)), integrations: $checkedConvert(json, 'integrations', - (v) => v == null ? null : FlutterGenIntegrations.fromJson(v as Map)), - colors: $checkedConvert(json, 'colors', - (v) => v == null ? null : FlutterGenColors.fromJson(v as Map)), + (v) => FlutterGenIntegrations.fromJson(v as Map)), + colors: $checkedConvert( + json, 'colors', (v) => FlutterGenColors.fromJson(v as Map)), ); return val; }, fieldKeyMap: const { - 'lineLength': 'line_length', - 'deprecatedLineLength': 'lineLength' + 'lineLength1': 'line_length', + 'lineLength0': 'lineLength' }); } -Map _$FlutterGenToJson(FlutterGen instance) => - { - 'output': instance.output, - 'line_length': instance.lineLength, - 'lineLength': instance.deprecatedLineLength, - 'assets': instance.assets, - 'integrations': instance.integrations, - 'colors': instance.colors, - }; - FlutterGenColors _$FlutterGenColorsFromJson(Map json) { return $checkedNew('FlutterGenColors', json, () { $checkKeys(json, requiredKeys: const ['inputs']); final val = FlutterGenColors( - inputs: $checkedConvert(json, 'inputs', - (v) => (v as List)?.map((e) => e as String)?.toList()), + inputs: $checkedConvert( + json, 'inputs', (v) => (v as List).map((e) => e as String).toList()), ); return val; }); } -Map _$FlutterGenColorsToJson(FlutterGenColors instance) => - { - 'inputs': instance.inputs, - }; - FlutterGenAssets _$FlutterGenAssetsFromJson(Map json) { return $checkedNew('FlutterGenAssets', json, () { $checkKeys(json, requiredKeys: const ['style']); @@ -126,11 +94,6 @@ FlutterGenAssets _$FlutterGenAssetsFromJson(Map json) { }); } -Map _$FlutterGenAssetsToJson(FlutterGenAssets instance) => - { - 'style': instance.style, - }; - FlutterGenIntegrations _$FlutterGenIntegrationsFromJson(Map json) { return $checkedNew('FlutterGenIntegrations', json, () { $checkKeys(json, requiredKeys: const ['flutter_svg', 'flare_flutter']); @@ -144,10 +107,3 @@ FlutterGenIntegrations _$FlutterGenIntegrationsFromJson(Map json) { 'flareFlutter': 'flare_flutter' }); } - -Map _$FlutterGenIntegrationsToJson( - FlutterGenIntegrations instance) => - { - 'flutter_svg': instance.flutterSvg, - 'flare_flutter': instance.flareFlutter, - }; diff --git a/lib/src/flutter_generator.dart b/lib/src/flutter_generator.dart index eb2d9ddf..d78c80d1 100644 --- a/lib/src/flutter_generator.dart +++ b/lib/src/flutter_generator.dart @@ -27,9 +27,6 @@ class FlutterGenerator { Config config; try { config = await loadPubspecConfig(pubspecFile); - } on InvalidSettingsException catch (e) { - stderr.writeln(e.message); - return; } on FileSystemException catch (e) { stderr.writeln(e.message); return; diff --git a/lib/src/settings/config.dart b/lib/src/settings/config.dart index 165f5523..f629d827 100644 --- a/lib/src/settings/config.dart +++ b/lib/src/settings/config.dart @@ -36,7 +36,8 @@ Future loadPubspecConfig(File pubspecFile) async { const _defaultConfig = ''' flutter_gen: output: lib/gen/ - lineLength: 80 + # deprecated key + lineLength: -1 line_length: 80 integrations: diff --git a/lib/src/settings/pubspec.dart b/lib/src/settings/pubspec.dart index 38ffd5e9..346ec46a 100644 --- a/lib/src/settings/pubspec.dart +++ b/lib/src/settings/pubspec.dart @@ -42,13 +42,19 @@ class FlutterFonts { class FlutterGen { FlutterGen({ this.output, - this.lineLength, - this.deprecatedLineLength, + this.lineLength1, + this.lineLength0, this.assets, this.integrations, this.colors, }) { - if (deprecatedLineLength != null) { + if (lineLength1 <= 0 && lineLength0 <= 0) { + throw ArgumentError.value( + lineLength1 <= 0 ? lineLength1 : lineLength0, + lineLength1 <= 0 ? 'line_length' : 'lineLength', + ); + } + if (lineLength0 > 0) { print('Warning: key lineLength is deprecated, use line_length instead.'); } } @@ -57,11 +63,11 @@ class FlutterGen { final String output; @JsonKey(name: 'line_length', required: true) - final int lineLength; + final int lineLength1; @deprecated - @JsonKey(name: 'lineLength', required: true) - final int deprecatedLineLength; + @JsonKey(name: 'lineLength', required: true, nullable: true) + final int lineLength0; @JsonKey(name: 'assets', required: true) final FlutterGenAssets assets; @@ -72,6 +78,9 @@ class FlutterGen { @JsonKey(name: 'colors', required: true) final FlutterGenColors colors; + // Backwards compatible + int get lineLength => lineLength0 > 0 ? lineLength0 : lineLength1; + factory FlutterGen.fromJson(Map json) => _$FlutterGenFromJson(json); } diff --git a/lib/src/settings/pubspec.g.dart b/lib/src/settings/pubspec.g.dart index 7b6dfc67..24844ccd 100644 --- a/lib/src/settings/pubspec.g.dart +++ b/lib/src/settings/pubspec.g.dart @@ -10,42 +10,31 @@ Pubspec _$PubspecFromJson(Map json) { return $checkedNew('Pubspec', json, () { $checkKeys(json, requiredKeys: const ['flutter_gen', 'flutter']); final val = Pubspec( - flutterGen: $checkedConvert(json, 'flutter_gen', - (v) => v == null ? null : FlutterGen.fromJson(v as Map)), - flutter: $checkedConvert(json, 'flutter', - (v) => v == null ? null : Flutter.fromJson(v as Map)), + flutterGen: $checkedConvert( + json, 'flutter_gen', (v) => FlutterGen.fromJson(v as Map)), + flutter: + $checkedConvert(json, 'flutter', (v) => Flutter.fromJson(v as Map)), ); return val; }, fieldKeyMap: const {'flutterGen': 'flutter_gen'}); } -Map _$PubspecToJson(Pubspec instance) => { - 'flutter_gen': instance.flutterGen, - 'flutter': instance.flutter, - }; - Flutter _$FlutterFromJson(Map json) { return $checkedNew('Flutter', json, () { $checkKeys(json, requiredKeys: const ['assets', 'fonts']); final val = Flutter( - assets: $checkedConvert(json, 'assets', - (v) => (v as List)?.map((e) => e as String)?.toList()), + assets: $checkedConvert( + json, 'assets', (v) => (v as List).map((e) => e as String).toList()), fonts: $checkedConvert( json, 'fonts', - (v) => (v as List) - ?.map((e) => e == null ? null : FlutterFonts.fromJson(e as Map)) - ?.toList()), + (v) => + (v as List).map((e) => FlutterFonts.fromJson(e as Map)).toList()), ); return val; }); } -Map _$FlutterToJson(Flutter instance) => { - 'assets': instance.assets, - 'fonts': instance.fonts, - }; - FlutterFonts _$FlutterFontsFromJson(Map json) { return $checkedNew('FlutterFonts', json, () { $checkKeys(json, requiredKeys: const ['family']); @@ -56,11 +45,6 @@ FlutterFonts _$FlutterFontsFromJson(Map json) { }); } -Map _$FlutterFontsToJson(FlutterFonts instance) => - { - 'family': instance.family, - }; - FlutterGen _$FlutterGenFromJson(Map json) { return $checkedNew('FlutterGen', json, () { $checkKeys(json, requiredKeys: const [ @@ -73,49 +57,33 @@ FlutterGen _$FlutterGenFromJson(Map json) { ]); final val = FlutterGen( output: $checkedConvert(json, 'output', (v) => v as String), - lineLength: $checkedConvert(json, 'line_length', (v) => v as int), - deprecatedLineLength: - $checkedConvert(json, 'lineLength', (v) => v as int), - assets: $checkedConvert(json, 'assets', - (v) => v == null ? null : FlutterGenAssets.fromJson(v as Map)), + lineLength1: $checkedConvert(json, 'line_length', (v) => v as int), + lineLength0: $checkedConvert(json, 'lineLength', (v) => v as int), + assets: $checkedConvert( + json, 'assets', (v) => FlutterGenAssets.fromJson(v as Map)), integrations: $checkedConvert(json, 'integrations', - (v) => v == null ? null : FlutterGenIntegrations.fromJson(v as Map)), - colors: $checkedConvert(json, 'colors', - (v) => v == null ? null : FlutterGenColors.fromJson(v as Map)), + (v) => FlutterGenIntegrations.fromJson(v as Map)), + colors: $checkedConvert( + json, 'colors', (v) => FlutterGenColors.fromJson(v as Map)), ); return val; }, fieldKeyMap: const { - 'lineLength': 'line_length', - 'deprecatedLineLength': 'lineLength' + 'lineLength1': 'line_length', + 'lineLength0': 'lineLength' }); } -Map _$FlutterGenToJson(FlutterGen instance) => - { - 'output': instance.output, - 'line_length': instance.lineLength, - 'lineLength': instance.deprecatedLineLength, - 'assets': instance.assets, - 'integrations': instance.integrations, - 'colors': instance.colors, - }; - FlutterGenColors _$FlutterGenColorsFromJson(Map json) { return $checkedNew('FlutterGenColors', json, () { $checkKeys(json, requiredKeys: const ['inputs']); final val = FlutterGenColors( - inputs: $checkedConvert(json, 'inputs', - (v) => (v as List)?.map((e) => e as String)?.toList()), + inputs: $checkedConvert( + json, 'inputs', (v) => (v as List).map((e) => e as String).toList()), ); return val; }); } -Map _$FlutterGenColorsToJson(FlutterGenColors instance) => - { - 'inputs': instance.inputs, - }; - FlutterGenAssets _$FlutterGenAssetsFromJson(Map json) { return $checkedNew('FlutterGenAssets', json, () { $checkKeys(json, requiredKeys: const ['style']); @@ -126,11 +94,6 @@ FlutterGenAssets _$FlutterGenAssetsFromJson(Map json) { }); } -Map _$FlutterGenAssetsToJson(FlutterGenAssets instance) => - { - 'style': instance.style, - }; - FlutterGenIntegrations _$FlutterGenIntegrationsFromJson(Map json) { return $checkedNew('FlutterGenIntegrations', json, () { $checkKeys(json, requiredKeys: const ['flutter_svg', 'flare_flutter']); @@ -144,10 +107,3 @@ FlutterGenIntegrations _$FlutterGenIntegrationsFromJson(Map json) { 'flareFlutter': 'flare_flutter' }); } - -Map _$FlutterGenIntegrationsToJson( - FlutterGenIntegrations instance) => - { - 'flutter_svg': instance.flutterSvg, - 'flare_flutter': instance.flareFlutter, - }; From 62de4a460a876a8999915aa9cbb4faf90ac9d68b Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 6 Feb 2021 13:29:24 +0900 Subject: [PATCH 07/14] Fix test --- lib/src/flutter_generator.dart | 3 +++ lib/src/generators/assets_generator.dart | 6 ++++++ lib/src/generators/colors_generator.dart | 6 ++++++ lib/src/generators/fonts_generator.dart | 6 ++++++ test/assets_gen_integrations_test.dart | 12 ++++++++---- test/assets_gen_test.dart | 5 +++-- test/colors_gen_test.dart | 4 ++-- test/flutter_gen_test.dart | 18 +++--------------- test/fonts_gen_test.dart | 4 ++-- test/gen_test_helper.dart | 6 +++--- 10 files changed, 42 insertions(+), 28 deletions(-) diff --git a/lib/src/flutter_generator.dart b/lib/src/flutter_generator.dart index d78c80d1..eb2d9ddf 100644 --- a/lib/src/flutter_generator.dart +++ b/lib/src/flutter_generator.dart @@ -27,6 +27,9 @@ class FlutterGenerator { Config config; try { config = await loadPubspecConfig(pubspecFile); + } on InvalidSettingsException catch (e) { + stderr.writeln(e.message); + return; } on FileSystemException catch (e) { stderr.writeln(e.message); return; diff --git a/lib/src/generators/assets_generator.dart b/lib/src/generators/assets_generator.dart index c6664b0e..1c5e5d19 100644 --- a/lib/src/generators/assets_generator.dart +++ b/lib/src/generators/assets_generator.dart @@ -7,6 +7,7 @@ import 'package:path/path.dart'; import '../settings/asset_type.dart'; import '../settings/pubspec.dart'; +import '../utils/error.dart'; import '../utils/string.dart'; import 'generator_helper.dart'; import 'integrations/flare_integration.dart'; @@ -19,6 +20,11 @@ String generateAssets( FlutterGen flutterGen, List assets, ) { + if (assets.isEmpty) { + throw InvalidSettingsException( + 'The value of "flutter/assets:" is incorrect.'); + } + final importsBuffer = StringBuffer(); final classesBuffer = StringBuffer(); diff --git a/lib/src/generators/colors_generator.dart b/lib/src/generators/colors_generator.dart index 37b5fabe..d3bd37aa 100644 --- a/lib/src/generators/colors_generator.dart +++ b/lib/src/generators/colors_generator.dart @@ -8,6 +8,7 @@ import 'package:xml/xml.dart'; import '../settings/color_path.dart'; import '../settings/pubspec.dart'; import '../utils/color.dart'; +import '../utils/error.dart'; import '../utils/string.dart'; import 'generator_helper.dart'; @@ -16,6 +17,11 @@ String generateColors( DartFormatter formatter, FlutterGenColors colors, ) { + if (colors.inputs.isEmpty) { + throw InvalidSettingsException( + 'The value of "flutter_gen/colors:" is incorrect.'); + } + final buffer = StringBuffer(); buffer.writeln(header); buffer.writeln("import 'package:flutter/painting.dart';"); diff --git a/lib/src/generators/fonts_generator.dart b/lib/src/generators/fonts_generator.dart index e36a4c80..3e7b3d96 100644 --- a/lib/src/generators/fonts_generator.dart +++ b/lib/src/generators/fonts_generator.dart @@ -2,6 +2,7 @@ import 'package:dart_style/dart_style.dart'; import 'package:dartx/dartx.dart'; import '../settings/pubspec.dart'; +import '../utils/error.dart'; import '../utils/string.dart'; import 'generator_helper.dart'; @@ -9,6 +10,11 @@ String generateFonts( DartFormatter formatter, List fonts, ) { + if (fonts.isEmpty) { + throw InvalidSettingsException( + 'The value of "flutter/fonts:" is incorrect.'); + } + final buffer = StringBuffer(); buffer.writeln(header); buffer.writeln('class FontFamily {'); diff --git a/test/assets_gen_integrations_test.dart b/test/assets_gen_integrations_test.dart index a2f60325..2d24770a 100644 --- a/test/assets_gen_integrations_test.dart +++ b/test/assets_gen_integrations_test.dart @@ -11,15 +11,18 @@ void main() { test('Assets with No integrations on pubspec.yaml', () async { final pubspec = 'test_resources/pubspec_assets_no_integrations.yaml'; final fact = 'test_resources/actual_data/assets_no_integrations.gen.dart'; - final generated = 'test_resources/lib/gen/assets_no_integrations.gen.dart'; + final generated = + 'test_resources/lib/gen/assets_no_integrations.gen.dart'; expectedAssetsGen(pubspec, generated, fact); }); test('Assets with Svg integrations on pubspec.yaml', () async { final pubspec = 'test_resources/pubspec_assets_svg_integrations.yaml'; - final fact = 'test_resources/actual_data/assets_svg_integrations.gen.dart'; - final generated = 'test_resources/lib/gen/assets_svg_integrations.gen.dart'; + final fact = + 'test_resources/actual_data/assets_svg_integrations.gen.dart'; + final generated = + 'test_resources/lib/gen/assets_svg_integrations.gen.dart'; expectedAssetsGen(pubspec, generated, fact); @@ -36,7 +39,8 @@ void main() { final pubspec = 'test_resources/pubspec_assets_flare_integrations.yaml'; final fact = 'test_resources/actual_data/assets_flare_integrations.gen.dart'; - final generated = 'test_resources/lib/gen/assets_flare_integrations.gen.dart'; + final generated = + 'test_resources/lib/gen/assets_flare_integrations.gen.dart'; expectedAssetsGen(pubspec, generated, fact); diff --git a/test/assets_gen_test.dart b/test/assets_gen_test.dart index 60fc1871..81cb9225 100644 --- a/test/assets_gen_test.dart +++ b/test/assets_gen_test.dart @@ -39,7 +39,8 @@ void main() { final pubspec = 'test_resources/pubspec_unknown_mime_type.yaml'; final fact = 'test_resources/actual_data/assets_unknown_mime_type.gen.dart'; - final generated = 'test_resources/lib/gen/assets_unknown_mime_type.gen.dart'; + final generated = + 'test_resources/lib/gen/assets_unknown_mime_type.gen.dart'; expectedAssetsGen(pubspec, generated, fact); }); @@ -54,7 +55,7 @@ void main() { test('Assets with No lists on pubspec.yaml', () async { final pubspec = File('test_resources/pubspec_assets_no_list.yaml'); - final config = await Config(pubspec).load(); + final config = await loadPubspecConfig(pubspec); final formatter = DartFormatter( pageWidth: config.flutterGen.lineLength, lineEnding: '\n'); diff --git a/test/colors_gen_test.dart b/test/colors_gen_test.dart index 94b5caa5..a6ea28db 100644 --- a/test/colors_gen_test.dart +++ b/test/colors_gen_test.dart @@ -22,7 +22,7 @@ void main() { test('Wrong colors settings on pubspec.yaml', () async { final pubspec = File('test_resources/pubspec_colors_no_inputs.yaml'); - final config = await Config(pubspec).load(); + final config = await loadPubspecConfig(pubspec); final formatter = DartFormatter( pageWidth: config.flutterGen.lineLength, lineEnding: '\n'); @@ -33,7 +33,7 @@ void main() { test('Wrong colors settings on pubspec.yaml', () async { final pubspec = File('test_resources/pubspec_colors_no_inputs_list.yaml'); - final config = await Config(pubspec).load(); + final config = await loadPubspecConfig(pubspec); final formatter = DartFormatter( pageWidth: config.flutterGen.lineLength, lineEnding: '\n'); diff --git a/test/flutter_gen_test.dart b/test/flutter_gen_test.dart index 59e5e506..3d94f647 100644 --- a/test/flutter_gen_test.dart +++ b/test/flutter_gen_test.dart @@ -159,22 +159,10 @@ void main() { test('Wrong lineLength', () async { final pubspec = 'test_resources/pubspec_wrong_line_length.yaml'; - final assets = 'pubspec_wrong_line_length_assets.gen.dart'; - final colors = 'pubspec_wrong_line_length_colors.gen.dart'; - final fonts = 'pubspec_wrong_line_length_fonts.gen.dart'; - await FlutterGenerator( - File(pubspec), - assetsName: assets, - colorsName: colors, - fontsName: fonts, - ).build(); - expect(File('test_resources/lib/gen/$assets').readAsStringSync(), - isNotEmpty); - expect( - File('test_resources/lib/gen/$fonts').readAsStringSync(), isNotEmpty); - expect(File('test_resources/lib/gen/$colors').readAsStringSync(), - isNotEmpty); + expect(() { + return FlutterGenerator(File(pubspec)).build(); + }, throwsA(isA())); }); }); } diff --git a/test/fonts_gen_test.dart b/test/fonts_gen_test.dart index b565fda1..ac3bea0c 100644 --- a/test/fonts_gen_test.dart +++ b/test/fonts_gen_test.dart @@ -20,9 +20,9 @@ void main() { }); test('Wrong fonts settings on pubspec.yaml', () async { - final config = await Config( + final config = await loadPubspecConfig( File('test_resources/pubspec_fonts_no_family.yaml'), - ).load(); + ); final formatter = DartFormatter( pageWidth: config.flutterGen.lineLength, lineEnding: '\n'); diff --git a/test/gen_test_helper.dart b/test/gen_test_helper.dart index 966d0f76..97306cb2 100644 --- a/test/gen_test_helper.dart +++ b/test/gen_test_helper.dart @@ -18,7 +18,7 @@ void expectedAssetsGen(String pubspec, String generated, String fact) async { .build(); final pubspecFile = File(pubspec); - final config = await Config(pubspecFile).load(); + final config = await loadPubspecConfig(pubspecFile); final formatter = DartFormatter(pageWidth: config.flutterGen.lineLength, lineEnding: '\n'); @@ -38,7 +38,7 @@ void expectedColorsGen(String pubspec, String generated, String fact) async { await FlutterGenerator(File(pubspec)).build(); final pubspecFile = File(pubspec); - final config = await Config(pubspecFile).load(); + final config = await loadPubspecConfig(pubspecFile); final formatter = DartFormatter(pageWidth: config.flutterGen.lineLength, lineEnding: '\n'); @@ -58,7 +58,7 @@ void expectedFontsGen(String pubspec, String generated, String fact) async { await FlutterGenerator(File(pubspec)).build(); final pubspecFile = File(pubspec); - final config = await Config(pubspecFile).load(); + final config = await loadPubspecConfig(pubspecFile); final formatter = DartFormatter(pageWidth: config.flutterGen.lineLength, lineEnding: '\n'); From 7fd03b1f3a87b0a70d9b9d64fbb65ef690e0ef05 Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 6 Feb 2021 13:39:47 +0900 Subject: [PATCH 08/14] lineLength test --- example/pubspec.yaml | 2 +- test/config_test.dart | 14 ++++++++++++++ test/flutter_gen_test.dart | 2 +- test_resources/pubspec.yaml | 2 +- test_resources/pubspec_assets.yaml | 2 +- test_resources/pubspec_assets_camel_case.yaml | 2 +- .../pubspec_assets_flare_integrations.yaml | 2 +- test_resources/pubspec_assets_no_integrations.yaml | 2 +- test_resources/pubspec_assets_no_list.yaml | 2 +- test_resources/pubspec_assets_snake_case.yaml | 2 +- .../pubspec_assets_svg_integrations.yaml | 2 +- test_resources/pubspec_colors.yaml | 2 +- test_resources/pubspec_colors_no_inputs.yaml | 2 +- test_resources/pubspec_colors_no_inputs_list.yaml | 2 +- test_resources/pubspec_deprecated_line_length.yaml | 2 ++ test_resources/pubspec_fonts.yaml | 2 +- test_resources/pubspec_fonts_no_family.yaml | 2 +- test_resources/pubspec_ignore_files.yaml | 4 ++-- test_resources/pubspec_only_flutter_gen_value.yaml | 2 +- test_resources/pubspec_unknown_mime_type.yaml | 2 +- test_resources/pubspec_wrong_line_length.yaml | 2 +- test_resources/pubspec_wrong_output_path.yaml | 2 +- 22 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 test/config_test.dart create mode 100644 test_resources/pubspec_deprecated_line_length.yaml diff --git a/example/pubspec.yaml b/example/pubspec.yaml index e8dc54d8..c31af58f 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -25,7 +25,7 @@ dev_dependencies: flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) integrations: flutter_svg: true diff --git a/test/config_test.dart b/test/config_test.dart new file mode 100644 index 00000000..0d737cdd --- /dev/null +++ b/test/config_test.dart @@ -0,0 +1,14 @@ +import 'dart:io'; + +import 'package:flutter_gen/src/settings/config.dart'; +import 'package:test/test.dart'; + +void main() { + group('Test deprecated key', () { + test('Deprecated lineLength', () async { + final pubspec = 'test_resources/pubspec_deprecated_line_length.yaml'; + final config = await loadPubspecConfig(File(pubspec)); + expect(config.flutterGen.lineLength, 120); + }); + }); +} diff --git a/test/flutter_gen_test.dart b/test/flutter_gen_test.dart index 3d94f647..871d0e37 100644 --- a/test/flutter_gen_test.dart +++ b/test/flutter_gen_test.dart @@ -137,7 +137,7 @@ void main() { isNotEmpty); }); - test('Wrong output path', () async { + test('Empty output path', () async { final pubspec = 'test_resources/pubspec_wrong_output_path.yaml'; final assets = 'pubspec_wrong_output_path_assets.gen.dart'; final colors = 'pubspec_wrong_output_path_colors.gen.dart'; diff --git a/test_resources/pubspec.yaml b/test_resources/pubspec.yaml index b838a35b..82396463 100644 --- a/test_resources/pubspec.yaml +++ b/test_resources/pubspec.yaml @@ -2,7 +2,7 @@ name: example flutter_gen: output: lib/gen/ - lineLength: 80 + line_length: 80 integrations: flutter_svg: true diff --git a/test_resources/pubspec_assets.yaml b/test_resources/pubspec_assets.yaml index d8f675fe..7a6e77d8 100644 --- a/test_resources/pubspec_assets.yaml +++ b/test_resources/pubspec_assets.yaml @@ -2,7 +2,7 @@ name: test flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) integrations: flutter_svg: true diff --git a/test_resources/pubspec_assets_camel_case.yaml b/test_resources/pubspec_assets_camel_case.yaml index 13ce783f..4892ccd2 100644 --- a/test_resources/pubspec_assets_camel_case.yaml +++ b/test_resources/pubspec_assets_camel_case.yaml @@ -2,7 +2,7 @@ name: test flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) assets: style: camel-case diff --git a/test_resources/pubspec_assets_flare_integrations.yaml b/test_resources/pubspec_assets_flare_integrations.yaml index 8a629944..bb806829 100644 --- a/test_resources/pubspec_assets_flare_integrations.yaml +++ b/test_resources/pubspec_assets_flare_integrations.yaml @@ -2,7 +2,7 @@ name: test flutter_gen: output: lib/gen/ - lineLength: 80 + line_length: 80 integrations: flare_flutter: true diff --git a/test_resources/pubspec_assets_no_integrations.yaml b/test_resources/pubspec_assets_no_integrations.yaml index e172069f..233d1e9c 100644 --- a/test_resources/pubspec_assets_no_integrations.yaml +++ b/test_resources/pubspec_assets_no_integrations.yaml @@ -2,7 +2,7 @@ name: test flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) flutter: assets: diff --git a/test_resources/pubspec_assets_no_list.yaml b/test_resources/pubspec_assets_no_list.yaml index fe07eecd..d1e4bb2b 100644 --- a/test_resources/pubspec_assets_no_list.yaml +++ b/test_resources/pubspec_assets_no_list.yaml @@ -2,7 +2,7 @@ name: test flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) integrations: flutter_svg: true diff --git a/test_resources/pubspec_assets_snake_case.yaml b/test_resources/pubspec_assets_snake_case.yaml index 155f4346..b1b0de5a 100644 --- a/test_resources/pubspec_assets_snake_case.yaml +++ b/test_resources/pubspec_assets_snake_case.yaml @@ -2,7 +2,7 @@ name: test flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) assets: style: snake-case diff --git a/test_resources/pubspec_assets_svg_integrations.yaml b/test_resources/pubspec_assets_svg_integrations.yaml index 48410587..daa3cbf1 100644 --- a/test_resources/pubspec_assets_svg_integrations.yaml +++ b/test_resources/pubspec_assets_svg_integrations.yaml @@ -2,7 +2,7 @@ name: test flutter_gen: output: lib/gen/ - lineLength: 80 + line_length: 80 integrations: flutter_svg: true diff --git a/test_resources/pubspec_colors.yaml b/test_resources/pubspec_colors.yaml index 8aba9df9..30e0e8ed 100644 --- a/test_resources/pubspec_colors.yaml +++ b/test_resources/pubspec_colors.yaml @@ -2,7 +2,7 @@ name: test flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) colors: inputs: diff --git a/test_resources/pubspec_colors_no_inputs.yaml b/test_resources/pubspec_colors_no_inputs.yaml index d78391e5..812fda7c 100644 --- a/test_resources/pubspec_colors_no_inputs.yaml +++ b/test_resources/pubspec_colors_no_inputs.yaml @@ -2,6 +2,6 @@ name: test flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) colors: diff --git a/test_resources/pubspec_colors_no_inputs_list.yaml b/test_resources/pubspec_colors_no_inputs_list.yaml index b9eed813..a85c0c26 100644 --- a/test_resources/pubspec_colors_no_inputs_list.yaml +++ b/test_resources/pubspec_colors_no_inputs_list.yaml @@ -2,7 +2,7 @@ name: test flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) colors: inputs: diff --git a/test_resources/pubspec_deprecated_line_length.yaml b/test_resources/pubspec_deprecated_line_length.yaml new file mode 100644 index 00000000..911192e7 --- /dev/null +++ b/test_resources/pubspec_deprecated_line_length.yaml @@ -0,0 +1,2 @@ +flutter_gen: + line_length: 120 diff --git a/test_resources/pubspec_fonts.yaml b/test_resources/pubspec_fonts.yaml index c2ea2550..50ba8d73 100644 --- a/test_resources/pubspec_fonts.yaml +++ b/test_resources/pubspec_fonts.yaml @@ -2,7 +2,7 @@ name: test flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) flutter: fonts: diff --git a/test_resources/pubspec_fonts_no_family.yaml b/test_resources/pubspec_fonts_no_family.yaml index 3a188797..8154c94e 100644 --- a/test_resources/pubspec_fonts_no_family.yaml +++ b/test_resources/pubspec_fonts_no_family.yaml @@ -2,7 +2,7 @@ name: test flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) flutter: fonts: diff --git a/test_resources/pubspec_ignore_files.yaml b/test_resources/pubspec_ignore_files.yaml index e940742a..8cb20f15 100644 --- a/test_resources/pubspec_ignore_files.yaml +++ b/test_resources/pubspec_ignore_files.yaml @@ -2,10 +2,10 @@ name: test flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) flutter: assets: - assets/unknown/.DS_Store - assets/unknown/dummy.DS_Store - - assets/unknown/unknown_mime_type.bk.swp \ No newline at end of file + - assets/unknown/unknown_mime_type.bk.swp diff --git a/test_resources/pubspec_only_flutter_gen_value.yaml b/test_resources/pubspec_only_flutter_gen_value.yaml index 436227b7..03adb244 100644 --- a/test_resources/pubspec_only_flutter_gen_value.yaml +++ b/test_resources/pubspec_only_flutter_gen_value.yaml @@ -2,7 +2,7 @@ name: example flutter_gen: output: lib/gen/ - lineLength: 80 + line_length: 80 colors: inputs: diff --git a/test_resources/pubspec_unknown_mime_type.yaml b/test_resources/pubspec_unknown_mime_type.yaml index 1b356c11..5594f0b0 100644 --- a/test_resources/pubspec_unknown_mime_type.yaml +++ b/test_resources/pubspec_unknown_mime_type.yaml @@ -2,7 +2,7 @@ name: test flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) flutter: assets: diff --git a/test_resources/pubspec_wrong_line_length.yaml b/test_resources/pubspec_wrong_line_length.yaml index 99ce07bb..fdadd1ed 100644 --- a/test_resources/pubspec_wrong_line_length.yaml +++ b/test_resources/pubspec_wrong_line_length.yaml @@ -2,7 +2,7 @@ name: example flutter_gen: output: lib/gen/ - lineLength: aaaa + line_length: aaaa colors: inputs: diff --git a/test_resources/pubspec_wrong_output_path.yaml b/test_resources/pubspec_wrong_output_path.yaml index 6984d52f..8deeb793 100644 --- a/test_resources/pubspec_wrong_output_path.yaml +++ b/test_resources/pubspec_wrong_output_path.yaml @@ -2,7 +2,7 @@ name: example flutter_gen: output: - lineLength: 80 + line_length: 80 colors: inputs: From 02063c1be2f25531521cdf2461d4008e0b44db0e Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 6 Feb 2021 13:41:22 +0900 Subject: [PATCH 09/14] Add comment --- _internal/lib/src/pubspec.dart | 2 ++ lib/src/settings/pubspec.dart | 2 ++ 2 files changed, 4 insertions(+) diff --git a/_internal/lib/src/pubspec.dart b/_internal/lib/src/pubspec.dart index 346ec46a..e1fba873 100644 --- a/_internal/lib/src/pubspec.dart +++ b/_internal/lib/src/pubspec.dart @@ -2,6 +2,8 @@ import 'package:json_annotation/json_annotation.dart'; part 'pubspec.g.dart'; +/// Edit the file under _internal/lib/src/, then run `make generate-config-model` + @JsonSerializable() class Pubspec { Pubspec({this.flutterGen, this.flutter}); diff --git a/lib/src/settings/pubspec.dart b/lib/src/settings/pubspec.dart index 346ec46a..e1fba873 100644 --- a/lib/src/settings/pubspec.dart +++ b/lib/src/settings/pubspec.dart @@ -2,6 +2,8 @@ import 'package:json_annotation/json_annotation.dart'; part 'pubspec.g.dart'; +/// Edit the file under _internal/lib/src/, then run `make generate-config-model` + @JsonSerializable() class Pubspec { Pubspec({this.flutterGen, this.flutter}); From fe71285561a2539836fc69ee8285fe91cd4eb686 Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 6 Feb 2021 13:46:55 +0900 Subject: [PATCH 10/14] Supress deprecated in config --- _internal/lib/src/pubspec.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/_internal/lib/src/pubspec.dart b/_internal/lib/src/pubspec.dart index e1fba873..2a0f8905 100644 --- a/_internal/lib/src/pubspec.dart +++ b/_internal/lib/src/pubspec.dart @@ -50,12 +50,15 @@ class FlutterGen { this.integrations, this.colors, }) { + // ignore: deprecated_member_use_from_same_package if (lineLength1 <= 0 && lineLength0 <= 0) { throw ArgumentError.value( + // ignore: deprecated_member_use_from_same_package lineLength1 <= 0 ? lineLength1 : lineLength0, lineLength1 <= 0 ? 'line_length' : 'lineLength', ); } + // ignore: deprecated_member_use_from_same_package if (lineLength0 > 0) { print('Warning: key lineLength is deprecated, use line_length instead.'); } @@ -81,6 +84,7 @@ class FlutterGen { final FlutterGenColors colors; // Backwards compatible + // ignore: deprecated_member_use_from_same_package int get lineLength => lineLength0 > 0 ? lineLength0 : lineLength1; factory FlutterGen.fromJson(Map json) => _$FlutterGenFromJson(json); From 5cd32f1352d8bd635fca0f38da6b779e6b99ee3f Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 6 Feb 2021 13:49:33 +0900 Subject: [PATCH 11/14] Remove unused code --- build.yaml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/build.yaml b/build.yaml index c67b5bd9..972bd7d0 100644 --- a/build.yaml +++ b/build.yaml @@ -3,22 +3,6 @@ targets: builders: flutter_gen: enabled: true -# flutter_gen:json: -# builders: -# json_serializable: -# options: -# any_map: true -# checked: true -# create_factory: true -# create_to_json: true -# disallow_unrecognized_keys: false -# explicit_to_json: false -# field_rename: none -# generic_argument_factories: false -# ignore_unannotated: false -# include_if_null: true -# nullable: true - builders: flutter_gen: From 08aa875cb762b6ca235c6ebfcf846a9652c03ca7 Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 6 Feb 2021 14:01:35 +0900 Subject: [PATCH 12/14] Run genreate --- lib/src/settings/pubspec.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/settings/pubspec.dart b/lib/src/settings/pubspec.dart index e1fba873..2a0f8905 100644 --- a/lib/src/settings/pubspec.dart +++ b/lib/src/settings/pubspec.dart @@ -50,12 +50,15 @@ class FlutterGen { this.integrations, this.colors, }) { + // ignore: deprecated_member_use_from_same_package if (lineLength1 <= 0 && lineLength0 <= 0) { throw ArgumentError.value( + // ignore: deprecated_member_use_from_same_package lineLength1 <= 0 ? lineLength1 : lineLength0, lineLength1 <= 0 ? 'line_length' : 'lineLength', ); } + // ignore: deprecated_member_use_from_same_package if (lineLength0 > 0) { print('Warning: key lineLength is deprecated, use line_length instead.'); } @@ -81,6 +84,7 @@ class FlutterGen { final FlutterGenColors colors; // Backwards compatible + // ignore: deprecated_member_use_from_same_package int get lineLength => lineLength0 > 0 ? lineLength0 : lineLength1; factory FlutterGen.fromJson(Map json) => _$FlutterGenFromJson(json); From ba57a33911bec0b14e6af95aacc5ef95763716f7 Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 6 Feb 2021 14:01:58 +0900 Subject: [PATCH 13/14] Update README line_length key --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14a67d2d..a8e4ad87 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ $ fluttergen -c example/pubspec.yaml flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - lineLength: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) # Optional integrations: From cd2335ca8b88f883834b51640075ca77f225d694 Mon Sep 17 00:00:00 2001 From: Mao Date: Sat, 6 Feb 2021 16:19:49 +0900 Subject: [PATCH 14/14] Remove nullable for lineLength0 --- _internal/lib/src/pubspec.dart | 2 +- lib/src/settings/pubspec.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_internal/lib/src/pubspec.dart b/_internal/lib/src/pubspec.dart index 2a0f8905..fab2bcea 100644 --- a/_internal/lib/src/pubspec.dart +++ b/_internal/lib/src/pubspec.dart @@ -71,7 +71,7 @@ class FlutterGen { final int lineLength1; @deprecated - @JsonKey(name: 'lineLength', required: true, nullable: true) + @JsonKey(name: 'lineLength', required: true) final int lineLength0; @JsonKey(name: 'assets', required: true) diff --git a/lib/src/settings/pubspec.dart b/lib/src/settings/pubspec.dart index 2a0f8905..fab2bcea 100644 --- a/lib/src/settings/pubspec.dart +++ b/lib/src/settings/pubspec.dart @@ -71,7 +71,7 @@ class FlutterGen { final int lineLength1; @deprecated - @JsonKey(name: 'lineLength', required: true, nullable: true) + @JsonKey(name: 'lineLength', required: true) final int lineLength0; @JsonKey(name: 'assets', required: true)