1 | 'use strict';
|
2 |
|
3 | var Q = require('q'),
|
4 | CP = require('child_process'),
|
5 | PATH = require('./path');
|
6 |
|
7 | Q.longStackJumpLimit = 0;
|
8 |
|
9 | module.exports = require('coa').Cmd()
|
10 | .name(PATH.basename(process.argv[1]))
|
11 | .title(['Tools to work with files written using the BEM-method.', '' +
|
12 | 'See http://bem.github.com/bem-method/ for more info.'].join('\n'))
|
13 | .helpful()
|
14 | .opt()
|
15 | .name('version').title('Show version')
|
16 | .short('v').long('version')
|
17 | .flag()
|
18 | .only()
|
19 | .act(function() {
|
20 | return require('../package.json').version;
|
21 | })
|
22 | .end()
|
23 | .cmd().name('decl').apply(require('./commands/decl')).end()
|
24 | .cmd().name('build').apply(require('./commands/build')).end()
|
25 | .cmd().name('create').apply(require('./commands/create')).end()
|
26 | .cmd().name('make').apply(require('./commands/make')).end()
|
27 | .cmd().name('server').apply(require('./commands/server')).end()
|
28 | .cmd().name('bench').apply(require('./commands/bench')).end()
|
29 | .completable()
|
30 | .act(function() {
|
31 | var defer = Q.defer(),
|
32 | readline = require('readline'),
|
33 | rl = readline.createInterface(process.stdin, process.stdout),
|
34 | prefix = '> ';
|
35 | rl.setPrompt(prefix, prefix.length);
|
36 |
|
37 | rl.on('line', function(line) {
|
38 | line = line.trim();
|
39 | if (!line) {
|
40 | rl.prompt();
|
41 | return;
|
42 | }
|
43 | var child = CP.spawn(process.argv[0],
|
44 | process.argv.slice(1, 2).concat(line.split(' ')),
|
45 | { cwd: process.cwd(), customFds: [-1, 1, 2] });
|
46 | child.on('exit', function() {
|
47 | rl.prompt();
|
48 | });
|
49 | })
|
50 | .on('close', function() {
|
51 | console.log('');
|
52 | process.stdin.destroy();
|
53 | defer.resolve();
|
54 | });
|
55 |
|
56 |
|
57 | console.log("Type '--help' for help, press ctrl+d or ctrl+c to exit");
|
58 |
|
59 | rl.prompt();
|
60 |
|
61 | return defer.promise;
|
62 | });
|