Skip to content

Commit 6098342

Browse files
committed
use commander's own sub command feature
1 parent 61d212a commit 6098342

File tree

3 files changed

+7
-67
lines changed

3 files changed

+7
-67
lines changed

bin/vue

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,8 @@
11
#!/usr/bin/env node
22

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')
164
.version(require('../package').version)
175
.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)

bin/vue-init

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var chalk = require('chalk')
1717
*/
1818

1919
program
20-
.usage('<template> <project-name>')
20+
.usage('<template-name> <project-name>')
2121

2222
/**
2323
* Help.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{
22
"name": "vue-cli",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "A simple CLI for scaffolding Vue.js projects.",
55
"preferGlobal": true,
66
"bin": {
7-
"vue": "bin/vue",
8-
"vue-init": "bin/vue-init",
9-
"vue-list": "bin/vue-list"
7+
"vue": "bin/vue"
108
},
119
"scripts": {
1210
"test": "mocha"

0 commit comments

Comments
 (0)