1
1
import 'dart:io' show stdout, Directory, File;
2
2
3
- import 'package:dart_style/dart_style.dart' show DartFormatter;
4
3
import 'package:flutter_gen_core/generators/assets_generator.dart' ;
5
4
import 'package:flutter_gen_core/generators/colors_generator.dart' ;
6
5
import 'package:flutter_gen_core/generators/fonts_generator.dart' ;
7
6
import 'package:flutter_gen_core/settings/config.dart' ;
8
7
import 'package:flutter_gen_core/utils/file.dart' ;
8
+ import 'package:flutter_gen_core/utils/formatter.dart' ;
9
9
import 'package:path/path.dart' show join, normalize;
10
10
11
11
class FlutterGenerator {
@@ -15,29 +15,26 @@ class FlutterGenerator {
15
15
this .assetsName = 'assets.gen.dart' ,
16
16
this .colorsName = 'colors.gen.dart' ,
17
17
this .fontsName = 'fonts.gen.dart' ,
18
+ this .overrideOutputPath,
18
19
});
19
20
20
21
final File pubspecFile;
21
22
final File ? buildFile;
22
23
final String assetsName;
23
24
final String colorsName;
24
25
final String fontsName;
26
+ final String ? overrideOutputPath;
25
27
26
28
Future <void > build ({Config ? config, FileWriter ? writer}) async {
27
29
config ?? = loadPubspecConfigOrNull (pubspecFile, buildFile: buildFile);
28
30
if (config == null ) {
29
31
return ;
30
32
}
31
33
34
+ final formatter = buildDartFormatterFromConfig (config);
32
35
final flutter = config.pubspec.flutter;
33
36
final flutterGen = config.pubspec.flutterGen;
34
37
final output = config.pubspec.flutterGen.output;
35
- final lineLength = config.pubspec.flutterGen.lineLength;
36
- final formatter = DartFormatter (
37
- languageVersion: DartFormatter .latestLanguageVersion,
38
- pageWidth: lineLength,
39
- lineEnding: '\n ' ,
40
- );
41
38
42
39
void defaultWriter (String contents, String path) {
43
40
final file = File (path);
@@ -49,39 +46,40 @@ class FlutterGenerator {
49
46
50
47
writer ?? = defaultWriter;
51
48
52
- final absoluteOutput =
53
- Directory (normalize (join (pubspecFile.parent.path, output)));
49
+ final absoluteOutput = Directory (
50
+ normalize (overrideOutputPath ?? join (pubspecFile.parent.path, output)),
51
+ );
54
52
if (! absoluteOutput.existsSync ()) {
55
53
absoluteOutput.createSync (recursive: true );
56
54
}
57
55
58
- if (flutterGen.colors.enabled && flutterGen.colors.inputs.isNotEmpty) {
59
- final generated =
60
- generateColors (pubspecFile, formatter, flutterGen.colors);
61
- final colorsPath =
62
- normalize (join (pubspecFile.parent.path, output, colorsName));
63
- writer (generated, colorsPath);
64
- stdout.writeln ('[FlutterGen] Generated: $colorsPath ' );
65
- }
66
-
67
56
if (flutterGen.assets.enabled && flutter.assets.isNotEmpty) {
68
57
final generated = await generateAssets (
69
58
AssetsGenConfig .fromConfig (pubspecFile, config),
70
59
formatter,
71
60
);
72
- final assetsPath =
73
- normalize (join (pubspecFile.parent.path, output, assetsName));
61
+ final assetsPath = normalize (join (absoluteOutput.path, assetsName));
74
62
writer (generated, assetsPath);
75
63
stdout.writeln ('[FlutterGen] Generated: $assetsPath ' );
76
64
}
77
65
66
+ if (flutterGen.colors.enabled && flutterGen.colors.inputs.isNotEmpty) {
67
+ final generated = generateColors (
68
+ pubspecFile,
69
+ formatter,
70
+ flutterGen.colors,
71
+ );
72
+ final colorsPath = normalize (join (absoluteOutput.path, colorsName));
73
+ writer (generated, colorsPath);
74
+ stdout.writeln ('[FlutterGen] Generated: $colorsPath ' );
75
+ }
76
+
78
77
if (flutterGen.fonts.enabled && flutter.fonts.isNotEmpty) {
79
78
final generated = generateFonts (
80
79
FontsGenConfig .fromConfig (config),
81
80
formatter,
82
81
);
83
- final fontsPath =
84
- normalize (join (pubspecFile.parent.path, output, fontsName));
82
+ final fontsPath = normalize (join (absoluteOutput.path, fontsName));
85
83
writer (generated, fontsPath);
86
84
stdout.writeln ('[FlutterGen] Generated: $fontsPath ' );
87
85
}
0 commit comments