forked from rthor/cra-generate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·41 lines (36 loc) · 1.34 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
'use strict'
const commander = require('commander')
const chalk = require('chalk')
const path = require('path')
const getConfig = require('./config')
const generate = require('./lib/generate')
const version = require('./package.json').version
let component = null
const program = commander
.version(version)
.option('-f, --functional', 'create a functional component')
.option('-t, --type-check [system]', 'add @flow comment to script files')
.option('-c, --css-extension [extension]', 'changes the extension of generated css files')
.option('-d, --directory [dir]', 'specify a directory for the component')
.option('--no-semi', 'remove semicolons')
.option('--test [type]', 'either "jest" or "none"')
.arguments('<component>')
.action((c) => component = c)
.parse(process.argv)
if (component == null) {
console.error(chalk.red('A component’s name is required.'))
console.log(` ${chalk.cyan(program.name())} ${chalk.green('<component>')}`)
process.exit(1)
}
try {
const { files, componentName, componentPath } = generate(component, program)
console.log(chalk.green(`Generated ${chalk.cyan.bold(componentName)} at ${
chalk.cyan(`./${path.relative(process.cwd(), componentPath)}`)
}:`))
for (const file of files) {
console.log(' -', file.fileName)
}
} catch (error) {
console.log(chalk.red(error.message))
}
console.log('')