generated from nativeshell/app_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_deps.dart
executable file
·121 lines (106 loc) · 2.58 KB
/
sync_deps.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
116
117
118
119
120
121
#!/usr/bin/env dart
import 'dart:io';
/// Utility to manage git dependencies.
///
/// Usage:
/// sync_deps.dart [clone|pull|<custom action>]
///
/// Example:
/// sync_deps.dart # initialize
/// sync_deps.dart clone # clone only.
/// sync_deps.dart pull # run git pull
/// sync_deps.dart pub # run certain custom action (pub get in this example).
final deps = [
Dependency(
path: 'deps/xterm',
repo: '[email protected]:TerminalStudio/xterm.dart.git',
actions: {
'checkout': 'git checkout master',
'pub': 'flutter pub get',
},
),
Dependency(
path: 'deps/tabs',
repo: '[email protected]:TerminalStudio/tabs.git',
actions: {
'checkout': 'git checkout stable',
'pub': 'flutter pub get',
},
),
];
// ---------------------------------------- //
void main(List<String> args) async {
if (args.isEmpty) {
return doAll();
}
final command = args[0];
switch (command) {
case 'clone':
return clone();
case 'pull':
return pull();
default:
return customAction(command);
}
}
class Dependency {
Dependency({
required this.path,
required this.repo,
this.actions = const {},
});
final String path;
final String repo;
final Map<String, String> actions;
}
Future<void> doAll() async {
await clone();
await customAction();
}
Future<void> run(
String executable,
List<String> arguments, {
String? workingDirectory,
}) async {
if (workingDirectory != null) {
print('[sync_deps] cd $workingDirectory');
}
print('[sync_deps] $executable ${arguments.join(' ')}');
final process = await Process.start(
executable,
arguments,
runInShell: true,
mode: ProcessStartMode.inheritStdio,
workingDirectory: workingDirectory,
);
final exitCode = await process.exitCode;
if (exitCode != 0) {
print('$executable returned $exitCode');
exit(exitCode);
}
}
Future<void> clone() async {
for (var dep in deps) {
if (Directory(dep.path).existsSync()) {
print('[sync_deps] ${dep.path} already exists, clone skipped.');
continue;
}
await run('git', ['clone', dep.repo, dep.path]);
}
}
Future<void> pull() async {
for (var dep in deps) {
await run('git', ['pull'], workingDirectory: dep.path);
}
}
Future<void> customAction([String? name]) async {
for (var dep in deps) {
for (var action in dep.actions.entries) {
if (name != null && action.key != name) {
continue;
}
final parts = action.value.split(' ');
await run(parts.first, parts.sublist(1), workingDirectory: dep.path);
}
}
}