-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
executable file
·50 lines (41 loc) · 1.09 KB
/
cli.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
#!/usr/bin/env node
'use strict'
const yargs = require('yargs')
const pkg = require('./package.json')
const tasks = require('./tasks.js')
const COMMANDS = {
new: 'Scaffold and initialize a new Cerebral application.'
}
const USAGE = 'Usage: cerebral-cli <command> {options}'
const AVAILABLE_COMMANDS = `Available commands: ${Object.keys(COMMANDS).join(', ')}`
const argv = yargs
.usage(USAGE)
.demand(1)
.check(function (argv) {
if (Object.keys(COMMANDS).indexOf(command) === -1) {
throw Error(
`Invalid command: ${command}
${AVAILABLE_COMMANDS}`
)
}
return true
})
Object.keys(COMMANDS).forEach(command => {
argv.command(command, COMMANDS[command], function(argv) {
if (!argv.argv._[1]) throw new Error('You must provide an application name.')
})
})
argv
.example('cerebral-cli new my-app', 'Create new-app dir with project files.')
argv
.version(pkg.version)
.alias('v', 'version')
.help('h')
.alias('h', 'help')
.argv
const ARGV = argv.argv
const command = ARGV._[0]
const options = {
appName: ARGV._[1]
}
tasks[command](options)