forked from neutralinojs/neutralinojs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
version-bump.js
120 lines (101 loc) · 3.18 KB
/
version-bump.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const { promisify } = require("util");
const { exec } = require("child_process");
const execPromise = promisify(exec);
const fs = require("fs");
const BUMP_TYPES = {
Major: "major",
Minor: "minor",
Patch: "patch"
};
(async () => {
if (process.argv.length < 3) {
console.error("ERROR: Please enter a [major/minor/patch] version bump.");
process.exit(1);
}
const bump = process.argv[2].toLowerCase();
if (
bump !== BUMP_TYPES.Major &&
bump !== BUMP_TYPES.Minor &&
bump !== BUMP_TYPES.Patch
) {
console.error("ERROR: Please enter a [major/minor/patch] version bump.");
process.exit(1);
}
// use native npm version CLI command for npm version bump
const { stdout } = await execPromise(`npm version ${bump}`, {
cwd: "./neutralino.js"
});
const newVersion = stdout.slice(1).trim();
// manually bump version number for CPP files
const cppFilePaths = [
"./core-linux/src/settings.cpp",
"./core-macos/src/settings.cpp",
"./core-windows/src/settings.cpp",
"./core-windows/bin/version_info"
];
cppFilePaths.forEach(filePath => {
let contents = fs.readFileSync(filePath, { encoding: "utf-8" });
if (filePath.includes("settings.cpp")) {
const oldVersion = contents.match(
/NL_VERSION='([0-9+]+\.[0-9+]+\.[0-9]+)'/
)[1];
const newV = bumpVersion(oldVersion, bump);
if (newV !== newVersion) {
console.error(
`Package versions in files do not match (${newV} and ${newVersion})`
);
process.exit(1);
}
contents = contents.replace(
`NL_VERSION='${oldVersion}'`,
`NL_VERSION='${newVersion}'`
);
} else {
const oldFileVersion = contents.match(
/"FileVersion", "([0-9+]+\.[0-9+]+\.[0-9]+)"/
)[1];
const oldProductVersion = contents.match(
/"ProductVersion", "([0-9+]+\.[0-9+]+\.[0-9]+)"/
)[1];
const newFileVersion = bumpVersion(oldFileVersion, bump);
const newProductVersion = bumpVersion(oldProductVersion, bump);
if (newFileVersion !== newVersion || newProductVersion !== newVersion) {
console.error(
`Package versions in files do not match (${newFileVersion}/${newProductVersion} and ${newVersion})`
);
process.exit(1);
}
contents = contents
.replace(
`"FileVersion", "${oldFileVersion}"`,
`"FileVersion", "${newVersion}"`
)
.replace(
`"ProductVersion", "${oldProductVersion}"`,
`"ProductVersion", "${newVersion}"`
);
}
fs.writeFileSync(filePath, contents);
});
// commit and tag
await execPromise(
`git add --all && git commit -m "chore: Bump packages to v${newVersion}" && git tag v${newVersion}`
);
})();
function bumpVersion(oldVersion, bumpType) {
if (typeof oldVersion !== "string" || typeof bumpType !== "string") {
return;
}
let [majorV, minorV, patchV] = oldVersion.split(".");
if (bumpType === BUMP_TYPES.Major) {
majorV++;
minorV = 0;
patchV = 0;
} else if (bumpType === BUMP_TYPES.Minor) {
minorV++;
patchV = 0;
} else if (bumpType === BUMP_TYPES.Patch) {
patchV++;
}
return `${majorV}.${minorV}.${patchV}`;
}