-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.js
executable file
·92 lines (81 loc) · 1.95 KB
/
release.js
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
#!/usr/bin/env node
const { execSync } = require("child_process");
const path = require("path");
const util = require("util");
const fs = require("fs");
const readline = require("readline").createInterface({
input: process.stdin,
output: process.stdout
});
/**
* Prepare a major, minor or patch release.
*/
const types = ["major", "minor", "patch"];
const type = process.argv[2];
const typeIndex = types.indexOf(type);
if (process.argv.length != 3 || !types.includes(type)) {
console.error(
`Usage: ./${path.basename(process.argv[1])} [major|minor|patch]`
);
process.exit(1);
}
process.argv;
// Get latest git version tag
const tags = execSync("git tag -l")
.toString()
.trim()
.split("\n")
.map(tag => tag
.replace("v", "")
.trim()
.split(".")
.map(p => parseInt(p))
)
.sort((a, b) => {
for (let i = 0; i < 3; i++) {
if (a[i] != b[i]) return b[i] - a[i];
}
return 0;
})
;
if (!tags.length) {
throw "Could not load git tag names";
}
const tagParts = tags[0];
const tag = `v${tagParts.join('.')}`;
console.log(`Last version: ${tag}`);
// Create new version
const newVersionParts = tagParts.slice().map((value, i) => {
if (i == typeIndex) value++;
if (i > typeIndex) value = 0;
return value;
});
const newTag = `v${newVersionParts.join(".")}`;
console.log(`New version tag: ${newTag}`);
execSync(`git add -A`);
confirm(`This will:
* git tag
* git push
Please check that git staging area is empty before continueing
Type y to confirm: `).then(() => {
execSync(`git tag ${newTag}`);
execSync(`git push`);
execSync(`git push --tags`);
});
function confirm(question) {
return new Promise(resolve => {
readline.question(question, answer => {
readline.close();
resolve(answer);
});
});
}
function replaceInFile(filename, searchValue, replaceValue) {
return fs.writeFileSync(
filename,
fs
.readFileSync(filename)
.toString()
.replace(searchValue, replaceValue)
);
}