forked from nbcnews/jetpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.js
117 lines (98 loc) · 2.69 KB
/
cmd.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
const globals = require('./lib/helpers/globals');
const info = require('./lib/helpers/info');
const bundler = require('./cmd/bundle');
const create = require('./cmd/create');
const deploy = require('./cmd/deploy');
const releaser = require('./cmd/release');
const master = require('./cmd/master');
const rollback = require('./cmd/rollback');
const log = require('./cmd/log');
const git = require('./lib/helpers/git-rev');
var args = (JSON.parse(process.env.npm_config_argv)).remain;
var cmd = args[0];
globals.setSite(args[1]);
if (args[2]) {
globals.setTag(args[2]);
}
if (!globals.site()) {
info.error('No site specified');
showHelp();
}
function showHelp () {
info.log(cmd + ' command not found. Try updating jetpack.');
info.log('Usage for');
info.label('npm run jetpack');
info.log('create [site]: create a new s3 location');
info.log('bundle [site]: build a site bundle');
info.log('bundle:dev [site]: build an unminified site bundle with verboses output');
info.log('build-master [site]');
info.log('deploy [site]: move a local site bundle to S3');
info.log('release [site]: put a bundle on S3 into production');
info.log('rollback [site] [version]: do a release with a previous version');
info.log('log [site]: look at the release logs');
}
function runWithVersionTag (action) {
if (globals.tag()) { //explicitly set tag
action();
return;
}
info.log('No tag/version name provided.');
git.branch(function (bstr) {
info.log('Using git branch name: ' + bstr);
if (bstr === 'master') {
info.log('Master branch will use the current local tag:');
git.tag(function (mtag) {
globals.setTag(mtag);
info.log(mtag);
action();
});
} else if (cmd === 'release') {
info.error('You must be on the master branch to do a release.');
} else {
globals.setTag(bstr);
action();
}
});
}
switch (cmd) {
case 'bundle:dev':
case 'build:dev':
globals.setDevMode(true);
runWithVersionTag(bundler);
break;
case 'bundle':
case 'build':
runWithVersionTag(bundler);
break;
case 'build-master':
master.buildMasterBundle();
break;
case 'log':
log();
break;
case 'create':
create();
break;
case 'deploy':
runWithVersionTag(deploy);
break;
case 'release':
runWithVersionTag(releaser.verifyAndPush);
break;
case 'rollback':
rollback();
break;
default:
showHelp();
break;
}
/**
We could also do this
compiler.watch({ // watch options:
aggregateTimeout: 300, // wait so long for more changes
poll: true // use polling instead of native watchers
// pass a number to set the polling interval
}, function(err, stats) {
// ...
});
*/