Skip to content

Commit 74f4205

Browse files
committed
✅ Update tests
1 parent 08749b8 commit 74f4205

File tree

11 files changed

+172
-86
lines changed

11 files changed

+172
-86
lines changed

packages/command/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/lib/gen/

packages/command/bin/flutter_gen_command.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ void main(List<String> args) {
1818
'build',
1919
abbr: 'b',
2020
help: 'Set the path of build.yaml.',
21-
defaultsTo: 'build.yaml',
2221
);
2322

2423
parser.addFlag(
@@ -57,11 +56,11 @@ void main(List<String> args) {
5756
}
5857
final pubspecFile = File(pubspecPath).absolute;
5958

60-
final buildPath = safeCast<String>(results['build']);
61-
if (buildPath == null || buildPath.trim().isEmpty) {
59+
final buildPath = safeCast<String>(results['build'])?.trim();
60+
if (buildPath?.isEmpty ?? false) {
6261
throw ArgumentError('Invalid value $buildPath', 'build');
6362
}
64-
final buildFile = File(buildPath).absolute;
63+
final buildFile = buildPath == null ? null : File(buildPath).absolute;
6564

6665
FlutterGenerator(pubspecFile, buildFile: buildFile).build();
6766
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
flutter:
2+
assets:
3+
- assets/
4+
5+
flutter_gen:
6+
assets:
7+
enabled: true
8+
style: snake-case
9+
package_parameter_enabled: true

packages/command/test/flutter_gen_command_test.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:io' show Platform;
22

3+
import 'package:flutter_gen_core/generators/generator_helper.dart' as helper;
34
import 'package:flutter_gen_core/version.gen.dart';
45
import 'package:test/test.dart';
56
import 'package:test_process/test_process.dart';
@@ -52,7 +53,7 @@ void main() {
5253
await process.shouldExit(0);
5354
});
5455

55-
test('Execute wrong argments with fluttergen --wrong', () async {
56+
test('Execute wrong arguments with fluttergen --wrong', () async {
5657
var process = await TestProcess.start(
5758
'dart',
5859
['bin/flutter_gen_command.dart', '--wrong'],
@@ -67,4 +68,20 @@ void main() {
6768
);
6869
await process.shouldExit(0);
6970
});
71+
72+
test('Execute deprecated config with fluttergen', () async {
73+
final process = await TestProcess.start(
74+
'dart',
75+
[
76+
'bin/flutter_gen_command.dart',
77+
'--config',
78+
'test/deprecated_configs.yaml',
79+
],
80+
);
81+
final errors = (await process.stderr.rest.toList()).join('\n');
82+
expect(errors, contains(helper.sWarning));
83+
expect(errors, contains('style'));
84+
expect(errors, contains('package_parameter_enabled'));
85+
await process.shouldExit(0);
86+
});
7087
}

packages/core/lib/generators/assets_generator.dart

Lines changed: 32 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -70,84 +70,42 @@ Future<String> generateAssets(
7070
LottieIntegration(config.packageParameterLiteral),
7171
];
7272

73+
// Warn for deprecated configs.
7374
final deprecatedStyle = config.flutterGen.assets.style != null;
7475
final deprecatedPackageParam =
7576
config.flutterGen.assets.packageParameterEnabled != null;
7677
if (deprecatedStyle || deprecatedPackageParam) {
77-
stderr.writeln('''
78-
79-
░░░░
80-
81-
██
82-
██░░██
83-
░░ ░░ ██░░░░░░██ ░░░░
84-
██░░░░░░░░░░██
85-
██░░░░░░░░░░██
86-
██░░░░░░░░░░░░░░██
87-
██░░░░░░██████░░░░░░██
88-
██░░░░░░██████░░░░░░██
89-
██░░░░░░░░██████░░░░░░░░██
90-
██░░░░░░░░██████░░░░░░░░██
91-
██░░░░░░░░░░██████░░░░░░░░░░██
92-
██░░░░░░░░░░░░██████░░░░░░░░░░░░██
93-
██░░░░░░░░░░░░██████░░░░░░░░░░░░██
94-
██░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░██
95-
██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██
96-
██░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░██
97-
██░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░██
98-
██░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░░░██
99-
░░ ██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██
100-
██████████████████████████████████████████
101-
102-
103-
░░''');
104-
}
105-
if (deprecatedStyle && deprecatedPackageParam) {
106-
stderr.writeln('''
107-
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
108-
│ ⚠️ Warning │
109-
│ The `style` and `package_parameter_enabled` property moved from asset to under asset.output. │
110-
│ It should be changed in the following pubspec.yaml. │
111-
│ https://github.com/FlutterGen/flutter_gen/pull/294 │
112-
│ │
113-
│ [pubspec.yaml] │
114-
│ │
115-
│ flutter_gen: │
116-
│ assets: │
117-
│ outputs: │
118-
│ style: snake-case │
119-
│ package_parameter_enabled: true │
120-
└────────────────────────────────────────────────────────────────────────────────────────────────┘''');
121-
} else if (deprecatedStyle) {
122-
stderr.writeln('''
123-
┌───────────────────────────────────────────────────────────────────────┐
124-
│ ⚠️ Warning │
125-
│ The `style` property moved from asset to under asset.output. │
126-
│ It should be changed in the following ways │
127-
│ https://github.com/FlutterGen/flutter_gen/pull/294 │
128-
│ │
129-
│ [pubspec.yaml] │
130-
│ │
131-
│ flutter_gen: │
132-
│ assets: │
133-
│ outputs: │
134-
│ style: snake-case │
135-
└───────────────────────────────────────────────────────────────────────┘''');
136-
} else if (deprecatedPackageParam) {
137-
stderr.writeln('''
138-
┌────────────────────────────────────────────────────────────────────────────────────────┐
139-
│ ⚠️ Warning │
140-
│ The `package_parameter_enabled` property moved from asset to under asset.output. │
141-
│ It should be changed in the following pubspec.yaml. │
142-
│ https://github.com/FlutterGen/flutter_gen/pull/294 │
143-
│ │
144-
│ [pubspec.yaml] │
145-
│ │
146-
│ flutter_gen: │
147-
│ assets: │
148-
│ outputs: │
149-
│ package_parameter_enabled: true │
150-
└────────────────────────────────────────────────────────────────────────────────────────┘''');
78+
stderr.writeln(sWarning);
79+
if (deprecatedStyle) {
80+
stderr.writeln(
81+
sBuildDeprecation(
82+
'style',
83+
'asset',
84+
'asset.output',
85+
'https://github.com/FlutterGen/flutter_gen/pull/294',
86+
[
87+
' assets:',
88+
' outputs:',
89+
' style: snake-case',
90+
],
91+
),
92+
);
93+
}
94+
if (deprecatedPackageParam) {
95+
stderr.writeln(
96+
sBuildDeprecation(
97+
'package_parameter_enabled',
98+
'asset',
99+
'asset.output',
100+
'https://github.com/FlutterGen/flutter_gen/pull/294',
101+
[
102+
' assets:',
103+
' outputs:',
104+
' package_parameter_enabled: true',
105+
],
106+
),
107+
);
108+
}
151109
}
152110

153111
final classesBuffer = StringBuffer();

packages/core/lib/generators/generator_helper.dart

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:collection/collection.dart';
12
import 'package:flutter_gen_core/settings/import.dart';
23

34
String get header {
@@ -21,3 +22,68 @@ String import(Import package) {
2122
return 'import \'${package.import}\''
2223
'${package.alias != null ? ' as ${package.alias}' : ''};';
2324
}
25+
26+
const sWarning = '''
27+
28+
░░░░
29+
30+
██
31+
██░░██
32+
░░ ░░ ██░░░░░░██ ░░░░
33+
██░░░░░░░░░░██
34+
██░░░░░░░░░░██
35+
██░░░░░░░░░░░░░░██
36+
██░░░░░░██████░░░░░░██
37+
██░░░░░░██████░░░░░░██
38+
██░░░░░░░░██████░░░░░░░░██
39+
██░░░░░░░░██████░░░░░░░░██
40+
██░░░░░░░░░░██████░░░░░░░░░░██
41+
██░░░░░░░░░░░░██████░░░░░░░░░░░░██
42+
██░░░░░░░░░░░░██████░░░░░░░░░░░░██
43+
██░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░██
44+
██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██
45+
██░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░██
46+
██░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░██
47+
██░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░░░██
48+
░░ ██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██
49+
██████████████████████████████████████████
50+
51+
52+
░░''';
53+
54+
String sBuildDeprecation(
55+
String deprecated,
56+
String oldLocation,
57+
String newLocation,
58+
String url,
59+
List<String> migration,
60+
) {
61+
final lines = <String>[
62+
'⚠️ Warning',
63+
'The $deprecated option has been moved from `$oldLocation` to `$newLocation`.',
64+
'It should be changed in the `pubspec.yaml`.',
65+
url,
66+
'',
67+
'```yaml',
68+
'flutter_gen:',
69+
...migration,
70+
'```'
71+
];
72+
73+
final longestLineLength = lines
74+
.map((line) => line
75+
.split('\n')
76+
.sorted((a, b) => b.length.compareTo(b.length))
77+
.first
78+
.length)
79+
.sorted((a, b) => b.compareTo(a))
80+
.first;
81+
82+
final buffer = StringBuffer();
83+
buffer.writeln('┌${'─' * (longestLineLength + 2)}┐');
84+
for (final line in lines) {
85+
buffer.writeln('| ${line.padRight(longestLineLength)} |');
86+
}
87+
buffer.writeln('└${'─' * (longestLineLength + 2)}┘');
88+
return buffer.toString();
89+
}

packages/core/lib/settings/config.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ Config loadPubspecConfig(File pubspecFile, {File? buildFile}) {
3232
'[FlutterGen] Reading options from $pubspecLocaleHint',
3333
);
3434

35+
// Fallback to the build.yaml when no build file has been specified and
36+
// the default one exists.
37+
if (buildFile == null && File('build.yaml').existsSync()) {
38+
buildFile = File('build.yaml');
39+
}
40+
3541
if (buildFile != null) {
3642
if (buildFile.existsSync()) {
3743
final buildContent = buildFile.readAsStringSync();

packages/core/lib/settings/config_default.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ flutter_gen:
1212
# Optional
1313
integrations:
1414
flutter_svg: false
15-
flare_flutter: false
1615
rive: false
1716
lottie: false
1817

packages/core/lib/settings/pubspec.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ part 'pubspec.g.dart';
44

55
// NOTE: Run `melos gen:build_runner` after editing this file
66

7-
@JsonSerializable()
7+
@JsonSerializable(disallowUnrecognizedKeys: false)
88
class Pubspec {
99
Pubspec({
1010
required this.packageName,
@@ -24,7 +24,7 @@ class Pubspec {
2424
final Flutter flutter;
2525
}
2626

27-
@JsonSerializable()
27+
@JsonSerializable(disallowUnrecognizedKeys: false)
2828
class Flutter {
2929
Flutter({
3030
required this.assets,
@@ -40,7 +40,7 @@ class Flutter {
4040
factory Flutter.fromJson(Map json) => _$FlutterFromJson(json);
4141
}
4242

43-
@JsonSerializable()
43+
@JsonSerializable(disallowUnrecognizedKeys: false)
4444
class FlutterFonts {
4545
FlutterFonts({required this.family});
4646

packages/core/lib/settings/pubspec.g.dart

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)