forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
increment-version.js
69 lines (53 loc) · 1.96 KB
/
increment-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
68
69
var fs = require('fs');
var path = require('path');
var semver = require('semver');
var optimist = require('optimist');
var updater = require('../app/lib/updater.js');
var _ = require('../app/lib/third/underscore.js');
// What files to update. Relative to project root.
var UPDATE_FILES = ['app/lib/updater.js',
'admin/install-s3.sh',
'admin/debian/changelog',
'admin/meteor.spec',
'docs/client/docs.js',
'docs/client/docs.html',
['admin/manifest.json', 'g']];
// Files to update for dev_bundle
var BUNDLE_FILES = ['admin/generate-dev-bundle.sh', 'meteor'];
var opt = require('optimist')
.alias('dev_bundle', 'd')
.boolean('dev_bundle')
.describe('dev_bundle', 'Update the dev_bundle version, not the main version.')
.alias('new_version', 'n')
.describe('new_version', 'A new version number. Default is to increment patch number.')
.usage('Usage: $0 [options]')
;
var argv = opt.argv;
if (argv.help) {
process.stdout.write(opt.help());
process.exit(1);
}
var CURRENT_VERSION = updater.CURRENT_VERSION;
var files = UPDATE_FILES;
if (argv.dev_bundle) {
var version_path = path.join(__dirname, '..', 'meteor');
var version_data = fs.readFileSync(version_path, 'utf8');
var version_match = /BUNDLE_VERSION=([\d\.]+)/.exec(version_data);
CURRENT_VERSION = version_match[1];
files = BUNDLE_FILES;
}
var NEW_VERSION = argv.new_version || semver.inc(CURRENT_VERSION, 'patch');
console.log("Updating from " + CURRENT_VERSION + " to " + NEW_VERSION);
_.each(files, function (file) {
var flags = '';
if (file instanceof Array) {
flags = file[1];
file = file[0];
}
var fp = path.join(__dirname, '..', file);
var text = fs.readFileSync(fp, 'utf8');
var new_text = text.replace(new RegExp(CURRENT_VERSION, flags), NEW_VERSION);
fs.writeFileSync(fp, new_text, 'utf8');
console.log("updated file: " + fp);
});
console.log("Complete");