-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·47 lines (40 loc) · 1.35 KB
/
index.js
File metadata and controls
executable file
·47 lines (40 loc) · 1.35 KB
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
#!/usr/bin/env node
require('colors');
const program = require('commander');
const pjson = require('./package.json');
const { getConfig } = require('./config');
const config = getConfig();
const generateComponent = require('./actions/generateComponent');
const initProject = require('./actions/initProject');
const { cond } = require('./utils/index');
const isNextJS = config.framework === 'nextjs';
cond(program)
.chain(program => program
.version(pjson.version, '-v, --version')
.command('component <component>')
.option('-s, --style', 'With stylesheet')
.option('-f, --functional', 'Create functional component')
.option('-c, --withConnect', 'Wrap with redux connect')
.option('--subfolder [subfolder]', 'Folder when you want to store your component', 'components')
)
.if(isNextJS, program => program.option('--withGetInitialProps', 'Attach getInitialProps static method'))
.chain(program => program.action(generateComponent))
.end();
if (isNextJS) {
program
.command('page <page>')
.option('-f, --functional', 'Create functional component')
.action((page, cmd) => generateComponent(page, cmd, {
withGetInitialProps: true,
subfolder: 'pages',
}));
}
program
.command('init')
.action(initProject);
program
.command('config')
.action(() => {
console.log(config);
});
program.parse(process.argv);