Skip to content

Commit f50ebdb

Browse files
feat: declare defs in config files
1 parent 306acd2 commit f50ebdb

File tree

5 files changed

+59
-44
lines changed

5 files changed

+59
-44
lines changed

configurator/bin/configurator.dart

+50-35
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,12 @@ Future<void> main(List<String> args) async {
3232
print('\n*****Configurator Starting!*****');
3333

3434
List<FileSystemEntity> files = findConfigurations(filters);
35+
List<FileSystemEntity> definitions = findDefinitions(filters);
3536

36-
if (applyDefs) {
37-
var idx = args.indexOf('-i');
38-
var input = args[idx + 1];
39-
40-
if (input.isEmpty) {
41-
throw Exception('Input not specified for definitions');
42-
}
43-
44-
if (!input.contains('.defs.yaml')) {
45-
throw Exception('Invalid file extension for definitions');
46-
}
47-
48-
await applyDefinitions(
49-
files: files,
50-
inputFile: input,
51-
);
52-
}
37+
await applyDefinitions(
38+
configFiles: files,
39+
defFiles: definitions,
40+
);
5341

5442
configure(
5543
files: files,
@@ -80,31 +68,58 @@ List<FileSystemEntity> findConfigurations(List<String> filters) {
8068
}).toList();
8169
}
8270

71+
List<FileSystemEntity> findDefinitions(List<String> filters) {
72+
return FileUtils.getFilesBreadthFirst(
73+
rootDirectory: Directory.current,
74+
extension: '.defs.yaml',
75+
ignoreTopLevelDirectories: {
76+
'.fvm',
77+
'.flutter.git',
78+
'.dart_tool',
79+
'.idea',
80+
'.gitignore',
81+
'build',
82+
'ios',
83+
'android',
84+
'web',
85+
},
86+
).where((file) => file.path.endsWith('.defs.yaml')).toList();
87+
}
88+
8389
Future<void> applyDefinitions({
84-
required List<FileSystemEntity> files,
85-
required String inputFile,
90+
required List<FileSystemEntity> configFiles,
91+
required List<FileSystemEntity> defFiles,
8692
}) async {
87-
final List<File> configFiles = files.map((e) => File(e.path)).toList();
93+
final List<File> configs = configFiles.map((e) => File(e.path)).toList();
94+
final List<File> defs = defFiles.map((e) => File(e.path)).toList();
95+
96+
for (var def in defs) {
97+
final YamlDocument document = loadYamlDocument(def.readAsStringSync());
98+
final YamlNode rootDefsNode = document.contents;
99+
100+
final String id = rootDefsNode.value['id'];
88101

89-
final File definitionsFile = File(inputFile);
102+
for (var config in configs) {
103+
var configSource = config.readAsLinesSync();
90104

91-
final YamlDocument document =
92-
loadYamlDocument(definitionsFile.readAsStringSync());
93-
final YamlNode rootNode = document.contents;
105+
if (configSource.contains('def_source: $id')) {
106+
print('Writings definitions ($id) to ${config.path}');
94107

95-
final YamlNode definitions = rootNode.value['definitions'];
96-
final YamlMap? colors = definitions.value['colors'];
97-
final YamlMap? sizes = definitions.value['sizes'];
98-
final YamlMap? flags = definitions.value['flags'];
108+
final YamlNode definitions = rootDefsNode.value['definitions'];
109+
final YamlMap? colors = definitions.value['colors'];
110+
final YamlMap? sizes = definitions.value['sizes'];
111+
final YamlMap? flags = definitions.value['flags'];
99112

100-
final Map colorsMap = Map.fromEntries(colors?.entries ?? {});
101-
final Map sizesMap = Map.fromEntries(sizes?.entries ?? {});
102-
final Map flagsMap = Map.fromEntries(flags?.entries ?? {});
113+
final Map colorsMap = Map.fromEntries(colors?.entries ?? {});
114+
final Map sizesMap = Map.fromEntries(sizes?.entries ?? {});
115+
final Map flagsMap = Map.fromEntries(flags?.entries ?? {});
116+
117+
writeDefsToFile(config, colorsMap, 'colors', true);
118+
writeDefsToFile(config, sizesMap, 'sizes');
119+
writeDefsToFile(config, flagsMap, 'flags');
120+
}
121+
}
103122

104-
for (var file in configFiles) {
105-
writeDefsToFile(file, colorsMap, 'colors', true);
106-
writeDefsToFile(file, sizesMap, 'sizes');
107-
writeDefsToFile(file, flagsMap, 'flags');
108123
}
109124
}
110125

configurator/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: configurator
22
description: A new Flutter package project.
3-
version: 0.0.39
3+
version: 0.0.40
44
homepage:
55

66
environment:

configurator_flutter/.flutter-plugins

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This is a generated file; do not edit or check into version control.
2-
path_provider=/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider-2.0.15/
3-
path_provider_android=/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_android-2.0.27/
4-
path_provider_foundation=/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.4/
5-
path_provider_linux=/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.11/
6-
path_provider_windows=/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.7/
2+
path_provider=/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider-2.1.1/
3+
path_provider_android=/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_android-2.2.0/
4+
path_provider_foundation=/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/
5+
path_provider_linux=/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/
6+
path_provider_windows=/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.4/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_android-2.0.27/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.4/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.11/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.7/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2023-08-02 17:53:57.520327","version":"3.10.5"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_android-2.2.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/cgiuliani/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2023-09-06 05:13:49.865858","version":"3.13.1"}

configurator_flutter/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: configurator_flutter
22
description: A new Flutter package project.
3-
version: 0.0.39
3+
version: 0.0.40
44
homepage:
55

66
environment:
@@ -30,7 +30,7 @@ dependencies:
3030
git:
3131
url: [email protected]:camrongiuliani/configurator.git
3232
path: configurator
33-
ref: 0.0.39
33+
ref: 0.0.40
3434

3535
dev_dependencies:
3636
flutter_test:

0 commit comments

Comments
 (0)