-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.js
85 lines (65 loc) · 1.94 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
const fs = require('fs');
const path = require('path');
const execSync = require('child_process').execSync;
const archiver = require('archiver');
const packageJSON = getJSON('package.json');
const manifestJSON = getJSON('manifest.json');
bumpRelease();
buildZipFile();
gitCommitAndTag();
function getJSON(fileName) {
const data = fs.readFileSync(path.join(__dirname, fileName), 'utf8');
return JSON.parse(data.slice().toString());
}
function bumpRelease() {
const version = packageJSON.version.split('.');
const releaseType = process.argv[2];
if (!releaseType) {
++version[2];
} else if (releaseType === 'minor') {
++version[1];
version[2] = 0;
} else {
++version[0];
version[1] = version[2] = 0;
}
global.versionStr = version.join('.');
packageJSON.version = manifestJSON.version = versionStr;
fs.writeFileSync(path.join(__dirname, 'package.json'), JSON.stringify(packageJSON, null, ' '));
fs.writeFileSync(path.join(__dirname, 'manifest.json'), JSON.stringify(manifestJSON, null, ' '));
}
function buildZipFile() {
npmBuild('production');
createDistDir();
createZipFile();
function npmBuild(env) {
process.env.NODE_ENV = env;
execSync(`NODE_ENV=${env} npm run build`);
}
function createDistDir() {
var dir = path.join(__dirname, 'dist');
try {
fs.accessSync(dir);
} catch (e) {
fs.mkdirSync(dir);
}
}
function createZipFile() {
const output = fs.createWriteStream('dist/httpolice-devtool-' + versionStr + '.zip');
const archive = archiver('zip');
archive.pipe(output);
archive.bulk([
{ expand: true, cwd: 'builds', src: ['**']}
]);
archive.finalize();
output.on('close', () => {
// rebuild /builds extension with sourcemap enabled
npmBuild('');
});
}
}
function gitCommitAndTag() {
execSync('git add manifest.json package.json');
execSync('git commit -m ' + versionStr);
execSync('git tag ' + versionStr);
}