-
Notifications
You must be signed in to change notification settings - Fork 52
/
publish.dart
76 lines (66 loc) · 1.88 KB
/
publish.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
import 'dart:io';
void main() async {
print("-----------------------");
print(" < B U I L D >");
print("-----------------------");
final packageFolders = [
"src/appcenter",
"src/appcenter_analytics",
"src/appcenter_crashes"
];
await stepProcess(
"Formatting code",
".",
'dartfmt',
[
'-w',
]..addAll(packageFolders.map((p) => p + "/lib")));
// Updating version in pubspecs
String version;
await step("Enter the new version", () {
version = stdin.readLineSync();
});
for (var dir in packageFolders) {
var pubspec = File(dir + "/pubspec.yaml");
await step("Updating version in '${pubspec.path}'", () async {
var contents = await pubspec.readAsString();
contents = contents.replaceFirst(
RegExp('version: ([^\\n]*)'), 'version: ' + version.trim());
await pubspec.writeAsString(contents);
});
}
// Dry run
for (var dir in packageFolders) {
await stepProcess(
"Dry run for '$dir' package", dir, 'pub', ['publish', '--dry-run']);
}
bool readyForPublishing = false;
await step("Ready for publishing ? (y/N)", () {
readyForPublishing = stdin.readLineSync().toLowerCase() == "y";
});
if (readyForPublishing) {
for (var dir in packageFolders) {
await stepProcess(
"Publising '$dir' package", dir, 'pub', ['publish', '--force']);
}
}
}
Future stepProcess(
String description, String cwd, String command, List<String> args) {
return step(description, () async {
final result = await Process.run(
command,
args,
workingDirectory: cwd,
);
print("<end>");
print(result.stdout);
print(result.stderr);
});
}
Future step(String description, Future execute()) {
print("\n${_step++}. $description...");
print("----------------------------------------------------");
return execute();
}
var _step = 1;