forked from royjafari/SOED
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincreaseVersion.ts
executable file
·64 lines (54 loc) · 1.57 KB
/
increaseVersion.ts
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
#!/usr/bin/env bun
const fs = require("fs");
const path = require("path");
function incrementVersion(version) {
let [major, minor, patch] = version.split(".").map(Number);
patch += 1;
if (patch >= 999) {
patch = 0;
minor += 1;
if (minor >= 999) {
minor = 0;
major += 1;
}
}
return `${major}.${minor}.${patch}`;
}
function updateSetupPy(newVersion) {
const setupPyPath = path.join(__dirname, "setup.py");
let setupPyContent = fs.readFileSync(setupPyPath, "utf8");
setupPyContent = setupPyContent.replace(
/version=['"](\d+\.\d+\.\d+)['"]/,
`version='${newVersion}'`
);
fs.writeFileSync(setupPyPath, setupPyContent, "utf8");
}
function updatePackageJson(newVersion) {
const packageJsonPath = path.join(__dirname, "package.json");
const packageJsonContent = JSON.parse(
fs.readFileSync(packageJsonPath, "utf8")
);
packageJsonContent.version = newVersion;
fs.writeFileSync(
packageJsonPath,
JSON.stringify(packageJsonContent, null, 2),
"utf8"
);
}
function main() {
const setupPyPath = path.join(__dirname, "setup.py");
const setupPyContent = fs.readFileSync(setupPyPath, "utf8");
const currentVersionMatch = setupPyContent.match(
/version=['"](\d+\.\d+\.\d+)['"]/
);
if (!currentVersionMatch) {
console.error("Failed to find version in setup.py");
process.exit(1);
}
const currentVersion = currentVersionMatch[1];
const newVersion = incrementVersion(currentVersion);
updateSetupPy(newVersion);
updatePackageJson(newVersion);
console.log(`Version updated to ${newVersion}`);
}
main();