-
Notifications
You must be signed in to change notification settings - Fork 4
/
rocket.js
executable file
·160 lines (135 loc) · 4.7 KB
/
rocket.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
#!/usr/bin/env node
(function () {
var fs = require('fs')
, nopt = require('nopt')
, colors = require('colors')
, path = require('path')
;
/******************************************************************************
* PRINT USAGE
*/
function printUsage() {
var generators = fs.readdirSync(path.join(__dirname, '..', 'lib', 'generator'))
, generators_list = ''
;
for(var i = 0, len = generators.length; i < len; i++) {
if(generators[i].substr(0,1) !== '_') {
generators_list += generators[i].split('_')[0] + ' ';
}
}
console.log(
[
''
, 'Usage: rocket [command] [argument(s)]'
, ''
, 'Options:'
, ' -v, --version................................Prints RocketJS\' version'
, ' -h, --help...................................Prints this message'
//, ' -p, --prod, --production.....................Set the current environment to be production mode.'
//, ' Default is development. Used in conjunction with --start'
//, ' -d, --daemon.................................Set the server to be started in daemon mode.'
, ' *** Use --kill to stop the server *** Used in conjunction with --start'
//, ' -k, --kill...................................Kill the server if it is running. Done before --start if used together.'
, ''
, 'Commands:'
//, ' -s, --start..................................Launch current RocketJS project'
, ' -I, --init [project name]....................Initialize project app'
, ' -a, --add [options].........................Add a [type] object to the current project working directory'
, ' do --info [type] for more info'
, ' -i, --info [type]............................Prints usage information about [type] object'
, ''
, 'Available object types: ' + generators_list
, ''
].join('\n')
);
};
/******************************************************************************
* PRINT VERSION
*/
function printVersion() {
console.log(
[
''
, '====----> RocketJS ' + require('rocket').version + ' | RocketJS.net | @RocketJS'
, '====----> The rapid development framework for node.js/couchDB web apps'
, ''
].join('\n')
);
}
/******************************************************************************
* KILL SERVER
*/
function killServer() {
}
/******************************************************************************
* START SERVER
*/
function startServer() {
}
/******************************************************************************
* MAIN
*/
var knownOpts = {
'version' : Boolean
, 'help' : Boolean
, 'init' : String
, 'add' : String
, 'info' : String
, 'start' : Boolean
, 'production' : Boolean
, 'daemon' : Boolean
, 'kill' : Boolean
, 'no-view' : Boolean
}
, shortHands = {
'v' : ['--version']
, 'h' : ['--help']
, 'I' : ['--init']
, 'a' : ['--add']
, 'i' : ['--info']
, 's' : ['--start']
, 'p' : ['--production']
, 'd' : ['--daemon']
, 'k' : ['--kill']
}
, parsed = nopt(knownOpts, shortHands)
;
if(parsed.argv.original.length === 0 || parsed.help) {
printUsage();
return;
}else if(parsed.version) {
printVersion();
return;
}else{
if(parsed.kill) {
killServer();
}
if(parsed.init) {
require('../lib/generator/_project_generator')(parsed.init);
}else if(parsed.info) {
generator = require('../lib/generator/' + parsed.info + '_generator/').info();
}else if(parsed.add) {
var generator
, args
, idx
, i
, cooked = parsed.argv.cooked
;
try {
generator = require('../lib/generator/' + parsed.add + '_generator');
}catch(err){
console.log(('xxx ERROR : [' + parsed.add + '] wrong element type.').red);
}
for(
idx = i = cooked.indexOf('--add') + 1;
i < cooked.length && cooked[i].substr(0,2) !== '--' ;
i++
);
args = cooked.slice(idx + 1, i);
args.push((typeof parsed.view === 'undefined' ? true : parsed.view));
generator.apply(generator, args);
}else if(parsed.start) {
startServer({daemon: parsed.daemon, production: parsed.production});
}
}
})();