-
Notifications
You must be signed in to change notification settings - Fork 14
/
release.js
108 lines (92 loc) · 3.01 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const execa = require('execa');
const nvexeca = require('nvexeca');
const semver = require('semver');
const inquirer = require('inquirer');
const curVersion = require('./package.json').version;
const execWrapper = async (...args) => {
let _promise = execa(...args);
_promise.stdout.pipe(process.stdout);
return await _promise;
};
const execWithTargetNode = async (...args) => {
let _promise = await nvexeca(...args);
_promise = _promise.childProcess;
_promise.stdout.pipe(process.stdout);
return await _promise;
};
const release = async () => {
console.log(`Current version: ${ curVersion }`);
const bumps = ['prerelease', 'prepatch', 'preminor', 'premajor', 'patch', 'minor', 'major' ];
const versions = {};
bumps.forEach(b => {
versions[b] = semver.inc(curVersion, b);
});
const bumpChoices = bumps.map(b => {
return { name: `${ b } (${ versions[b] })`, value: b };
});
const { bump, customVersion, isPublish, buildTarget } = await inquirer.prompt([
{
name: 'bump',
message: 'Select release type:',
type: 'list',
choices: [
...bumpChoices,
{ name: 'custom', value: 'custom' }
]
},
{
name: 'customVersion',
message: 'Input version:',
type: 'input',
when: answers => answers.bump === 'custom'
},
{
name: 'isPublish',
message: 'Do you want to publish to github?',
type: 'list',
choices: [ { name: 'N', value: false }, { name: 'Y', value: true } ]
},
{
name: 'buildTarget',
message: 'Which target do you want to build?',
type: 'list',
choices: ['all', 'mac', 'win']
}
]);
const version = customVersion || versions[bump];
const { yes } = await inquirer.prompt([{
name: 'yes',
message: `Confirm releasing ${ version }?`,
type: 'list',
choices: [ 'N', 'Y' ]
}]);
if (yes === 'N') {
console.log('[release] cancelled.');
return;
}
console.log(`npm version ${bumps.indexOf(bump) > -1 ? bump : version }`);
// Delete files
await execWrapper('npm', ['run', 'clean']);
await execWithTargetNode('v10', 'npm', ['run', 'build:web']);
const releaseConfig = {
env: {
...process.env,
RELEASE: isPublish
}
};
if (isPublish) {
await execWrapper('npm', ['version', bumps.indexOf(bump) > -1 ? bump : version]);
await execWrapper('git', ['push']);
await execWrapper('git', ['push', '--tags', '-f']);
}
if (['all', 'mac'].indexOf(buildTarget) > -1) {
await execWrapper('npm', ['run', 'release:mac'], releaseConfig);
}
if (['all', 'win'].indexOf(buildTarget) > -1) {
await execWrapper('npm', ['run', 'release:win'], releaseConfig);
}
};
release().catch(err => {
console.error(err);
process.exit(1);
});