Skip to content

Commit 10c357e

Browse files
committed
Update
1 parent 6961c4b commit 10c357e

File tree

3 files changed

+168
-59
lines changed

3 files changed

+168
-59
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//.title
2+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
3+
//
4+
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. See LICENSE file
5+
// in root directory.
6+
//
7+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
8+
//.title~
9+
10+
import 'package:df_gen_core/df_gen_core.dart';
11+
import 'package:df_log/df_log.dart';
12+
import 'package:df_config/df_config.dart';
13+
import 'package:df_screen_core/df_screen_core.dart';
14+
import 'package:df_string/df_string.dart';
15+
16+
import 'package:path/path.dart' as p;
17+
18+
import '_extract_class_insights_from_dart_file.dart';
19+
20+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
21+
22+
final generatorConverger = _GeneratorConverger(
23+
(replacements, templates) async {
24+
final [template] = templates;
25+
26+
final a = replacements.fold<Map<String, String>>({}, (accumulator, currentMap) {
27+
currentMap.replacements.forEach((key, value) {
28+
if (accumulator.containsKey(key)) {
29+
accumulator[key] = '${accumulator[key]},$value';
30+
} else {
31+
accumulator[key] = value;
32+
}
33+
});
34+
return accumulator;
35+
});
36+
37+
printRed(a);
38+
39+
// // Fill the template with the replacement data.
40+
// final output = replaceData(
41+
// template,
42+
// {
43+
// ...replacements.map((e) => e.replacements),
44+
// },
45+
// );
46+
47+
// // Determine the output file path.
48+
49+
// final outputFilePath = p.join('test', '.g.dart');
50+
51+
// // Write the generated Dart file.
52+
// await writeFile(outputFilePath, output);
53+
54+
// // Fix the generated Dart file.
55+
// await fixDartFile(outputFilePath);
56+
57+
// // Format the generated Dart file.
58+
// await fmtDartFile(outputFilePath);
59+
60+
// // Log a success.
61+
// debugLogSuccess('Generated "${previewPath(outputFilePath)}"');
62+
},
63+
);
64+
65+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
66+
67+
typedef _GeneratorConverger
68+
= GeneratorConverger<ClassInsight<ModelGenerateScreenBindings>, Enum, String>;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//.title
2+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
3+
//
4+
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. See LICENSE file
5+
// in root directory.
6+
//
7+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
8+
//.title~
9+
10+
import 'package:df_gen_core/df_gen_core.dart';
11+
import 'package:df_screen_core/df_screen_core.dart';
12+
import 'package:df_string/df_string.dart';
13+
14+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
15+
16+
final insightMappers = [
17+
_InsightMapper(
18+
placeholder: Placeholders.SCREEN_MAKERS,
19+
mapInsights: (insight) async {
20+
final a = insight.className.toPascalCase();
21+
return 'maker$a';
22+
},
23+
),
24+
_InsightMapper(
25+
placeholder: Placeholders.PATHS,
26+
mapInsights: (insight) async {
27+
final a = insight.className.toUpperSnakeCase();
28+
return '...PATH_$a';
29+
},
30+
),
31+
_InsightMapper(
32+
placeholder: Placeholders.PATHS_NOT_REDIRECTABLE,
33+
mapInsights: (insight) async {
34+
final a = insight.className.toUpperSnakeCase();
35+
return '...PATH_NOT_REDIRECTABLE_$a';
36+
},
37+
),
38+
_InsightMapper(
39+
placeholder: Placeholders.PATHS_ALWAYS_ACCESSIBLE,
40+
mapInsights: (insight) async {
41+
final a = insight.className.toUpperSnakeCase();
42+
return '...PATH_ALWAYS_ACCESSIBLE_$a';
43+
},
44+
),
45+
_InsightMapper(
46+
placeholder: Placeholders.PATHS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED,
47+
mapInsights: (insight) async {
48+
final a = insight.className.toUpperSnakeCase();
49+
return '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED_$a';
50+
},
51+
),
52+
_InsightMapper(
53+
placeholder: Placeholders.PATHS_ACCESSIBLE_ONLY_IF_LOGGED_IN,
54+
mapInsights: (insight) async {
55+
final a = insight.className.toUpperSnakeCase();
56+
return '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_IN_$a';
57+
},
58+
),
59+
_InsightMapper(
60+
placeholder: Placeholders.PATHS_ACCESSIBLE_ONLY_IF_LOGGED_OUT,
61+
mapInsights: (insight) async {
62+
final a = insight.className.toUpperSnakeCase();
63+
return '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_OUT_$a';
64+
},
65+
),
66+
_InsightMapper(
67+
placeholder: Placeholders.GENERATED_SCREEN_ROUTES,
68+
mapInsights: (insight) async {
69+
final a = insight.className.toPascalCase();
70+
return 'generated${a}Route';
71+
},
72+
),
73+
];
74+
75+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
76+
77+
enum Placeholders {
78+
SCREEN_MAKERS,
79+
PATHS,
80+
PATHS_NOT_REDIRECTABLE,
81+
PATHS_ALWAYS_ACCESSIBLE,
82+
PATHS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED,
83+
PATHS_ACCESSIBLE_ONLY_IF_LOGGED_IN,
84+
PATHS_ACCESSIBLE_ONLY_IF_LOGGED_OUT,
85+
GENERATED_SCREEN_ROUTES,
86+
}
87+
88+
typedef _InsightMapper = InsightMapper<ClassInsight<ModelGenerateScreenBindings>, Placeholders>;

