-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathyote-cli.js
More file actions
executable file
·293 lines (260 loc) · 10.7 KB
/
yote-cli.js
File metadata and controls
executable file
·293 lines (260 loc) · 10.7 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/env node
// requirements
let program = require('commander');
let fs = require('fs');
let chalk = require('chalk');
let shell = require('shelljs');
let promptly = require('promptly');
// let builder = require('./lib/yote-builder')
let config = require('./package.json');
function howl() {
console.log(chalk.bgCyan(" test howl "));
shell.exec("say 'owooooooooooooooo'");
}
// building libraries - load current version
let init = require('./lib/v_' + config['yote-version'] + '/init');
let add = require('./lib/v_' + config['yote-version'] + '/add');
let remove = require('./lib/v_' + config['yote-version'] + '/remove');
program
.version(config.version)
.usage('<command> [options]')
/**
* TODO: capture yote version from CWD and use appropriate library version - doesn't exist for versions older than v0.7
*
*/
// .option('-b, --build <buildNum>', 'Select which version of Yote to install') // old
.option('-H, --howl', '', howl)
program
.command('init <appName>')
.alias('I')
.description('Initialize a new Yote application called <appName>')
.option('-a', '--all', 'with Client, Server, and Mobile (default)')
.option('-c', '--client', 'with Client')
.option('-w', '--web', 'with web client')
.option('-s', '--server', 'with Server')
.option('-m', '--mobile', 'with Mobile')
.option('-i', '--install', 'and install packages')
.action(init)
.on('--help', () => {
console.log(' To initialize a new blank Yote app')
console.log(chalk.green(' $ yote I <appName>'))
console.log(chalk.dim(' # OR'))
console.log(chalk.green(' $ yote init <appName>'))
console.log();
console.log(' Examples:');
console.log();
console.log(' $ yote init myApp');
console.log(' $ yote I myApp');
console.log();
console.log(' Options:');
console.log(' -w,s,m: install just web, server, and/or mobile')
console.log();
console.log(' $ yote I -sm')
console.log(chalk.dim(' # installs only the server and mobile components'))
});
program
.command('add <resourceName>')
.alias('A')
.option('-n', '--nav', 'main navigation item')
.option('-t', '--tab', 'tab bar item')
.option('-a', '--admin', 'admin directory')
.description('Add a new Resource to the Yote application called <resourceName>')
// .option('-a', '--all', 'with Client, Server, and Mobile (default)')
// .option('-c', '--client', 'with Client')
// .option('-s', '--server', 'with Server')
// .option('-m', '--mobile', 'with Mobile')
.action(add)
.on('--help', () => {
console.log(' To add a new resource to the Yote app')
console.log(chalk.green(' $ yote A <resourceName>'));
console.log(chalk.dim(' # OR'))
console.log(chalk.green(' $ yote add <resourceName>'));
console.log();
console.log(' Examples:');
console.log();
console.log(' $ yote add myResource');
console.log(' $ yote A myResource');
console.log();
console.log(chalk.bgRed(' NOTE: singular, camelcase names work best, like "product" or "book'));
console.log();
console.log();
});
program
.command('remove <resourceName>')
.alias('R')
.description('Remove a Resource from the Yote application called <resourceName>')
// .option('-a', '--all', 'with Client, Server, and Mobile (default)')
// .option('-c', '--client', 'with Client')
// .option('-s', '--server', 'with Server')
// .option('-m', '--mobile', 'with Mobile')
.action(remove)
.on('--help', () => {
console.log(' To remove an existing resource from the Yote app')
console.log(chalk.green(' $ yote A <resourceName>'));
console.log(chalk.dim(' # OR'))
console.log(chalk.green(' $ yote remove <resourceName>'));
console.log();
console.log(' Examples:');
console.log();
console.log(' $ yote remove myResource');
console.log(' $ yote A myResource');
console.log();
console.log(chalk.bgRed(' NOTE: singular, camelcase names work best, like "product" or "book'));
console.log();
console.log();
});
//yote remote database tools. will be removed from package in the future
require('./tools/remote')(program);
require('./tools/run')(program);
//old commands, will break
//preserving for the time being until we through the transition
/**
program
.command('create <appName>')
.alias('C')
.description('Create a new Yote applicaion directory called <appName>')
// .option('-b, --build [buildNum]', 'Select which version of Yote to install. Defaults to most recent stable.')
.action(function(cmd, options){
// creating a new yote project might need to be done by
// creating a fork through the github api in the future.
// right now all this does is setup a clean repo
// but it is up to the user to create the new upstream origin correctly.
// This method would be used to capture the github username
// promptly.prompt('What is your github username: ', function(err, value){
// console.log(value);
// -----------------------------------------------
// doing it this way sets fugitivelabs/yote-react.git as the upstream master and
// allows the user to pull from the upstream remote -- do we want this?
shell.exec("git clone https://github.com/fugitivelabs/yote-react.git " + cmd);
shell.cd(cmd);
// set the repo with a clean origin
shell.exec('git remote rename origin upstream');
// remove the upstream master to unlink yote master repo
// shell.exec('git remote rm upstream');
// ************* ALTERNATIVELY ********************
// doing it this way creates a brand new git directory that is not associated
// with the fugitivelabs/yote-react.git upstream master at all.
// shell.exec("git clone --bare https://github.com/fugitivelabs/yote-react.git " + program.create);
// shell.cd(program.create);
// shell.exec("git init");
// --------------------------------------------------
console.log('');
console.log(chalk.bgCyan(" Success! "));
console.log('');
console.log(chalk.green(" Now install your dependencies to get started"));
console.log('');
console.log(chalk.green(" $ cd " + cmd));
console.log(chalk.green(" $ [sudo] npm install"));
console.log('');
console.log('');
console.log(chalk.magenta(" To setup your github repository:"));
console.log('');
console.log(chalk.magenta(" - Create a repository on https://github.com"));
console.log(chalk.magenta(" - Copy the respository URL "));
console.log(chalk.magenta(" - $ cd " + cmd));
console.log(chalk.magenta(" - $ git remote add origin [repository URL]"));
console.log('');
console.log(chalk.magenta(" Then you're good to go."))
// process.exit(0);
}).on('--help', function() {
console.log(' Examples:');
console.log();
console.log(' $ yote create myApp');
console.log(' $ yote C myApp');
console.log();
});
program
.command('run')
.alias('start')
.description('Fire up the local server.')
.action(function(){
shell.exec('nodemon');
});
program
.command('generate <name>')
.alias('gen')
.description('Generate a new Yote resource.')
.option('-s, --scaffold', 'Generate a scaffold.')
.option('-c, --client [type]', "Generate an api agnostic client resource. Currently accepting: 'react' ('r'), 'angular' ('ng'). Default 'react'.")
.option('-a, --api', "Generate a client agnostic api resource.")
.action(function(name, options){
console.log("DEBUG");
console.log(builder);
console.log(builder.react);
if(options.client) {
if(options.client == 'ng' || options.client == 'angular') {
builder.ng(name, options);
} if(options.client == 'r' || options.client == 'react') {
builder.react(name, options);
} else {
builder.react(name, options); //default to react
// if we end up with more than one client type, we can add this back in
// console.log("");
// console.log(chalk.red('Whoops'));
// console.log(chalk.red("Can't understand your client type"));
// console.log("");
// console.log(chalk.yellow("Acceptable client types (so far):"));
// console.log("");
// console.log(chalk.yellow(" 'ng' ...... Client-side AngularJS MVC resource (can also spell out as 'angular') "));
// console.log("");
}
} else if(options.api) {
builder.api(name, options);
} else if(options.scaffold) {
builder.scaffold(name, options);
} else {
builder.scaffold(name, options);
}
}).on('--help', function() {
console.log(' Examples:');
console.log();
console.log(' $ yote gen myResource ');
console.log(chalk.dim(' - will generate an integrated Yote scaffold'));
console.log();
console.log(' $ yote gen myResource -c ');
console.log(chalk.dim(' - OR - '));
console.log(' $ yote gen myResource --client ');
console.log(chalk.dim(' - will generate a Yote client with dummy data'));
console.log();
console.log(' $ yote gen myResource -a');
console.log(chalk.dim(' - OR - '));
console.log(' $ yote gen myResource --api');
console.log(chalk.dim(' - will generate a Yote API that can be hit by any client'));
console.log();
});
program.on('--help', function() {
console.log(' Create Examples:');
console.log();
console.log(' $ yote create myApp');
console.log(chalk.dim(' - OR - '));
console.log(' $ yote C myApp');
console.log(chalk.dim(' - will create a new Yote application in the myApp directory'));
console.log();
console.log();
console.log(' Generate help:');
console.log();
console.log(' $ yote gen -h ');
console.log(chalk.dim(' - generate command helper'));
console.log();
console.log();
console.log(' Generate Examples:');
console.log();
console.log(' $ yote gen myResource ');
console.log(chalk.dim(' - will generate an integrated Yote scaffold'));
console.log();
console.log(' $ yote gen myResource -c ');
console.log(chalk.dim(' - OR - '));
console.log(' $ yote gen myResource --client ');
console.log(chalk.dim(' - will generate a Yote client with dummy data'));
console.log();
console.log(' $ yote gen myResource -a');
console.log(chalk.dim(' - OR - '));
console.log(' $ yote gen myResource --api');
console.log(chalk.dim(' - will generate a Yote API that can be hit by any client'));
console.log();
});
**/
program.parse(process.argv);
if(!program.args.length) {
program.help();
}