Skip to content

Commit b0cfa9b

Browse files
committed
Update
1 parent 3eabfbf commit b0cfa9b

File tree

1 file changed

+72
-70
lines changed

1 file changed

+72
-70
lines changed

lib/src/generate_screen_access/generator.dart

Lines changed: 72 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import 'package:df_config/df_config.dart';
1212
import 'package:df_gen_core/df_gen_core.dart';
1313
import 'package:df_log/df_log.dart';
14+
import 'package:df_screen_core/df_screen_core.dart';
1415
import 'package:df_string/df_string.dart';
1516

1617
import '_extract_class_insights_from_dart_file.dart';
@@ -65,86 +66,87 @@ Future<void> generateScreenAccess({
6566
fallbackDartSdkPath,
6667
);
6768

69+
final classInsights = <ClassInsight<ModelGenerateScreenBindings>>[];
70+
6871
// For each file...
6972
for (final filePathResult in sourceFileExplorerResults.filePathResults
7073
.where((e) => e.category == _Categories.DART)) {
7174
final filePath = filePathResult.path;
7275

7376
// Extract insights from the file.
74-
final classInsights = await extractClassInsightsFromDartFile(
77+
final temp = await extractClassInsightsFromDartFile(
7578
analysisContextCollection,
7679
filePath,
7780
);
7881

79-
if (classInsights.isNotEmpty) {
80-
final output = template.replaceData(
81-
{
82-
Placeholders.SCREEN_MAKERS.placeholder: classInsights.map(
83-
(e) {
84-
final a = e.className.toPascalCase();
85-
return 'maker$a,';
86-
},
87-
),
88-
Placeholders.PATHS.placeholder: classInsights.map(
89-
(e) {
90-
final a = e.className.toUpperSnakeCase();
91-
return '...PATH_$a';
92-
},
93-
),
94-
Placeholders.PATHS_NOT_REDIRECTABLE.placeholder: classInsights.map(
95-
(e) {
96-
final a = e.className.toUpperSnakeCase();
97-
return '...PATH_NOT_REDIRECTABLE_$a';
98-
},
99-
),
100-
Placeholders.PATHS_ALWAYS_ACCESSIBLE.placeholder: classInsights.map(
101-
(e) {
102-
final a = e.className.toUpperSnakeCase();
103-
return '...PATH_ALWAYS_ACCESSIBLE_$a';
104-
},
105-
),
106-
Placeholders.PATHS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED
107-
.placeholder: classInsights.map(
108-
(e) {
109-
final a = e.className.toUpperSnakeCase();
110-
return '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED_$a';
111-
},
112-
),
113-
Placeholders.PATHS_ACCESSIBLE_ONLY_IF_LOGGED_IN.placeholder:
114-
classInsights.map(
115-
(e) {
116-
final a = e.className.toUpperSnakeCase();
117-
return '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_IN_$a';
118-
},
119-
),
120-
Placeholders.PATHS_ACCESSIBLE_ONLY_IF_LOGGED_OUT.placeholder:
121-
classInsights.map(
122-
(e) {
123-
final a = e.className.toUpperSnakeCase();
124-
return '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_OUT_$a';
125-
},
126-
),
127-
Placeholders.GENERATED_SCREEN_ROUTES.placeholder: classInsights.map(
128-
(e) {
129-
final a = e.className.toPascalCase();
130-
return 'generated${a}Route';
131-
},
132-
),
133-
},
134-
);
135-
136-
// Write the generated Dart file.
137-
await writeFile(outputFilePath, output);
138-
139-
// Fix the generated Dart file.
140-
await fixDartFile(outputFilePath);
141-
142-
// Format the generated Dart file.
143-
await fmtDartFile(outputFilePath);
144-
145-
// Log a success.
146-
debugLogSuccess('Generated "${previewPath(outputFilePath)}"');
147-
}
82+
classInsights.addAll(temp);
83+
}
84+
85+
if (classInsights.isNotEmpty) {
86+
final output = template.replaceData(
87+
{
88+
Placeholders.SCREEN_MAKERS.placeholder: classInsights.map(
89+
(e) {
90+
final a = e.className.toPascalCase();
91+
return 'maker$a,';
92+
},
93+
).join(','),
94+
Placeholders.PATHS.placeholder: classInsights.map(
95+
(e) {
96+
final a = e.className.toUpperSnakeCase();
97+
return '...PATH_$a';
98+
},
99+
).join(','),
100+
Placeholders.PATHS_NOT_REDIRECTABLE.placeholder: classInsights.map(
101+
(e) {
102+
final a = e.className.toUpperSnakeCase();
103+
return '...PATH_NOT_REDIRECTABLE_$a';
104+
},
105+
),
106+
Placeholders.PATHS_ALWAYS_ACCESSIBLE.placeholder: classInsights.map(
107+
(e) {
108+
final a = e.className.toUpperSnakeCase();
109+
return '...PATH_ALWAYS_ACCESSIBLE_$a';
110+
},
111+
).join(','),
112+
Placeholders.PATHS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED.placeholder: classInsights.map(
113+
(e) {
114+
final a = e.className.toUpperSnakeCase();
115+
return '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED_$a';
116+
},
117+
).join(','),
118+
Placeholders.PATHS_ACCESSIBLE_ONLY_IF_LOGGED_IN.placeholder: classInsights.map(
119+
(e) {
120+
final a = e.className.toUpperSnakeCase();
121+
return '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_IN_$a';
122+
},
123+
).join(','),
124+
Placeholders.PATHS_ACCESSIBLE_ONLY_IF_LOGGED_OUT.placeholder: classInsights.map(
125+
(e) {
126+
final a = e.className.toUpperSnakeCase();
127+
return '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_OUT_$a';
128+
},
129+
).join(','),
130+
Placeholders.GENERATED_SCREEN_ROUTES.placeholder: classInsights.map(
131+
(e) {
132+
final a = e.className.toPascalCase();
133+
return 'generated${a}Route';
134+
},
135+
).join(','),
136+
},
137+
);
138+
139+
// Write the generated Dart file.
140+
await writeFile(outputFilePath, output);
141+
142+
// Fix the generated Dart file.
143+
await fixDartFile(outputFilePath);
144+
145+
// Format the generated Dart file.
146+
await fmtDartFile(outputFilePath);
147+
148+
// Log a success.
149+
debugLogSuccess('Generated "${previewPath(outputFilePath)}"');
148150
}
149151

150152
// await writeFile(outputFilePath, outputContent);

0 commit comments

Comments
 (0)