Skip to content

Commit 04aa959

Browse files
committed
♻️ Move helper message
1 parent fc52cb2 commit 04aa959

File tree

2 files changed

+98
-74
lines changed

2 files changed

+98
-74
lines changed

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+
}

0 commit comments

Comments
 (0)