-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbin.js
executable file
·66 lines (57 loc) · 1.37 KB
/
bin.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
#!/usr/bin/env node
const minimist = require('minimist')
const argv = minimist(process.argv.slice(2))
const dedent = require('dedent')
const inquirer = require('inquirer')
const createApp = require('./commands/createApp')
const createTopic = require('./commands/createTopic')
const createType = require('./commands/createType')
const promptText = `
Please provide a valid command:
- app
- topic
- type
e.g. $ npx create-dogstack-app topic
or $ npx create-dogstack-app --help to see all options in full.
`
;(function main (argv) {
const cmd = argv._[0]
const arg = argv._[1]
switch (cmd) {
case 'app':
createApp({ appName: arg })(done)
break
case 'topic':
createTopic({ topicName: arg })(done)
break
case 'type':
createType({ typeName: arg })(done)
break
default:
prompt()
}
function prompt () {
console.log(promptText)
inquirer.prompt([{
type: 'list',
name: 'command',
message: 'Choose a valid command:',
choices: [
'app',
'topic',
'type'
]
}])
.then(function (answers) {
const command = answers.command
main({ _: [command] })
})
}
function done (err, res) {
if (err) {
console.log('Aborting. The following error occured:')
console.log(' ' + err.message + '\n')
process.exitcode = 1
}
}
})(argv)