-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump.js
73 lines (68 loc) · 2.15 KB
/
bump.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
70
71
72
73
#!/usr/bin/env node
var npmPackage = require('./package.json');
var oldVersion = npmPackage.version;
var fs = require('fs');
var semver = require('semver');
var operation = process.argv[2];
var newVersion;
var exec = require('child_process').exec;
var yesno = require('yesno');
var colors = require('colors');
colors.setTheme({
error: ['white', 'bold', 'bgRed'],
warn: ['white', 'bold', 'bgBlue']
});
exec('[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]] && echo "*"', function(err, stdout){
if (stdout === "*\n"){
throwError("Git directory not clean");
}
if (semver.valid(operation)){
newVersion = semver.valid(operation);
} else {
newVersion = semver.inc(oldVersion, operation);
}
if (!newVersion){
throwError("No version operation specified");
}
npmPackage.version = newVersion;
exec('git branch | grep -i "\*" | sed -e "s/\* *//"', function(err, stdout){
if (err) throwError(err);
console.log("About to bump version number from "+oldVersion+" to " +newVersion);
var branch = stdout;
if (branch === 'master\n'){
console.log('You are on the MASTER branch. Pushing this change will PUBLISH a new version.'.warn);
}
yesno.ask('Commit and push this change to git repo? Y/n', true, function(ok){
if (ok){
var newSrc = fs.readFileSync('tevatron-build.js').toString().replace(oldVersion, newVersion);
fs.writeFileSync('tevatron-build.js', newSrc);
fs.writeFileSync('package.json', JSON.stringify(npmPackage, null, 2));
exec('git add -u && git commit -m "'+newVersion+'" && git tag v'+newVersion, function(err, stdout, stderr){
if (err) throwError(err);
if (err) throwError(stderr);
console.log(stdout);
exec('git push origin '+branch, function(err, stdout){
console.log(stdout);
exec('git push --tags', function(err, stdout){
console.log(stdout);
if (branch === 'master'){
exec('npm publish', function(){
process.exit();
});
} else {
process.exit();
}
});
});
});
} else {
console.log('not pushed');
process.exit();
}
});
});
});
function throwError(e){
console.error("ERROR:".error, e);
process.exit();
}