@@ -26,9 +26,7 @@ Future<void> genIndexes(
2626 'A tool for generating index/barrel files for Dart. Ignores files that starts with underscores.' ,
2727 example: 'gen-indexes -i .' ,
2828 params: [
29- DefaultFlags .HELP .flag.copyWith (
30- negatable: true ,
31- ),
29+ DefaultFlags .HELP .flag.copyWith (negatable: true ),
3230 DefaultOptions .INPUT_PATH .option.copyWith (
3331 defaultsTo: FileSystemUtility .i.currentDir,
3432 ),
@@ -46,10 +44,7 @@ Future<void> genIndexes(
4644
4745 final help = argResults.flag (DefaultFlags .HELP .name);
4846 if (help) {
49- _print (
50- printCyan,
51- parser.getInfo (argParser),
52- );
47+ _print (printCyan, parser.getInfo (argParser));
5348 exit (ExitCodes .SUCCESS .code);
5449 }
5550
@@ -75,10 +70,7 @@ Future<void> genIndexes(
7570
7671 // ---------------------------------------------------------------------------
7772
78- _print (
79- printWhite,
80- 'Looking for files..' ,
81- );
73+ _print (printWhite, 'Looking for files..' );
8274 final filePathStream0 = PathExplorer (inputPath).exploreFiles ();
8375 final filePathStream1 = filePathStream0.where ((e) {
8476 final path = p.relative (e.path, from: inputPath);
@@ -88,106 +80,69 @@ Future<void> genIndexes(
8880 try {
8981 findings = await filePathStream1.toList ();
9082 } catch (e) {
91- _print (
92- printRed,
93- 'Failed to read file tree!' ,
94- spinner,
95- );
83+ _print (printRed, 'Failed to read file tree!' , spinner);
9684 exit (ExitCodes .FAILURE .code);
9785 }
9886 if (findings.isEmpty) {
9987 spinner.stop ();
100- _print (
101- printYellow,
102- 'No files found in $inputPath !' ,
103- );
88+ _print (printYellow, 'No files found in $inputPath !' );
10489 exit (ExitCodes .SUCCESS .code);
10590 }
10691
10792 // ---------------------------------------------------------------------------
10893
10994 final templateData = < String , String > {};
11095 for (final template in templates) {
111- _print (
112- printWhite,
113- 'Reading template at: $template ...' ,
114- );
115- final result = await MdTemplateUtility .i
116- .readTemplateFromPathOrUrl (
117- template,
118- )
119- .value;
96+ _print (printWhite, 'Reading template at: $template ...' );
97+ final result =
98+ await MdTemplateUtility .i.readTemplateFromPathOrUrl (template).value;
12099
121100 if (result.isErr ()) {
122101 spinner.stop ();
123- _print (
124- printRed,
125- ' Failed to read template!' ,
126- );
102+ _print (printRed, ' Failed to read template!' );
127103 exit (ExitCodes .FAILURE .code);
128104 }
129105 templateData[template] = result.unwrap ();
130106 }
131107
132108 // ---------------------------------------------------------------------------
133109
134- _print (
135- printWhite,
136- 'Generating...' ,
137- spinner,
138- );
110+ _print (printWhite, 'Generating...' , spinner);
139111
140112 for (final entry in templateData.entries) {
141- final fileName = p. basename (entry.key). replaceAll ( '.md' , '' ). replaceAll (
142- '{ basename}' ,
143- p. basename (inputPath),
144- );
113+ final fileName = p
114+ . basename (entry.key)
115+ . replaceAll ( '.md' , '' )
116+ . replaceAll ( '{basename}' , p. basename (inputPath) );
145117 final template = entry.value;
146118 final skipPath = p.join (inputPath, fileName);
147- final data = template.replaceData (
148- {
149- '___PUBLIC_EXPORTS___' : _publicExports (
150- inputPath,
151- findings.map ((e) => e.path).where ((e) => e != skipPath),
152- (e) => true ,
153- (e) => 'export \' ./$e \' ;' ,
154- ),
155- },
156- );
119+ final data = template.replaceData ({
120+ '___PUBLIC_EXPORTS___' : _publicExports (
121+ inputPath,
122+ findings.map ((e) => e.path).where ((e) => e != skipPath),
123+ (e) => true ,
124+ (e) => 'export \' ./$e \' ;' ,
125+ ),
126+ });
157127
158- _print (
159- printWhite,
160- 'Writing output to $fileName ...' ,
161- spinner,
162- );
128+ _print (printWhite, 'Writing output to $fileName ...' , spinner);
163129 try {
164130 await FileSystemUtility .i.writeLocalFile (fileName, data);
165131 } catch (e) {
166- _print (
167- printRed,
168- 'Failed to write at: $fileName ' ,
169- spinner,
170- );
132+ _print (printRed, 'Failed to write at: $fileName ' , spinner);
171133 exit (ExitCodes .FAILURE .code);
172134 }
173135 }
174136
175137 // ---------------------------------------------------------------------------
176138
177139 spinner.stop ();
178- _print (
179- printGreen,
180- 'Done!' ,
181- );
140+ _print (printGreen, 'Done!' );
182141}
183142
184143// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
185144
186- void _print (
187- void Function (String ) print,
188- String message, [
189- Spinner ? spinner,
190- ]) {
145+ void _print (void Function (String ) print, String message, [Spinner ? spinner]) {
191146 spinner? .stop ();
192147 print ('[gen-indexes] $message ' );
193148 spinner? .start ();
@@ -199,8 +154,9 @@ String _publicExports(
199154 bool Function (String filePath) test,
200155 String Function (String baseName) statementBuilder,
201156) {
202- final relativeFilePaths =
203- filePaths.map ((e) => p.relative (e, from: inputPath));
157+ final relativeFilePaths = filePaths.map (
158+ (e) => p.relative (e, from: inputPath),
159+ );
204160 final exportFilePaths = relativeFilePaths.where ((e) => test (e));
205161 final statements = exportFilePaths.map (statementBuilder);
206162 return statements.join ('\n ' );
0 commit comments