-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpatch.js
More file actions
executable file
·30 lines (22 loc) · 969 Bytes
/
Copy pathpatch.js
File metadata and controls
executable file
·30 lines (22 loc) · 969 Bytes
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
#!/usr/bin/env node
(function(global) {
var fs = require("fs");
patch(process.cwd() + "/" + "package.json");
function patch(file) {
var packagejson1 = fs.readFileSync(file, "UTF-8");
var packagejson2 = packagejson1.replace(/"version":(\s+)"(\d+)\.(\d+)\.(\d+)"/, function(_, space, major, minor, patch) {
return '"version":' + space + '"' + major + "." + minor + "." + (parseInt(patch, 10) + 1) + '"';
});
var json1 = JSON.parse(packagejson1);
var json2 = JSON.parse(packagejson2);
var version1 = parseInt(json1.version.split(".")[2] || 0, 10);
var version2 = parseInt(json2.version.split(".")[2] || 0, 10);
if (version1 + 1 === version2) {
console.log("update patch version. " + json1.version + " -> " + json2.version);
fs.writeFileSync(file, packagejson2);
//console.log( fs.readFileSync(file, "UTF-8") );
} else {
console.error("format error.");
}
}
})(GLOBAL);