From 5f6dc51ea18845f20451f56aaa97ceea8f973978 Mon Sep 17 00:00:00 2001 From: Mao Date: Tue, 8 Sep 2020 20:45:49 +0900 Subject: [PATCH 1/4] Generate sorted statement --- example/lib/gen/assets.gen.dart | 6 +++--- example/lib/gen/colors.gen.dart | 14 +++++++------- lib/src/generators/colors_generator.dart | 3 ++- lib/src/generators/fonts_generator.dart | 4 +++- lib/src/settings/asset_type.dart | 3 ++- lib/src/settings/color_path.dart | 12 ------------ test_resources/actual_data/assets.gen.dart | 6 +++--- .../actual_data/assets_no_integrations.gen.dart | 6 +++--- test_resources/actual_data/colors.gen.dart | 14 +++++++------- 9 files changed, 30 insertions(+), 38 deletions(-) diff --git a/example/lib/gen/assets.gen.dart b/example/lib/gen/assets.gen.dart index 5aa085454..1889f25fb 100644 --- a/example/lib/gen/assets.gen.dart +++ b/example/lib/gen/assets.gen.dart @@ -16,13 +16,13 @@ class $PicturesGen { class $AssetsImagesGen { const $AssetsImagesGen(); - AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg'); AssetGenImage get chip1 => const AssetGenImage('assets/images/chip1.jpg'); - AssetGenImage get logo => const AssetGenImage('assets/images/logo.png'); - AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg'); + AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg'); $AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen(); $AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen(); $AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen(); + AssetGenImage get logo => const AssetGenImage('assets/images/logo.png'); + AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg'); } class $AssetsJsonGen { diff --git a/example/lib/gen/colors.gen.dart b/example/lib/gen/colors.gen.dart index 68ef4ebb6..abe07b544 100644 --- a/example/lib/gen/colors.gen.dart +++ b/example/lib/gen/colors.gen.dart @@ -9,10 +9,11 @@ import 'package:flutter/material.dart'; class ColorName { ColorName._(); - static const Color white = Color(0xFFFFFFFF); static const Color black = Color(0xFF000000); - static const Color gray70 = Color(0xFFEEEEEE); - static const Color gray410 = Color(0xFF979797); + static const Color black30 = Color(0x4D000000); + static const Color black40 = Color(0x66000000); + static const Color black50 = Color(0x80000000); + static const Color black60 = Color(0x99000000); static const MaterialColor crimsonRed = MaterialColor( 0xFFCF2A2A, { @@ -28,6 +29,9 @@ class ColorName { 900: Color(0xFFB20F0F), }, ); + static const Color gray410 = Color(0xFF979797); + static const Color gray70 = Color(0xFFEEEEEE); + static const Color white = Color(0xFFFFFFFF); static const MaterialColor yellowOcher = MaterialColor( 0xFFDF9527, { @@ -43,8 +47,4 @@ class ColorName { 900: Color(0xFFCA670E), }, ); - static const Color black30 = Color(0x4D000000); - static const Color black40 = Color(0x66000000); - static const Color black50 = Color(0x80000000); - static const Color black60 = Color(0x99000000); } diff --git a/lib/src/generators/colors_generator.dart b/lib/src/generators/colors_generator.dart index 35978f942..051c3ac51 100644 --- a/lib/src/generators/colors_generator.dart +++ b/lib/src/generators/colors_generator.dart @@ -43,7 +43,8 @@ String generateColors( }); colorList - .distinctBy((color) => color.hex) + .distinctBy((color) => color.name) + .sortedBy((color) => color.name) .map(_colorStatement) .forEach(buffer.writeln); diff --git a/lib/src/generators/fonts_generator.dart b/lib/src/generators/fonts_generator.dart index 24ae97315..ffa79467f 100644 --- a/lib/src/generators/fonts_generator.dart +++ b/lib/src/generators/fonts_generator.dart @@ -4,6 +4,7 @@ import 'package:flutter_gen/src/settings/flutter.dart'; import 'package:flutter_gen/src/utils/camel_case.dart'; import 'package:flutter_gen/src/utils/cast.dart'; import 'package:yaml/yaml.dart'; +import 'package:dartx/dartx.dart'; String generateFonts(DartFormatter formatter, FlutterFonts fonts) { assert(fonts != null && fonts.hasFonts, @@ -18,7 +19,8 @@ String generateFonts(DartFormatter formatter, FlutterFonts fonts) { fonts.fonts .cast() .map((element) => safeCast(element['family'])) - .toSet() // to Set<> for remove duplicated item + .distinct() + .sorted() .forEach((family) { buffer .writeln(" static const String ${family.camelCase()} = \'$family\';"); diff --git a/lib/src/settings/asset_type.dart b/lib/src/settings/asset_type.dart index 5f89dddbd..0578eec6c 100644 --- a/lib/src/settings/asset_type.dart +++ b/lib/src/settings/asset_type.dart @@ -1,5 +1,6 @@ import 'package:mime/mime.dart'; import 'package:path/path.dart'; +import 'package:dartx/dartx.dart'; /// https://github.com/dart-lang/mime/blob/master/lib/src/default_extension_map.dart class AssetType { @@ -32,7 +33,7 @@ class AssetType { String get baseName => basenameWithoutExtension(path); - List get children => _children; + List get children => _children.sortedBy((e) => e.path); void addChild(AssetType type) { _children.add(type); diff --git a/lib/src/settings/color_path.dart b/lib/src/settings/color_path.dart index 5d2dd8dbe..6376c25ae 100644 --- a/lib/src/settings/color_path.dart +++ b/lib/src/settings/color_path.dart @@ -14,16 +14,4 @@ class ColorPath { /// https://api.flutter.dev/flutter/widgets/Image-class.html bool get isXml => mime == 'application/xml'; - - @override - // ignore: avoid_equals_and_hash_code_on_mutable_classes - bool operator ==(Object other) => - identical(this, other) || - other is ColorPath && - runtimeType == other.runtimeType && - path == other.path; - - @override - // ignore: avoid_equals_and_hash_code_on_mutable_classes - int get hashCode => path.hashCode; } diff --git a/test_resources/actual_data/assets.gen.dart b/test_resources/actual_data/assets.gen.dart index 5aa085454..1889f25fb 100644 --- a/test_resources/actual_data/assets.gen.dart +++ b/test_resources/actual_data/assets.gen.dart @@ -16,13 +16,13 @@ class $PicturesGen { class $AssetsImagesGen { const $AssetsImagesGen(); - AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg'); AssetGenImage get chip1 => const AssetGenImage('assets/images/chip1.jpg'); - AssetGenImage get logo => const AssetGenImage('assets/images/logo.png'); - AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg'); + AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg'); $AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen(); $AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen(); $AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen(); + AssetGenImage get logo => const AssetGenImage('assets/images/logo.png'); + AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg'); } class $AssetsJsonGen { diff --git a/test_resources/actual_data/assets_no_integrations.gen.dart b/test_resources/actual_data/assets_no_integrations.gen.dart index 191dc1f8f..69fcefcfe 100644 --- a/test_resources/actual_data/assets_no_integrations.gen.dart +++ b/test_resources/actual_data/assets_no_integrations.gen.dart @@ -14,13 +14,13 @@ class $PicturesGen { class $AssetsImagesGen { const $AssetsImagesGen(); - AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg'); AssetGenImage get chip1 => const AssetGenImage('assets/images/chip1.jpg'); - AssetGenImage get logo => const AssetGenImage('assets/images/logo.png'); - AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg'); + AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg'); $AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen(); $AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen(); $AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen(); + AssetGenImage get logo => const AssetGenImage('assets/images/logo.png'); + AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg'); } class $AssetsJsonGen { diff --git a/test_resources/actual_data/colors.gen.dart b/test_resources/actual_data/colors.gen.dart index 68ef4ebb6..abe07b544 100644 --- a/test_resources/actual_data/colors.gen.dart +++ b/test_resources/actual_data/colors.gen.dart @@ -9,10 +9,11 @@ import 'package:flutter/material.dart'; class ColorName { ColorName._(); - static const Color white = Color(0xFFFFFFFF); static const Color black = Color(0xFF000000); - static const Color gray70 = Color(0xFFEEEEEE); - static const Color gray410 = Color(0xFF979797); + static const Color black30 = Color(0x4D000000); + static const Color black40 = Color(0x66000000); + static const Color black50 = Color(0x80000000); + static const Color black60 = Color(0x99000000); static const MaterialColor crimsonRed = MaterialColor( 0xFFCF2A2A, { @@ -28,6 +29,9 @@ class ColorName { 900: Color(0xFFB20F0F), }, ); + static const Color gray410 = Color(0xFF979797); + static const Color gray70 = Color(0xFFEEEEEE); + static const Color white = Color(0xFFFFFFFF); static const MaterialColor yellowOcher = MaterialColor( 0xFFDF9527, { @@ -43,8 +47,4 @@ class ColorName { 900: Color(0xFFCA670E), }, ); - static const Color black30 = Color(0x4D000000); - static const Color black40 = Color(0x66000000); - static const Color black50 = Color(0x80000000); - static const Color black60 = Color(0x99000000); } From 61e2f88e6c108706e29b09eabb75072d95b3c948 Mon Sep 17 00:00:00 2001 From: Mao Date: Tue, 8 Sep 2020 20:46:29 +0900 Subject: [PATCH 2/4] Run build on 3 os --- .github/workflows/flutter-ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/flutter-ci.yml b/.github/workflows/flutter-ci.yml index eca64f45c..2be12e2e6 100644 --- a/.github/workflows/flutter-ci.yml +++ b/.github/workflows/flutter-ci.yml @@ -10,7 +10,10 @@ on: jobs: build: - runs-on: macos-latest + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - uses: subosito/flutter-action@v1 From 464b7b560fed27f0255d7a6ed72bb9dc6559e9ce Mon Sep 17 00:00:00 2001 From: Mao Date: Tue, 8 Sep 2020 21:10:41 +0900 Subject: [PATCH 3/4] Rm windows --- .github/workflows/flutter-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/flutter-ci.yml b/.github/workflows/flutter-ci.yml index 2be12e2e6..9894c8fd7 100644 --- a/.github/workflows/flutter-ci.yml +++ b/.github/workflows/flutter-ci.yml @@ -12,7 +12,7 @@ jobs: build: strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 From b150d12afe7c3449fb4a05c4e5a349403343eefb Mon Sep 17 00:00:00 2001 From: Mao Date: Tue, 8 Sep 2020 21:18:47 +0900 Subject: [PATCH 4/4] Show generated files diff --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..13b5adb74 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +example/lib/gen/* linguist-generated=false +test_resources/actual_data/* linguist-generated=false