/
cli.js
executable file
·132 lines (123 loc) · 2.89 KB
/
cli.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env node
'use strict';
var colors = require('colors');
var program = require('commander');
var shjs = require('shelljs');
var confirm = require('confirm-simple');
var pkg = require('./package.json');
var updateNotifier = require('update-notifier');
var gbm = require('./index.js');
function getType() {
var type = (!!program.major && 'major') || (!!program.minor && 'minor') || (!!program.patch && 'patch') || 'minor';
return type;
}
function branch(cb) {
shjs.exec('git rev-parse --abbrev-ref HEAD', {
silent: true
}, function(code, out) {
if (code === 0) {
cb(out.trim());
}
});
}
updateNotifier({
pkg: pkg,
updateCheckInterval: 60 * 60 * 1000 * 24
}).notify()
program
.version(pkg.version)
.usage(colors.yellow('<commands> [options]'))
.option('-M, --major', '主版本号增加 Eg. 1.0.2 -> 2.0.0')
.option('-m, --minor', '次版本号增加 ' + 'default'.yellow + ' Eg. 1.0.2 -> 1.1.0')
.option('-p, --patch', '补丁版本号增加 Eg. 1.0.2 -> 1.0.3');
program.name = 'gbm';
program
.command('new [x.y.z|options]')
.alias('n')
.description('创建新分支')
.action(function(val) {
branch(function(name) {
gbm.new(name, val || getType());
});
});
program
.command('bump [options]')
.alias('b')
.description('增加当前版本号')
.action(function() {
gbm.bump(getType());
});
program
.command('commit <message>')
.alias('c')
.description('添加所有变更文件 and commit')
.action(function(message) {
branch(function(name) {
gbm.commit(name, message);
});
});
program
.command('switch <x.y.z>')
.alias('s')
.description('切换分支到 daily/x.y.z')
.action(function(val) {
gbm.switch(val);
});
program
.command('set <x.y.z>')
.description('设置当前版本号')
.action(function(val) {
branch(function(name) {
gbm.parser(name, val);
});
});
program
.command('get')
.description('获取当前版本号')
.action(function() {
branch(function(name) {
gbm.now(name);
});
});
program
.command('push')
.alias('prepub')
.description('推送当前分支到远端')
.action(function() {
branch(function(name) {
gbm.prepub(name);
});
});
program
.command('pull')
.description('拉取当前分支到')
.action(function() {
branch(function(name) {
gbm.pull(name);
});
});
program
.command('publish')
.description('发布当前分支资源')
.action(function() {
confirm('你确定发布当前分支吗? 此操作不可逆!', ['yes', 'no'], function(ok) {
if (ok) {
branch(function(name) {
gbm.publish(name);
});
}
});
});
program
.command('sync')
.description('同步当前版本号')
.action(function() {
branch(function(name) {
gbm.sync(name);
});
});
program.parse(process.argv);
if (program.args.length === 0) {
program.help();
process.exit();
}