-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
executable file
·63 lines (55 loc) · 1.79 KB
/
index.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
#!/usr/bin/env node
const program = require('commander')
const inquirer = require('inquirer')
const createProject = require('./src/create')
const { commands, preHook } = require('./src/scripts')
const { log, colorize } = require('./src/util')
const { version } = require('./package.json')
program.version(version).description('Create client + server apps with one CLI command. Easy. Unobstrusive. Powerful.')
program
.command('init <projectName> [projectFolderName]')
.description('Initialize a project.')
.action(async (projectName, projectFolderName) => {
let urlTemplate = 'ghondar/counter-with-redux-ducks-and-sagas-template'
const { manager, template } = await inquirer.prompt([
{
type : 'list',
name : 'manager',
message : 'Choose Package Manager:',
choices : [ 'yarn', 'npm' ],
'default': 'yarn'
},
{
type : 'list',
name : 'template',
message : 'Choose Template:',
choices : [ 'default', 'typescript', 'custom' ],
'default': 'default'
}
])
if(template === 'typescript') {
urlTemplate = urlTemplate + '#typescript'
} else if(template === 'custom') {
const { url } = await inquirer.prompt([
{
type : 'input',
name : 'url',
message: 'Git URL Template:'
}
])
urlTemplate = url
}
createProject({ projectName, projectFolderName, manager, urlTemplate })
})
commands.forEach(({ name, fn, description = '' }) => {
program
.command(name)
.allowUnknownOption()
.description(description)
.action(async () => {
const { error } = await preHook()
if(!error) fn()
else log({ text: colorize(error).FgRed(), type: 'error' })
})
})
program.parse(process.argv)