-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhydrate.dart
More file actions
64 lines (51 loc) · 1.65 KB
/
Copy pathhydrate.dart
File metadata and controls
64 lines (51 loc) · 1.65 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import 'dart:convert';
import 'dart:io';
void hydrate(String coreFile, String templateFile, String outputFile) {
print('Processing $coreFile -> $outputFile...');
final coreFileObj = File(coreFile);
if (!coreFileObj.existsSync()) {
print('Error: $coreFile not found');
exit(1);
}
// Read core logic as string and normalize line endings to LF (\n)
final coreContent = coreFileObj.readAsStringSync().replaceAll('\r\n', '\n');
// Encode payload to base64
final payload = base64Encode(utf8.encode(coreContent));
final templateFileObj = File(templateFile);
if (!templateFileObj.existsSync()) {
print('Error: $templateFile not found');
exit(1);
}
// Read template as string (assuming UTF-8)
// We use readAsString to easily do string replacement,
// ensuring we handle the template text correctly.
// Note: Binary replacement would be safer for unknown encodings,
// but source files are likely UTF-8 text.
String templateContent = templateFileObj.readAsStringSync();
if (!templateContent.contains('REPLACE_ME')) {
print('Error: REPLACE_ME not found in $templateFile');
exit(1);
}
final newContent = templateContent.replaceFirst('REPLACE_ME', payload);
final outputFileObj = File(outputFile);
outputFileObj.writeAsStringSync(newContent);
print('Written to $outputFile');
}
void main() {
final distDir = Directory('dist');
if (!distDir.existsSync()) {
distDir.createSync();
}
// Bash
hydrate(
'core_logic.sh',
'setup_flutter.template.sh',
'dist/setup_flutter.sh',
);
// PowerShell
hydrate(
'core_logic.ps1',
'setup_flutter.template.ps1',
'dist/setup_flutter.ps1',
);
}