|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | | -var exists = require('fs').existsSync |
4 | | -var join = require('path').join |
5 | | -var logger = require('../lib/logger') |
6 | | -var program = require('commander') |
7 | | -var resolve = require('path').resolve |
8 | | -var spawn = require('child_process').spawn |
9 | | -var stat = require('fs').statSync |
10 | | - |
11 | | -/** |
12 | | - * Usage. |
13 | | - */ |
14 | | - |
15 | | -program |
| 3 | +require('commander') |
16 | 4 | .version(require('../package').version) |
17 | 5 | .usage('<command> [options]') |
18 | | - |
19 | | -/** |
20 | | - * Help. |
21 | | - */ |
22 | | - |
23 | | -program.on('--help', function () { |
24 | | - console.log() |
25 | | - console.log(' Commands:') |
26 | | - console.log() |
27 | | - console.log(' init generate a new project from a template') |
28 | | - console.log(' list list available official templates') |
29 | | - console.log() |
30 | | -}) |
31 | | - |
32 | | -/** |
33 | | - * Parse. |
34 | | - */ |
35 | | - |
36 | | -program.parse(process.argv) |
37 | | -if (!program.args.length) program.help() |
38 | | - |
39 | | -/** |
40 | | - * Settings. |
41 | | - */ |
42 | | - |
43 | | -var cmd = program.args[0] |
44 | | -var args = process.argv.slice(3) |
45 | | -var name = 'vue-' + cmd |
46 | | - |
47 | | -/** |
48 | | - * Resolve a local or remote executable. |
49 | | - */ |
50 | | - |
51 | | -var bin = join(__dirname, name) |
52 | | -if (!exists(bin)) { |
53 | | - bin = process.env.PATH.split(':').reduce(function (binary, path) { |
54 | | - path = resolve(path, bin) |
55 | | - return exists(path) && stat(path).isFile() ? path : binary |
56 | | - }, bin) |
57 | | -} |
58 | | - |
59 | | -if (!exists(bin)) logger.fatal('The "%s" command does not exist.', name) |
60 | | - |
61 | | -/** |
62 | | - * Spawn a new, forwarded child process with the executable. |
63 | | - */ |
64 | | - |
65 | | -spawn(bin, args, { stdio: 'inherit' }) |
66 | | - .on('close', process.exit.bind(process)) |
| 6 | + .command('init', 'generate a new project from a template') |
| 7 | + .command('list', 'list available official templates') |
| 8 | + .parse(process.argv) |
0 commit comments