-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstimpy.js
executable file
·207 lines (131 loc) · 3.12 KB
/
stimpy.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env node
require('shelljs/global');
var cli = require('cli').enable('status'),
fs = require('fs');
_ = require('underscore-node');
var config = {
repo: 'https://github.com/semateos',
}
cli.parse({});
//run a 'script' of console commands:
var run = function(script, cli){
//if the script is a string, run it
if(typeof script === 'string'){
console.log(script);
var outcome = exec(script);
if (outcome.code !== 0) {
cli.error(outcome.output);
exit(1);
}
//otherwise if the script is an array, run each line
}else if(Array.isArray(script)){
_.each(script, function(line){
console.log(line);
var outcome = exec(line);
if (outcome.code !== 0) {
cli.error(outcome.output);
exit(1);
}
});
}
}
//create a new starter project based on a repo
cli.create = function(type, location){
if(!location){
location = 'stimpy-' + type;
}
console.log('I am creating for you now: ' + type + ' at: ' + location);
var outcome = exec('git clone ' + config.repo + '/stimpy-' + type + '.git ' + location);
this.debug(outcome);
if (outcome.code !== 0) {
this.error(outcome.output);
exit(1);
}
cd(location);
var outcome = exec('npm install');
this.debug(outcome);
if (outcome.code !== 0) {
this.error(outcome.output);
exit(1);
}
cd('..');
}
//start the local server
cli.start = function(env){
if(!env){
env = 'development';
}
if(process.platform === 'win32'){
run('set NODE_ENV=' + env + ' && npm start', this);
}else{
run('NODE_ENV=' + env + ' npm start', this);
}
}
//deploy
cli.deploy = function(type, branch){
//default branch to deploy is master
if(branch == undefined){
branch = 'master';
}
switch(type){
//deploy to heroku
case 'heroku':
var script = [
'heroku create',
'git push heroku ' + branch,
'heroku open'
];
var remotes = exec('git remote').output;
this.debug(remotes);
var has_heroku = remotes.indexOf('heroku');
this.debug(has_heroku);
//if heroku app has already been created:
if(has_heroku >= 0){
script = [
'git push heroku ' + branch,
'heroku open'
];
}
run(script, this);
break;
}
}
//emulate on mobile devices using cordova
cli.emulate = function(type){
switch(type){
//emulate the app on ios sim
case 'ios':
if(process.platform === 'win32'){
run('set NODE_ENV=cordova && gulp cordova', this);
}else{
run('NODE_ENV=cordova gulp cordova', this);
}
//run('gulp cordova', this);
cd('./cordova');
run('cordova emulate ios', this);
cd('..');
//run('NODE_ENV=development npm start', this);
break;
}
}
//cli starts here
cli.main(function(args, options) {
this.debug(args);
this.debug(options);
var operation = args[0];
console.log('Aye captain!');
switch(operation){
case 'create':
cli.create(args[1], args[2]);
break;
case 'start':
cli.start();
break;
case 'deploy':
cli.deploy(args[1], args[2]);
break;
case 'emulate':
cli.emulate(args[1]);
break;
}
});