Skip to content

Commit df34bed

Browse files
committed
Update
1 parent 564f6c0 commit df34bed

File tree

3 files changed

+69
-78
lines changed

3 files changed

+69
-78
lines changed

lib/src/generate_screen_access/_generator_converger.dart

Lines changed: 0 additions & 65 deletions
This file was deleted.

lib/src/generate_screen_access/app.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Future<void> generateScreenAccessApp(List<String> args) async {
5353
'output',
5454
abbr: 'o',
5555
help: 'Output file path.',
56-
defaultsTo: '.',
56+
defaultsTo: './_screen_access.g.dart',
5757
)
5858
..addOption(
5959
'dart-sdk',

lib/src/generate_screen_access/generator.dart

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
99
//.title~
1010

11+
import 'package:df_config/df_config.dart';
1112
import 'package:df_gen_core/df_gen_core.dart';
1213
import 'package:df_log/df_log.dart';
14+
import 'package:df_string/df_string.dart';
1315

1416
import '_extract_class_insights_from_dart_file.dart';
15-
import '_generator_converger.dart';
1617
import '_insight_mappers.dart';
1718

1819
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
@@ -65,8 +66,8 @@ Future<void> generateScreenAccess({
6566
);
6667

6768
// For each file...
68-
for (final filePathResult in sourceFileExplorerResults.filePathResults
69-
.where((e) => e.category == _Categories.DART)) {
69+
for (final filePathResult
70+
in sourceFileExplorerResults.filePathResults.where((e) => e.category == _Categories.DART)) {
7071
final filePath = filePathResult.path;
7172

7273
// Extract insights from the file.
@@ -75,17 +76,72 @@ Future<void> generateScreenAccess({
7576
filePath,
7677
);
7778

78-
printRed(classInsights.length);
79-
8079
if (classInsights.isNotEmpty) {
81-
// Converge what was gathered to generate the output.
82-
await generatorConverger.converge(
83-
classInsights,
84-
[template],
85-
[
86-
...insightMappers,
87-
],
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.placeholder:
107+
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: classInsights.map(
114+
(e) {
115+
final a = e.className.toUpperSnakeCase();
116+
return '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_IN_$a';
117+
},
118+
),
119+
Placeholders.PATHS_ACCESSIBLE_ONLY_IF_LOGGED_OUT.placeholder: classInsights.map(
120+
(e) {
121+
final a = e.className.toUpperSnakeCase();
122+
return '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_OUT_$a';
123+
},
124+
),
125+
Placeholders.GENERATED_SCREEN_ROUTES.placeholder: classInsights.map(
126+
(e) {
127+
final a = e.className.toPascalCase();
128+
return 'generated${a}Route';
129+
},
130+
),
131+
},
88132
);
133+
134+
// Write the generated Dart file.
135+
await writeFile(outputFilePath, output);
136+
137+
// Fix the generated Dart file.
138+
await fixDartFile(outputFilePath);
139+
140+
// Format the generated Dart file.
141+
await fmtDartFile(outputFilePath);
142+
143+
// Log a success.
144+
debugLogSuccess('Generated "${previewPath(outputFilePath)}"');
89145
}
90146
}
91147

0 commit comments

Comments
 (0)