This repository has been archived by the owner on Mar 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
68 lines (53 loc) · 1.49 KB
/
index.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
/**
* Module dependencies.
*/
var exists = require('fs').existsSync;
var resolve = require('path').resolve;
var increment = require('semver').inc;
var write = require('fs').writeFileSync;
/**
* Expose `bump`
*/
module.exports = bump;
/**
* Bump `manifests` in `root`.
*
* @param {String} root
* @param {String} version
* @param {Array} manifests
* @api public
*/
function bump(root, version, manifests){
manifests = manifests || ['package.json', 'component.json', 'bower.json'];
var files = {};
var ret = {};
var prev;
manifests.forEach(function(manifest){
var path = resolve(root, manifest);
if (!exists(path)) return;
var json = require(path);
if (!json.version) return;
var v = json.version;
var p = json.private;
if (p && !v) return;
if (!v) throw new Error('no existing version found in "' + manifest + '"');
if (prev && v != prev) throw new Error('existing version in "' + manifest + '" does not match others');
prev = v;
files[manifest] = json;
});
if (!~version.indexOf('.')) {
var file = Object.keys(files)[0];
version = increment(files[file].version, version);
if (!version) throw new Error('invalid release type specified');
}
var keys = Object.keys(files);
keys.forEach(function(key){
var path = resolve(root, key);
var json = files[key];
if (json.version) json.version = version;
write(path, JSON.stringify(json, null, 2) + '\n');
});
ret.version = version;
ret.in = keys;
return ret;
}