forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 6
/
version.js
executable file
·67 lines (58 loc) · 1.86 KB
/
version.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
#!/usr/bin/env node
var FILE = 'version.yaml';
var fs = require('fs');
var optimist = require('optimist');
optimist
.usage('Manage ' + FILE + '.\nUsage: $0 [options]')
.describe('remove-snapshot', 'Remove -snapshot suffix.')
.describe('minor-bump', 'Bump minor version one step.')
.describe('minor-next', 'Return next minor version.')
.describe('current', 'Return current verion')
.describe('help', 'Show usage');
var bumpMinor = function(version) {
var parts = version.split('.');
var last = parts.pop();
var rc = last.match(/(\d*)rc(\d*)/);
if (rc) {
parts.push(rc[1] + 'rc' + (parseInt(rc[2], 10) + 1));
} else {
parts.push('' + (parseInt(last, 10) + 1));
}
return parts.join('.');
};
fs.readFile(FILE, 'utf8', function(err, content) {
var version = content.match(/version\:\s([^\-\n]*)/)[1];
var args = optimist.argv;
if (args['remove-snapshot']) {
fs.writeFile(FILE, content.replace('-snapshot', ''), function(err) {
if (!err) {
console.log('Version updated (removed -snapshot).');
process.exit(0);
} else {
console.error('Version update failed.');
process.exit(1);
}
});
} else if (args['minor-next']) {
process.stdout.write(bumpMinor(version) + '\n');
process.exit(0);
} else if (args['current']) {
process.stdout.write(version + '\n');
process.exit(0);
} else if (args['minor-bump']) {
var bumped = bumpMinor(version);
if (!content.match(/\-snapshot/)) bumped += '-snapshot';
fs.writeFile(FILE, content.replace(version, bumped), function(err) {
if (!err) {
console.log('Version updated (bumped to ' + bumped + ').');
process.exit(0);
} else {
console.error('Version update failed.');
process.exit(1);
}
});
} else {
console.log(optimist.help());
process.exit(args['help'] ? 0 : 1);
}
});