-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathkeys-n-stuff.dart
115 lines (94 loc) · 3.59 KB
/
keys-n-stuff.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import 'dart:io';
import 'dart:convert';
Future<void> copyFile(String source, String destination) async {
try {
final sourceFile = File(source);
final destinationFile = File(destination);
if (await destinationFile.exists()) {
print('Overwriting existing file: $destination');
await destinationFile.delete();
}
await sourceFile.copy(destination);
print('Successfully copied: $destination');
} catch (e) {
throw 'Failed to copy $source to $destination: $e';
}
}
Future<void> main() async {
try {
// Check if .keys-n-stuff directory exists
final keysDir = Directory('.keys-n-stuff');
// Read the keys-n-stuff.json file
final configFile = File('.keys-n-stuff.json');
if (!await configFile.exists()) {
throw 'Configuration file not found';
}
final config = jsonDecode(await configFile.readAsString());
final String projectDir = config['dir'];
final String projectType = config['type'];
final String repo = config['repo'];
final source = ".keys-n-stuff/$projectDir";
print('Project directory: $projectDir');
print('Project type: $projectType');
print('Repository: $repo');
if (await keysDir.exists()) {
print('Repository already exists, pulling latest changes...');
final pullResult =
await Process.run('git', ['pull'], workingDirectory: '.keys-n-stuff');
if (pullResult.exitCode != 0) {
throw 'Failed to pull repository: ${pullResult.stderr}';
}
print('Successfully pulled latest changes');
} else {
print('Cloning repository...');
final cloneResult =
await Process.run('git', ['clone', repo, '.keys-n-stuff']);
if (cloneResult.exitCode != 0) {
throw 'Failed to clone repository: ${cloneResult.stderr}';
}
print('Successfully cloned repository');
}
if (projectType == 'flutter') {
// Create necessary directories
await Directory('android/app').create(recursive: true);
await Directory('ios/Runner').create(recursive: true);
await Directory('macos/Runner').create(recursive: true);
// Copy Firebase config files
// Android
await copyFile(
'$source/google-services.json', 'android/app/google-services.json');
// iOS
await copyFile('$source/GoogleService-Info.plist',
'ios/Runner/GoogleService-Info.plist');
// macOS
await copyFile('$source/GoogleService-Info.plist',
'macos/Runner/GoogleService-Info.plist');
// Copy keystore properties file to android root
await copyFile('$source/prod.properties', 'android/prod.properties');
// Copy keystore file to android/app
final prodKeystoreFile = File('$source/prod.jks');
if (await prodKeystoreFile.exists()) {
await copyFile('$source/prod.jks', 'android/app/prod.jks');
}
await copyFile('$source/dev.properties', 'android/dev.properties');
// Copy keystore file to android/app
final devKeystoreFile = File('$source/dev.jks');
if (await devKeystoreFile.exists()) {
await copyFile('$source/dev.jks', 'android/app/dev.jks');
}
final serviceAccountFile = File('$source/service-account.json');
if (await serviceAccountFile.exists()) {
await copyFile('$source/service-account.json', 'service-account.json');
}
print(
'Successfully copied all configuration files to their respective directories',
);
} else {
throw 'Unsupported project type: $projectType';
}
print('Setup completed successfully');
} catch (e) {
print('Error: $e');
exit(1);
}
}