@@ -18,14 +18,13 @@ import 'package:path/path.dart' as p;
1818
1919import 'extract_insights_from_file.dart' ;
2020
21- const _OUTPUT_FILE_NAME = '_access.g.dart' ;
22-
2321// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2422
2523Future <void > genScreenAccessApp (
2624 List <String > args, {
27- String defaultTemplatePathOrUrl =
28- 'https://raw.githubusercontent.com/robmllze/df_generate_screen/main/templates/v1/access.dart.md' ,
25+ List <String > defaultTemplates = const [
26+ 'https://raw.githubusercontent.com/robmllze/df_generate_screen/main/templates/v1/_access.g.dart.md' ,
27+ ],
2928}) async {
3029 final parser = CliParser (
3130 title: 'DevCetra.com/df/tools' ,
@@ -39,8 +38,8 @@ Future<void> genScreenAccessApp(
3938 DefaultOptions .INPUT_PATH .option.copyWith (
4039 defaultsTo: FileSystemUtility .i.currentDir,
4140 ),
42- DefaultOptions . TEMPLATE_PATH_OR_URL .option .copyWith (
43- defaultsTo: defaultTemplatePathOrUrl ,
41+ DefaultMultiOptions . TEMPLATES .multiOption .copyWith (
42+ defaultsTo: defaultTemplates ,
4443 ),
4544 DefaultOptions .DART_SDK .option,
4645 ],
@@ -55,11 +54,11 @@ Future<void> genScreenAccessApp(
5554 exit (ExitCodes .SUCCESS .code);
5655 }
5756 late final String inputPath;
58- late final String templatePathOrUrl ;
57+ late final List < String > templates ;
5958 late final String ? dartSdk;
6059 try {
6160 inputPath = argResults.option (DefaultOptions .INPUT_PATH .name)! ;
62- templatePathOrUrl = argResults.option ( DefaultOptions . TEMPLATE_PATH_OR_URL .name)! ;
61+ templates = argResults.multiOption ( DefaultMultiOptions . TEMPLATES .name);
6362 dartSdk = argResults.option (DefaultOptions .DART_SDK .name);
6463 } catch (_) {
6564 _print (
@@ -76,23 +75,6 @@ Future<void> genScreenAccessApp(
7675 final spinner = Spinner ();
7776 spinner.start ();
7877
79- _print (
80- printWhite,
81- 'Reading template at: $templatePathOrUrl ...' ,
82- );
83- final result = await MdTemplateUtility .i.readTemplateFromPathOrUrl (
84- templatePathOrUrl,
85- );
86- final template = result.unwrap ();
87- if (result.isErr) {
88- _print (
89- printRed,
90- ' Failed to read template!' ,
91- spinner,
92- );
93- exit (ExitCodes .FAILURE .code);
94- }
95-
9678 _print (
9779 printWhite,
9880 'Looking for Dart files..' ,
@@ -103,10 +85,10 @@ Future<void> genScreenAccessApp(
10385 try {
10486 findings = await filePathStream1.toList ();
10587 } catch (e) {
88+ spinner.stop ();
10689 _print (
10790 printRed,
10891 'Failed to read file tree!' ,
109- spinner,
11092 );
11193 exit (ExitCodes .FAILURE .code);
11294 }
@@ -119,38 +101,67 @@ Future<void> genScreenAccessApp(
119101 exit (ExitCodes .SUCCESS .code);
120102 }
121103
104+ final templateData = < String , String > {};
105+ for (final template in templates) {
106+ _print (
107+ printWhite,
108+ 'Reading template at: $template ...' ,
109+ );
110+ final result = await MdTemplateUtility .i.readTemplateFromPathOrUrl (
111+ template,
112+ );
113+
114+ final data = result.unwrap ();
115+ if (result.isErr) {
116+ spinner.stop ();
117+ _print (
118+ printRed,
119+ ' Failed to read template!' ,
120+ );
121+ exit (ExitCodes .FAILURE .code);
122+ }
123+ templateData[template] = data;
124+ }
125+
122126 _print (
123127 printWhite,
124- 'Generating access file ...' ,
128+ 'Generating...' ,
125129 spinner,
126130 );
127- try {
128- for (final finding in findings) {
129- final inputFilePath = finding.path;
130- final insights = await extractInsightsFromFile (
131- inputFilePath,
132- analysisContextCollection,
133- );
134-
135- final output = _interpolator.interpolate (template, insights, ',' );
136131
137- final outputFilePath = p.join (
138- PathUtility .i.localDirName (inputFilePath),
139- _OUTPUT_FILE_NAME ,
140- );
141- await FileSystemUtility .i.writeLocalFile (outputFilePath, output);
142- printWhite (
143- '[gen-screen-access] ✔ Generated $_OUTPUT_FILE_NAME ' ,
132+ for (final entry in templateData.entries) {
133+ final fileName = p.basename (entry.key).replaceAll ('.md' , '' );
134+ final template = entry.value;
135+
136+ try {
137+ for (final finding in findings) {
138+ final inputFilePath = finding.path;
139+ final insights = await extractInsightsFromFile (
140+ inputFilePath,
141+ analysisContextCollection,
142+ );
143+
144+ final output = _interpolator.interpolate (template, insights, ',' );
145+
146+ final outputFilePath = p.join (
147+ PathUtility .i.localDirName (inputFilePath),
148+ fileName,
149+ );
150+ await FileSystemUtility .i.writeLocalFile (outputFilePath, output);
151+ printWhite (
152+ '[gen-screen-access] ✔ Generated $fileName ' ,
153+ );
154+ }
155+ } catch (e) {
156+ _print (
157+ printRed,
158+ '✘ One or more files failed to generate!' ,
159+ spinner,
144160 );
161+ exit (ExitCodes .FAILURE .code);
145162 }
146- } catch (e) {
147- _print (
148- printRed,
149- '✘ One or more files failed to generate!' ,
150- spinner,
151- );
152- exit (ExitCodes .FAILURE .code);
153163 }
164+
154165 _print (
155166 printWhite,
156167 'Fixing generated files..' ,
0 commit comments