-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen.dart
44 lines (36 loc) · 982 Bytes
/
gen.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import 'dart:io';
var componentTemplate = File('web/component.dart.template').readAsStringSync();
var mainFile = File('web/main.dart');
void main(List<String> args) {
var num = int.parse(args.isNotEmpty ? args.first : '10');
deleteOldFiles(num);
generateNewFiles(num);
}
void deleteOldFiles(int num) {
for (var i = 0; i < num; i++) {
try {
File('web/component$i').deleteSync();
} catch (_) {}
}
try {
mainFile.deleteSync();
} catch (_) {}
}
void generateNewFiles(int num) {
var imports = StringBuffer();
var mainCalls = StringBuffer();
for (var i = 0; i < num; i++) {
imports.writeln("import 'component${i}.dart' as component${i};");
mainCalls.writeln(' component${i}.mane();');
var f = File('web/component$i.dart');
var out = '$componentTemplate'.replaceAll('XX', '$i');
f.writeAsStringSync(out);
}
mainFile.writeAsStringSync('''
// GENERATED: $num components
$imports
void main() async {
$mainCalls
}
''');
}