lib/src/generate_screen_access/generator.dart

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import 'package:df_gen_core/df_gen_core.dart';
1212
import 'package:df_log/df_log.dart';
1313

1414
import '_extract_class_insights_from_dart_file.dart';
15+
import '_generator_converger.dart';
16+
import '_insight_mappers.dart';
1517

1618
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
1719

@@ -54,8 +56,6 @@ Future<void> generateScreenAccess({
5456
),
5557
);
5658

57-
printRed(template.length);
58-
5959
// ---------------------------------------------------------------------------
6060

6161
// Create context for the Dart analyzer.
@@ -65,8 +65,8 @@ Future<void> generateScreenAccess({
6565
);
6666

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

7272
// Extract insights from the file.
@@ -77,65 +77,18 @@ Future<void> generateScreenAccess({
7777

7878
if (classInsights.isNotEmpty) {
7979
// Converge what was gathered to generate the output.
80-
// await generatorConverger.converge(
81-
// classInsights,
82-
// [template],
83-
// [
84-
// ...insightMappersA,
85-
// ...insightMappersB,
86-
// ],
87-
// );
80+
await generatorConverger.converge(
81+
classInsights,
82+
[template],
83+
[
84+
...insightMappers,
85+
],
86+
);
8887
}
8988
}
9089

91-
// final screenClassNames = <String>{};
92-
// for (final dirPath in combinePathSets([rootDirPaths, subDirPaths])) {
93-
// final filePaths = await listFilePaths(dirPath);
94-
// if (filePaths != null) {
95-
// filePaths.sort();
96-
// for (final filePath in filePaths) {
97-
// if (isGeneratedDartFilePath(filePath) && matchesAnyPathPattern(filePath, pathPatterns)) {
98-
// var screenFileKey = getBaseName(filePath).replaceAll('.g.dart', '');
99-
// screenFileKey =
100-
// screenFileKey.startsWith('_') ? screenFileKey.substring(1) : screenFileKey;
101-
// final contents = await readFile(filePath);
102-
// if (contents != null) {
103-
// final x = RegExp(r'''const +_CLASS += +["'](\w+)["'];''');
104-
// final match = x.firstMatch(contents);
105-
// if (match != null && match.groupCount == 1) {
106-
// final screenClassName = match.group(1);
107-
// if (screenClassName != null) {
108-
// screenClassNames1.add(screenClassName);
109-
// }
110-
// }
111-
// }
112-
// }
113-
// }
114-
// }
115-
// }
116-
// final sorted = screenClassNames1.toList()..sort();
117-
// final keys = sorted.map((e) => e.toSnakeCase().toUpperCase());
118-
// final a = sorted.map((e) => 'maker$e').join(',');
119-
// final b = keys.map((e) => '...PATH_$e').join(',');
120-
// final c = keys.map((e) => '...PATH_NOT_REDIRECTABLE_$e').join(',');
121-
// final d = keys.map((e) => '...PATH_ALWAYS_ACCESSIBLE_$e').join(',');
122-
// final e = keys.map((e) => '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED_$e').join(',');
123-
// final f = keys.map((e) => '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_IN_$e').join(',');
124-
// final g = keys.map((e) => '...PATH_ACCESSIBLE_ONLY_IF_LOGGED_OUT_$e').join(',');
125-
// final h = sorted.map((e) => 'generated${e}Route').join(',');
126-
// final template = (await readSnippetsFromMarkdownFile(templateFilePath)).join('\n');
127-
// final outputContent = replaceData(template, {
128-
// '___SCREEN_MAKERS___': a,
129-
// '___PATHS___': b,
130-
// '___PATHS_NOT_REDIRECTABLE___': c,
131-
// '___PATHS_ALWAYS_ACCESSIBLE___': d,
132-
// '___PATHS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED___': e,
133-
// '___PATHS_ACCESSIBLE_ONLY_IF_LOGGED_IN___': f,
134-
// '___PATHS_ACCESSIBLE_ONLY_IF_LOGGED_OUT___': g,
135-
// '___GENERATED_SCREEN_ROUTES___': h,
136-
// });
13790
// await writeFile(outputFilePath, outputContent);
138-
// Here().debugLogStop('Done!');
91+
Here().debugLogStop('Done!');
13992
}
14093

14194
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

0 commit comments

Comments
 (0)