Skip to content

Commit ca7ccb7

Browse files
authored
Generate sorted statements (#27)
* Generate sorted statement * Run build on 3 os * Rm windows * Show generated files diff
1 parent f5be67a commit ca7ccb7

File tree

11 files changed

+36
-39
lines changed

11 files changed

+36
-39
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
example/lib/gen/* linguist-generated=false
2+
test_resources/actual_data/* linguist-generated=false

.github/workflows/flutter-ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ on:
1010

1111
jobs:
1212
build:
13-
runs-on: macos-latest
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest, macos-latest]
16+
runs-on: ${{ matrix.os }}
1417
steps:
1518
- uses: actions/checkout@v2
1619
- uses: subosito/flutter-action@v1

example/lib/gen/assets.gen.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ class $PicturesGen {
1616
class $AssetsImagesGen {
1717
const $AssetsImagesGen();
1818

19-
AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg');
2019
AssetGenImage get chip1 => const AssetGenImage('assets/images/chip1.jpg');
21-
AssetGenImage get logo => const AssetGenImage('assets/images/logo.png');
22-
AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg');
20+
AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg');
2321
$AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen();
2422
$AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen();
2523
$AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen();
24+
AssetGenImage get logo => const AssetGenImage('assets/images/logo.png');
25+
AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg');
2626
}
2727

2828
class $AssetsJsonGen {

example/lib/gen/colors.gen.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import 'package:flutter/material.dart';
99
class ColorName {
1010
ColorName._();
1111

12-
static const Color white = Color(0xFFFFFFFF);
1312
static const Color black = Color(0xFF000000);
14-
static const Color gray70 = Color(0xFFEEEEEE);
15-
static const Color gray410 = Color(0xFF979797);
13+
static const Color black30 = Color(0x4D000000);
14+
static const Color black40 = Color(0x66000000);
15+
static const Color black50 = Color(0x80000000);
16+
static const Color black60 = Color(0x99000000);
1617
static const MaterialColor crimsonRed = MaterialColor(
1718
0xFFCF2A2A,
1819
<int, Color>{
@@ -28,6 +29,9 @@ class ColorName {
2829
900: Color(0xFFB20F0F),
2930
},
3031
);
32+
static const Color gray410 = Color(0xFF979797);
33+
static const Color gray70 = Color(0xFFEEEEEE);
34+
static const Color white = Color(0xFFFFFFFF);
3135
static const MaterialColor yellowOcher = MaterialColor(
3236
0xFFDF9527,
3337
<int, Color>{
@@ -43,8 +47,4 @@ class ColorName {
4347
900: Color(0xFFCA670E),
4448
},
4549
);
46-
static const Color black30 = Color(0x4D000000);
47-
static const Color black40 = Color(0x66000000);
48-
static const Color black50 = Color(0x80000000);
49-
static const Color black60 = Color(0x99000000);
5050
}

lib/src/generators/colors_generator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ String generateColors(
4343
});
4444

4545
colorList
46-
.distinctBy((color) => color.hex)
46+
.distinctBy((color) => color.name)
47+
.sortedBy((color) => color.name)
4748
.map(_colorStatement)
4849
.forEach(buffer.writeln);
4950

lib/src/generators/fonts_generator.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter_gen/src/settings/flutter.dart';
44
import 'package:flutter_gen/src/utils/camel_case.dart';
55
import 'package:flutter_gen/src/utils/cast.dart';
66
import 'package:yaml/yaml.dart';
7+
import 'package:dartx/dartx.dart';
78

89
String generateFonts(DartFormatter formatter, FlutterFonts fonts) {
910
assert(fonts != null && fonts.hasFonts,
@@ -18,7 +19,8 @@ String generateFonts(DartFormatter formatter, FlutterFonts fonts) {
1819
fonts.fonts
1920
.cast<YamlMap>()
2021
.map((element) => safeCast<String>(element['family']))
21-
.toSet() // to Set<> for remove duplicated item
22+
.distinct()
23+
.sorted()
2224
.forEach((family) {
2325
buffer
2426
.writeln(" static const String ${family.camelCase()} = \'$family\';");

lib/src/settings/asset_type.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:mime/mime.dart';
22
import 'package:path/path.dart';
3+
import 'package:dartx/dartx.dart';
34

45
/// https://github.com/dart-lang/mime/blob/master/lib/src/default_extension_map.dart
56
class AssetType {
@@ -32,7 +33,7 @@ class AssetType {
3233

3334
String get baseName => basenameWithoutExtension(path);
3435

35-
List<AssetType> get children => _children;
36+
List<AssetType> get children => _children.sortedBy((e) => e.path);
3637

3738
void addChild(AssetType type) {
3839
_children.add(type);

lib/src/settings/color_path.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,4 @@ class ColorPath {
1414

1515
/// https://api.flutter.dev/flutter/widgets/Image-class.html
1616
bool get isXml => mime == 'application/xml';
17-
18-
@override
19-
// ignore: avoid_equals_and_hash_code_on_mutable_classes
20-
bool operator ==(Object other) =>
21-
identical(this, other) ||
22-
other is ColorPath &&
23-
runtimeType == other.runtimeType &&
24-
path == other.path;
25-
26-
@override
27-
// ignore: avoid_equals_and_hash_code_on_mutable_classes
28-
int get hashCode => path.hashCode;
2917
}

test_resources/actual_data/assets.gen.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ class $PicturesGen {
1616
class $AssetsImagesGen {
1717
const $AssetsImagesGen();
1818

19-
AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg');
2019
AssetGenImage get chip1 => const AssetGenImage('assets/images/chip1.jpg');
21-
AssetGenImage get logo => const AssetGenImage('assets/images/logo.png');
22-
AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg');
20+
AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg');
2321
$AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen();
2422
$AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen();
2523
$AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen();
24+
AssetGenImage get logo => const AssetGenImage('assets/images/logo.png');
25+
AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg');
2626
}
2727

2828
class $AssetsJsonGen {

test_resources/actual_data/assets_no_integrations.gen.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class $PicturesGen {
1414
class $AssetsImagesGen {
1515
const $AssetsImagesGen();
1616

17-
AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg');
1817
AssetGenImage get chip1 => const AssetGenImage('assets/images/chip1.jpg');
19-
AssetGenImage get logo => const AssetGenImage('assets/images/logo.png');
20-
AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg');
18+
AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg');
2119
$AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen();
2220
$AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen();
2321
$AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen();
22+
AssetGenImage get logo => const AssetGenImage('assets/images/logo.png');
23+
AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg');
2424
}
2525

2626
class $AssetsJsonGen {

0 commit comments

Comments
 (0)