-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
279 lines (232 loc) · 7.14 KB
/
index.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
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
/**
SoapBox Simon CLI implementation
*/
var fs = require('fs'),
path = require('path'), // Path. http://nodejs.org/api/path.html
configFileName = path.join(process.cwd(), 'simon.json'), // Current project simon.json
program, // Commander. Command-line interface provider. https://github.com/visionmedia/commander.js
Command, // Constructor class for Commander
pkg, config, simon;
require('colors');
program = require('commander');
Command = program.Command;
pkg = require('./package.json'); // package.json info
// Instantiate Simon!
simon = require('./lib/simon');
// Don't exist when there's an unknown options (could belong to the proxy)
Command.prototype.unknownOption = function (flag) {
console.warn();
console.warn(" Warning: unknown option `%s'", flag);
console.warn();
//process.exit(1);
};
// Parse given commandline arguments
// Makes sure that the executed commands get the right args
function parseArgs(command) {
var args = process.argv,
commandIndex = command ? args.indexOf(command) : -1;
return args.slice(commandIndex + 1);
}
// Perform configuration based on simon.json
function configureSimon(simon, config, program, skipSimonJsonCheck) {
var configExists = fs.existsSync(configFileName);
if (!skipSimonJsonCheck && !configExists) {
// Make sure simon.json is defined
console.error([
'',
' No simon.json file found. Visit',
' https://github.com/nfrasser/simon',
' To find out how to set this up\n'
].join('\n'));
process.exit();
}
config = config || configExists ? require(configFileName) : {};
// Perform configuration
if (program.local) {
config.local = true;
}
if (program.super) {
config.hhvm = true;
}
// Simon's help method will be the commander's help
config.help = program.outputHelp.bind(program);
// Get the banner
config.banner = fs.readFileSync(
path.join(
__dirname, 'lib', 'options', 'banner.txt'), {
encoding: 'utf8'
}
);
// Perform configuation
simon.configure(config);
return simon;
}
// Setup for program commands
program.version(pkg.version)
.option('-i, --interactive', 'Jump right into interactive mode.')
.option('-l, --local', 'Run all commands locally instead of on the Vagrant VM.')
.option('-s, --super', 'Run PHP commands such as PHPUnit and Artisan with HHVM.')
.option('--subdomain [slug]', 'Specify a subdomain for the "add" and "remove" commands');
// Add the currently configured domain to the hosts file
program.command('add')
.description('Add a new website for the current project')
.action(function () {
configureSimon(simon, config, program);
simon.add(program.subdomain);
});
// Run artisan
program.command('artisan *')
.description('Run the local php artisan command')
.action(function (args) {
configureSimon(simon, config, program);
args = parseArgs('artisan');
simon.artisan.apply(simon, args);
});
// Run bower
program.command('bower *')
.description('Run the bower command')
.action(function (args) {
configureSimon(simon, config, program);
args = parseArgs('bower');
simon.bower.apply(simon, args);
});
// Run composer
program.command('composer *')
.description('Run the composer command')
.action(function (args) {
configureSimon(simon, config, program);
args = parseArgs('composer');
simon.composer.apply(simon, args);
});
// Run git
program.command('git *')
.description('Run git')
.action(function (args) {
configureSimon(simon, config, program);
args = parseArgs('git');
simon.git.apply(simon, args);
});
// Run grunt
program.command('grunt *')
.description('Run grunt command')
.action(function (args) {
configureSimon(simon, config, program);
args = parseArgs('grunt');
simon.grunt.apply(simon, args);
});
program.command('help')
.description('Show this help block')
.action(function () {
configureSimon(simon, config, program, true);
simon.help();
});
// Run the install
program.command('install')
.description('Install all vendor dependencies from NPM, Composer, and Bower')
.action(function () {
configureSimon(simon, config, program);
simon.install();
});
// Run NPM
program.command('npm *')
.description('Run the npm command')
.action(function (args) {
configureSimon(simon, config, program);
args = parseArgs('npm');
simon.npm.apply(simon, args);
});
// Fix permissions on the app/storage folder
program.command('permissions')
.description('Fix permissions on the app/storage folder (UNIX only)')
.action(function () {
configureSimon(simon, config, program);
simon.permissions();
});
// Run php
program.command('php *')
.description('Run the php command')
.action(function (args) {
configureSimon(simon, config, program);
args = parseArgs('php');
simon.php.apply(simon, args);
});
// Run PHPUnit
program.command('phpunit *')
.description('Run the local phpunit command')
.action(function (args) {
//args = arguments.length > 1 ? Array.prototype.slice.call(arguments, 0, -1) : [];
configureSimon(simon, config, program);
args = parseArgs('phpunit');
simon.phpunit.apply(simon, args);
});
// Run refresh
program.command('refresh')
.description('Rollback and reapply migrations, seed the database')
.action(function () {
configureSimon(simon, config, program);
simon.refresh();
});
// Remove the currently configured domain from the hosts file
program.command('remove')
.description('Remove the website for the current project')
.action(function () {
configureSimon(simon, config, program);
simon.remove(program.subdomain);
});
// Run a command on the Vagrant VM
program.command('ssh <cmd>')
.description('Run the given command on the Vagrant VM')
.action(function (/*cmd*/) {
configureSimon(simon, config, program);
var args = parseArgs('ssh');
simon.ssh.call(simon, args.join(' '));
});
// Initialize the app
program.command('start')
.description('Initialize the development environment')
.action(function () {
configureSimon(simon, config, program);
simon.start();
});
// Run update for all package managers
program.command('update')
.description('Update all vendor dependencies from NPM, Composer, and Bower')
.action(function () {
configureSimon(simon, config, program);
simon.update();
});
// Run Vagrant
program.command('vagrant *')
.description('Run the vagrant command')
.action(function (args) {
configureSimon(simon, config, program);
args = parseArgs('vagrant');
simon.vagrant.apply(simon, args);
});
// Run a grunt command
program.command('*')
.description('Run a given Grunt task')
.action(function (task) {
var args = parseArgs(task);
configureSimon(simon, config, program);
args.unshift(task);
simon.grunt.apply(simon, args);
});
program.on('help', function () {
console.log(' Run simon without arguments to enter ' + 'interactive mode\n'.bold);
console.log([
' If you\'re running a proxy command, make sure you specify any',
' options to simon ' + 'before'.bold + ' the command you want to call.\n',
' In this command, the -s options will be applied to simon, and the --debug',
' options will be applied to phpunit:\n',
' simon -s phpunit --debug\n'
].join('\n'));
});
program.parse(process.argv);
module.exports = {
program: program,
simon: simon,
options: config,
configure: configureSimon,
parse: parseArgs
};