generated from electron-react-boilerplate/electron-react-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.js
105 lines (84 loc) · 2.27 KB
/
update.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
/* eslint-disable no-console */
const { exec } = require('child_process');
const { readFileSync, writeFileSync } = require('fs');
const path = require('path');
const PACKAGE_JSON_PATH = path.join(__dirname, 'release/app/package.json');
const PACKAGE_LOCK_JSON_PATH = path.join(
__dirname,
'release/app/package-lock.json'
);
const args = process.argv
.filter((a) => a.includes('='))
.reduce((result, current) => {
const values = current.split('=');
result[values[0]] = values[1] || '';
return result;
}, {});
exec(`git fetch && git tag`, (e1, tagsExecResult) => {
if (e1) {
console.log(`error: ${e1.message}`);
return;
}
const latestVersion = tagsExecResult
.split('\n')
.filter((a) => a.startsWith('v'))
.map((i) =>
i
.slice(1)
.split('.')
.map((j) => parseInt(j.trim(), 10))
)
.sort((a, b) => {
if (a[0] !== b[0]) {
return b[0] - a[0];
}
if (a[1] !== b[1]) {
return b[1] - a[1];
}
return b[2] - a[2];
})[0] || [0, 0, 0];
const op = args.type?.toLowerCase() || 'major';
switch (op) {
case 'major':
latestVersion[0] += 1;
latestVersion[1] = 0;
latestVersion[2] = 0;
break;
case 'minor':
latestVersion[1] += 1;
latestVersion[2] = 0;
break;
case 'patch':
latestVersion[2] += 1;
break;
default:
break;
}
const newVersion = latestVersion.join('.');
const packageJson = JSON.parse(readFileSync(PACKAGE_JSON_PATH));
const packageLockJson = JSON.parse(readFileSync(PACKAGE_LOCK_JSON_PATH));
packageJson.version = newVersion;
packageLockJson.version = newVersion;
packageLockJson.packages[''].version = newVersion;
writeFileSync(PACKAGE_JSON_PATH, JSON.stringify(packageJson, null, 2));
writeFileSync(
PACKAGE_LOCK_JSON_PATH,
JSON.stringify(packageLockJson, null, 2)
);
exec(
`git fetch && git add --all && git commit -m "Before Release v${newVersion}" && git tag v${newVersion} && git push --tags`,
(e2, stdout, stderr) => {
if (e2) {
console.log(`error: ${e2.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
}
);
});
/*
*/