-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathversion-update.js
45 lines (35 loc) · 1.12 KB
/
version-update.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
// Semantic Versioning Tool
// ========================
//
// See: http://semver.org/
// For projects with package.json in the target folder.
//
// * Author: George Pantazis
//
// * Usage:
// * Major (0.x.x -> 1.0.0) : `node version-update major`
// * Minor (x.0.x -> x.1.0) : `node version-update minor`
// * Patch (x.x.0 -> x.x.1) : `node version-update patch`
// * Custom (x.x.x -> 1.2.3) : `node version-update custom 1.2.3`
var exec = require('child_process').exec,
json = require('./package.json'),
newVersion, splitVersion;
if (process.argv[2] === 'custom') {
newVersion = process.argv[3];
} else {
splitVersion = json.version.split('.');
if (process.argv[2] === 'major') {
splitVersion[0] = splitVersion[0] * 1 + 1;
splitVersion[1] = 0;
splitVersion[2] = 0;
}
if (process.argv[2] === 'minor') {
splitVersion[1] = splitVersion[1] * 1 + 1;
splitVersion[2] = 0;
}
if (process.argv[2] === 'patch') {
splitVersion[2] = splitVersion[2] * 1 + 1;
}
newVersion = splitVersion.join('.');
}
exec('find ./* -type f | xargs perl -pi -e \'s/' + json.version + '/' + newVersion + '/g\'');