forked from GitJournal/GitJournal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_env.dart
executable file
·44 lines (35 loc) · 1015 Bytes
/
setup_env.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
43
44
#!/usr/bin/env dart
// SPDX-FileCopyrightText: 2019-2021 Vishesh Handa <[email protected]>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import 'dart:convert';
import 'dart:io';
Future<int> main(List<String> args) async {
var config = <String, String?>{};
try {
var contents = await File('secrets/env.json').readAsString();
config = (json.decode(contents) as Map).map(
(key, value) => MapEntry(key, value.toString()),
);
} catch (ex) {
stderr.writeln(ex);
}
if (args.isNotEmpty) {
config = config.map((key, value) => MapEntry(key, null));
}
stderr.writeln(config);
stderr.writeln('');
var contents = 'class Env {\n';
config.forEach((key, value) {
if (value == null) {
contents += ' static final String $key = "";\n';
} else {
contents += ' static final String $key = "$value";\n';
}
});
contents += '}\n';
stderr.writeln(contents);
const filename = 'lib/.env.dart';
await File(filename).writeAsString(contents);
return 0;
}