Skip to content

Commit

Permalink
Generate sorted statements (#27)
Browse files Browse the repository at this point in the history
* Generate sorted statement

* Run build on 3 os

* Rm windows

* Show generated files diff
  • Loading branch information
lcdsmao authored Sep 8, 2020
1 parent f5be67a commit ca7ccb7
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
example/lib/gen/* linguist-generated=false
test_resources/actual_data/* linguist-generated=false
5 changes: 4 additions & 1 deletion .github/workflows/flutter-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ on:

jobs:
build:
runs-on: macos-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v1
Expand Down
6 changes: 3 additions & 3 deletions example/lib/gen/assets.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions example/lib/gen/colors.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
<int, Color>{
Expand All @@ -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,
<int, Color>{
Expand All @@ -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);
}
3 changes: 2 additions & 1 deletion lib/src/generators/colors_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ String generateColors(
});

colorList
.distinctBy((color) => color.hex)
.distinctBy((color) => color.name)
.sortedBy((color) => color.name)
.map(_colorStatement)
.forEach(buffer.writeln);

Expand Down
4 changes: 3 additions & 1 deletion lib/src/generators/fonts_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,7 +19,8 @@ String generateFonts(DartFormatter formatter, FlutterFonts fonts) {
fonts.fonts
.cast<YamlMap>()
.map((element) => safeCast<String>(element['family']))
.toSet() // to Set<> for remove duplicated item
.distinct()
.sorted()
.forEach((family) {
buffer
.writeln(" static const String ${family.camelCase()} = \'$family\';");
Expand Down
3 changes: 2 additions & 1 deletion lib/src/settings/asset_type.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -32,7 +33,7 @@ class AssetType {

String get baseName => basenameWithoutExtension(path);

List<AssetType> get children => _children;
List<AssetType> get children => _children.sortedBy((e) => e.path);

void addChild(AssetType type) {
_children.add(type);
Expand Down
12 changes: 0 additions & 12 deletions lib/src/settings/color_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions test_resources/actual_data/assets.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions test_resources/actual_data/assets_no_integrations.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions test_resources/actual_data/colors.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
<int, Color>{
Expand All @@ -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,
<int, Color>{
Expand All @@ -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);
}

0 comments on commit ca7ccb7

Please sign in to comment.