-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateVersion.js
45 lines (39 loc) · 1.25 KB
/
updateVersion.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
const {
promises: { writeFile }
} = require("fs");
// eslint-disable-next-line import/no-extraneous-dependencies
const { zip } = require("zip-a-folder");
function save(fileName, obj, newVersion) {
obj.version = newVersion;
return writeFile(`${__dirname}/${fileName}`, JSON.stringify(obj, 0, 2));
}
(async () => {
const semanticVersion = { major: 0, minor: 1, patch: 2 };
const packageJSON = require("./package.json");
let currentVersion = packageJSON.version.split(".").map(element => +element);
const update = semanticVersion[process.argv[3]];
switch (update) {
case 0: {
currentVersion = [++currentVersion[update], 0, 0];
break;
}
case 1: {
currentVersion = [currentVersion[0], ++currentVersion[update], 0];
break;
}
case 2: {
++currentVersion[update];
break;
}
default: {
return console.log(`v-${currentVersion.join(".")}`);
}
}
const newVersion = currentVersion.join(".");
await Promise.all([
save("package.json", packageJSON, newVersion),
save("public/manifest.json", require("./public/manifest.json"), newVersion),
save("build/manifest.json", require("./build/manifest.json"), newVersion)
]);
await zip(`${__dirname}/build`, `${__dirname}/build.zip`);
})();