forked from balderdashy/sails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsails.js
executable file
·220 lines (169 loc) · 4.84 KB
/
sails.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
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env node
/**
* Module dependencies
*/
var _ = require('@sailshq/lodash');
var program = require('./private/patched-commander');
var sailsPackageJson = require('../package.json');
var NOOP = function() {};
program
.version(sailsPackageJson.version, '-v, --version');
//
// Normalize version argument, i.e.
//
// $ sails -v
// $ sails -V
// $ sails --version
// $ sails version
//
// make `-v` option case-insensitive
process.argv = _.map(process.argv, function(arg) {
return (arg === '-V') ? '-v' : arg;
});
// $ sails version (--version synonym)
program
.command('version')
.description('')
.action(program.versionInformation);
program
.unknownOption = NOOP;
program.usage('[command]');
// $ sails lift
var cmd;
cmd = program.command('lift');
cmd.option('--prod', 'Lift in "production" environment.');
cmd.option('--staging', 'Lift in "staging" environment.');
cmd.option('--port [port]', 'Listen on the specified port (defaults to 1337).');
cmd.option('--silent', 'Set log level to "silent".');
cmd.option('--verbose', 'Set log level to "verbose".');
cmd.option('--silly', 'Set log level to "silly".');
cmd.unknownOption = NOOP;
cmd.description('');
cmd.alias('l');
cmd.action(require('./sails-lift'));
// $ sails new <appname>
cmd = program.command('new [path_to_new_app]');
// cmd.option('--dry');
cmd.option('--no-frontend', 'Don\'t generate "assets", "views" or "task" folders.');
cmd.option('--fast', 'Don\'t install node modules after generating app.');
cmd.usage('[path_to_new_app]');
cmd.unknownOption = NOOP;
cmd.description('');
cmd.action(require('./sails-new'));
// $ sails generate <module>
cmd = program.command('generate');
// cmd.option('--dry');
cmd.unknownOption = NOOP;
cmd.description('');
cmd.usage('[something]');
cmd.action(require('./sails-generate'));
// $ sails upgrade
cmd = program.command('upgrade');
cmd.unknownOption = NOOP;
cmd.description('');
cmd.action(require('./sails-upgrade'));
// $ sails migrate
cmd = program.command('migrate');
cmd.unknownOption = NOOP;
cmd.description('');
cmd.action(require('./sails-migrate'));
// $ sails console
cmd = program.command('console');
cmd.option('--silent', 'Set log level to "silent".');
cmd.option('--verbose', 'Set log level to "verbose".');
cmd.option('--silly', 'Set log level to "silly".');
cmd.option('--dontLift', 'Start console session without lifting an HTTP server.');
cmd.unknownOption = NOOP;
cmd.description('');
cmd.alias('c');
cmd.action(require('./sails-console'));
// $ sails www
// Compile `assets` directory into a standalone `www` folder.
cmd = program.command('www');
cmd.unknownOption = NOOP;
cmd.description('');
cmd.action(require('./sails-www'));
// $ sails debug
cmd = program.command('debug');
cmd.unknownOption = NOOP;
cmd.description('(for Node v5 and below)');
cmd.action(require('./sails-debug'));
// $ sails inspect
cmd = program.command('inspect');
cmd.unknownOption = NOOP;
cmd.description('(for Node v6 and above)');
cmd.action(require('./sails-inspect'));
// $ sails run
cmd = program.command('run');
cmd.usage('[name-of-script]');
cmd.unknownOption = NOOP;
cmd.description('');
cmd.action(require('./sails-run'));
// $ sails test
cmd = program.command('test');
cmd.unknownOption = NOOP;
cmd.description('');
cmd.action(function(){
require('./sails-run')('test', _.last(arguments));
});
// $ sails lint
cmd = program.command('lint');
cmd.unknownOption = NOOP;
cmd.description('');
cmd.action(function(){
require('./sails-run')('lint', _.last(arguments));
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - -
// $ sails deploy
cmd = program.command('deploy');
// cmd.option('--dry');
cmd.unknownOption = NOOP;
cmd.description('');
cmd.usage('');
cmd.action(require('./sails-deploy'));
// FUTURE: ^^ Consider simplifying this into a script.
// - - - - - - - - - - - - - - - - - - - - - - - - - - -
// $ sails debug-console
cmd = program.command('debug-console');
cmd.unknownOption = NOOP;
cmd.description('');
cmd.alias('dc');
cmd.action(require('./sails-debug-console'));
//
// Normalize help argument, i.e.
//
// $ sails --help
// $ sails help
// $ sails
// $ sails <unrecognized_cmd>
//
// $ sails help (--help synonym)
cmd = program.command('help [command]');
cmd.description('');
cmd.action(function(){
if (program.args.length > 1 && _.isString(program.args[0])) {
var helpCmd = _.find(program.commands, {_name: program.args[0]});
if (helpCmd) {
helpCmd.help();
return;
}
}
program.help();
});
// $ sails <unrecognized_cmd>
// Output Sails help when an unrecognized command is used.
program
.command('*')
.action(function(cmd){
console.log('\n ** Unrecognized command:', cmd, '**');
program.help();
});
// Don't balk at unknown options
program.unknownOption = NOOP;
// $ sails
//
program.parse(process.argv);
var NO_COMMAND_SPECIFIED = program.args.length === 0;
if (NO_COMMAND_SPECIFIED) {
program.help();
}