-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (56 loc) · 1.79 KB
/
index.js
File metadata and controls
58 lines (56 loc) · 1.79 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
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node
const yargs = require('yargs');
const chalk = require('chalk');
const util = require('./util.js');
const log = require('./log.js');
const core = require('./core.js');
yargs
.scriptName('scaffold')
.command(
'$0 [name] [type] [storybookCategory]',
chalk.green.bold('Scaffold a React component with styles, tests and a story.'),
(y) => {
y.example('$0', 'ActionPanel');
y.example('$0', 'ActionPanel class');
y.example('$0', 'ActionPanel --type class');
y.example('$0', 'ActionPanel Common');
y.example('$0', 'ActionPanel --sb Common');
},
(argv) => {
return core.Scaffold(argv.name, argv.type, argv.sb).then(() => {
log.info(chalk.bold("Scaffolding complete!"))
})
.catch(ex => {
log.err(ex);
});
})
.option('name', {
alias: 'n',
type: 'string',
description: chalk.blue('The name of the component to scaffold'),
demandOption: true
})
.option('type', {
alias: 't',
type: 'string',
description: chalk.blue('Type of the React component'),
choices: ['functional', 'class'],
default: 'functional'
})
.option('storybookCategory', {
alias: 'sb',
type: 'string',
description: chalk.blue('Category for the Story to use'),
default: 'Common'
})
.check((argv) => {
//check first letter of name is a capital
if(!(util.isCapitalLetter(argv.name[0]))) {
log.err('Error: The component name should be capitalised.');
return false;
};
return true;
})
.wrap(yargs.terminalWidth())
.help()
.argv;