forked from bcode-tech/ethereum-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversioning.js
57 lines (50 loc) · 1.68 KB
/
versioning.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
const { exec } = require("child_process");
const { readFile, writeFileSync } = require("fs");
const argv = require("minimist")(process.argv.slice(2));
const { join } = require("path");
const pkg = require(join(process.cwd(), "package.json"));
const VERSIONING_FILE = argv.constantPath || "constant.js";
const VERSION = pkg.version;
const VERSION_PATTERN_REGEX = /\[?(\d+\.\d+\.\d+)/m;
/**
* Update version in constant file
*
* @param {string} input Input to be changed
* @return {string} Updated input
*/
function updateVersionFile(input) {
if (!VERSION_PATTERN_REGEX.test(input)) {
process.exit(1);
}
const previousVersion = input.match(VERSION_PATTERN_REGEX)[1];
return input.replace(previousVersion, VERSION);
}
function run() {
readFile(
VERSIONING_FILE,
{ encoding: "utf-8" },
(error, constantContent) => {
if (error) {
console.log("[FS ERROR]", error);
}
writeFileSync(VERSIONING_FILE, updateVersionFile(constantContent));
exec(`git add ${VERSIONING_FILE}`, (error, stdout) => {
if (error) {
console.log("[GIT ERROR]", error);
process.exit(1);
} else {
exec(
`git commit --amend -m "Updated to version ${VERSION}"`,
(error, stdout) => {
if (error) {
console.log("[GIT ERROR]", error);
}
process.exit(0);
}
);
}
});
}
);
}
run();