-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckApiVersion.js
44 lines (36 loc) · 1.02 KB
/
checkApiVersion.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
const fs = require("fs");
const readline = require("readline");
const packageJsonPath = "./package.json";
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
function updateVersion(newVersion) {
fs.readFile(packageJsonPath, "utf8", (err, data) => {
if (err) {
console.error(`Error reading ${packageJsonPath}:`, err);
process.exit(1);
}
// Parse the JSON data from package.json
const packageJson = JSON.parse(data);
// Update the version property
packageJson.version = newVersion;
fs.writeFile(
packageJsonPath,
JSON.stringify(packageJson, null, 2),
"utf8",
(writeErr) => {
if (writeErr) {
console.error(`Error writing to ${packageJsonPath}:`, writeErr);
process.exit(1);
}
console.log(`Version updated to ${newVersion} in package.json.`);
process.exit(0);
},
);
});
}
rl.question("Enter the new version number: ", (answer) => {
updateVersion(answer);
rl.close();
});