forked from Friendly-Pixel/grid-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.js
executable file
·83 lines (71 loc) · 2.06 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
#!/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()
.split('\n');
if (tags.length <= 1) {
throw 'Could not load git tag names';
}
const tag = tags[tags.length - 2];
const tagParts = tag.replace('v', '').trim().split('.').map(p => parseInt(p));
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 newVersion = newVersionParts.join('.');
const newTag = 'v' + newVersionParts.join('.');
console.log(`New version tag: ${newTag}`);
execSync(`npm run build`);
replaceInFile('package.json', /"version": "[0-9.]+"/, `"version": "${newVersion}"`)
replaceInFile('bower.json', /"version": "[0-9.]+"/, `"version": "${newVersion}"`)
execSync(`git add -A`);
confirm(`This will:
* committing to git
* git tag
* git push
* npm publish
Please check git staging area
Type y to confirm:`).then(() => {
execSync(`git commit -m ${newTag}`);
execSync(`git tag ${newTag}`);
execSync(`git push`);
execSync(`git push --tags`);
execSync(`npm publish`);
});
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)
);
}