-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
update-version.js
31 lines (26 loc) · 929 Bytes
/
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
const fs = require('fs');
const newVersion = process.argv.pop();
if (!newVersion || !/^\d\.\d\.\d$/.test(newVersion)) {
console.error('Invalid new version. Usage: npm run newver 1.2.3');
process.exit();
}
const packageFile = './package.json';
const packageLockFile = './package-lock.json';
const manifestFile = './src/manifest.json';
const package = require(packageFile);
const packageLock = require(packageLockFile);
const manifest = require(manifestFile);
package.version = newVersion;
packageLock.version = newVersion;
packageLock.packages[''].version = newVersion;
manifest.Version = newVersion;
[
{ file: packageFile, data: package },
{ file: packageLockFile, data: packageLock },
{ file: manifestFile, data: manifest },
].forEach(({ file, data }) => {
fs.writeFile(file, JSON.stringify(data, null, 2) + "\n", (err) => {
if (err) return console.error(err);
console.log('Updated ' + file);
});
});