forked from github/hubot-scripts
-
Notifications
You must be signed in to change notification settings - Fork 9
/
commit.js
61 lines (51 loc) · 1.52 KB
/
commit.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
var child;
var argv = require('optimist').argv;
var exec = require('child_process').exec;
var colors = require('colors');
var util = require('util');
var theChange = '[no declared change]';
var whatChanged;
var commitMessage;
var commands = require('./src/scripts/support/commitCommands');
var command;
var checkable = ['major', 'minor', 'patch'];
checkable.forEach(function (toCheck) {
if (argv[toCheck]) {
whatChanged = toCheck;
theChange = argv[toCheck];
}
});
if (!whatChanged) {
console.log('Please provide a `major`/`minor`/`patch` flag'.red);
process.exit();
}
commitMessage = util.format('[hubot-1stdibs] %s update: %s', whatChanged, theChange);
command = [
'git reset -q HEAD',
'git add --all .',
util.format('git commit -m %s', JSON.stringify(commitMessage)),
util.format('npm version %s', whatChanged),
'git reset HEAD~1',
'git commit -a --amend --no-edit',
'git pull --rebase origin master',
'git push origin master',
'npm publish .',
"ssh root@dibsy 'updateDibsy'"
].join(' && ');
child = exec(command);
child.stdout.pipe(process.stdout);
child.stderr.on('data', function (data) {
(data + '').split('\n').forEach(function (dataLine) {
dataLine = dataLine.replace(/^\s+|\s+$/, '');
if (dataLine) {
console.log(util.format('%s %s', '=='.yellow, dataLine));
}
});
});
child.on('error', function (err) {
console.log('ERROR'.red);
console.log(err);
if (err.stack) {
console.log(err.stack);
}
});