-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrelease.js
62 lines (55 loc) · 1.52 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
const inquirer = require('inquirer')
const semver = require('semver')
const shell = require('shelljs')
const pkg = require('./package.json')
console.log('');
console.log('Welcome to servable release utility!');
console.log('----------------------------------------------------------------');
console.log('');
const questions = [
{
type: 'list',
name: 'version',
message: 'Which version will it be? (current is ' + pkg.version + ')',
choices: [
semver.inc(pkg.version, 'patch'),
semver.inc(pkg.version, 'minor'),
semver.inc(pkg.version, 'major'),
semver.inc(pkg.version, 'premajor', 'rc'),
],
},
{
type: 'list',
name: 'dryRun',
message: 'Do you want to release, or just see what would happen if you do?',
choices: ['Just see', 'Release!'],
},
];
inquirer.prompt(questions).then(function(answers) {
const newVerison = answers.version
const dryRun = answers.dryRun === 'Just see';
pkg.version = newVerison;
console.log('');
if (dryRun) {
console.log('Ok, here is what would happen:');
} else {
console.log('Doing actual release:');
}
console.log('');
run(`npm version ${newVerison}`, dryRun) &&
run('yarn build', dryRun) &&
run('git push origin --tags', dryRun) &&
run('npm publish', dryRun);
});
function run(cmd, dry) {
console.log('Running `' + cmd + '`');
if (!dry) {
if (shell.exec(cmd, {silent: false}).code === 0) {
console.log('... ok');
} else {
console.error('... fail!');
return false;
}
}
return true;
}