-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-version.js
48 lines (37 loc) · 1.22 KB
/
update-version.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
const fs = require('fs');
const path = require('path');
const version = process.argv[2]?.trim();
const swConfig = require(path.resolve(__dirname, 'ngsw-config.json'));
const packageJson = require(path.resolve(__dirname, 'package.json'));
const packageLockJson = require(path.resolve(__dirname, 'package-lock.json'));
const child = require('child_process');
if ( ! version ) throw new Error('No version specified!');
function spawn(command, ...args) {
return new Promise((resolve, reject) => {
child.spawn(command, args, {
windowsHide: true,
cwd: process.cwd(),
stdio: 'inherit'
})
.on('close', resolve)
.on('error', reject);
});
}
swConfig.appData = { version };
packageJson.version = version;
packageLockJson.version = version;
fs.writeFileSync(
path.resolve(__dirname, 'ngsw-config.json'),
JSON.stringify(swConfig, null, 2)
);
fs.writeFileSync(
path.resolve(__dirname, 'package.json'),
JSON.stringify(packageJson, null, 2)
);
fs.writeFileSync(
path.resolve(__dirname, 'package-lock.json'),
JSON.stringify(packageLockJson, null, 2)
);
spawn('git', 'add', 'ngsw-config.json', 'package.json', 'package-lock.json')
.then(() => spawn('git', 'commit', '-m', `v${version}`))
.catch(console.error);