-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-react-oui.js
89 lines (70 loc) · 2.19 KB
/
go-react-oui.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const { Generator } = require('goman')
const inquirerDirectory = require('inquirer-directory')
const toSlugCase = require('to-slug-case')
const help = `
g react-oui -c [name] -d [baseDir]
name - component name
baseDir - component's base directory
`
module.exports = class extends Generator {
constructor(opts) {
super(opts);
this.inquirer.registerPrompt('directory', inquirerDirectory);
this.props = {}
}
mapArgsToProps() {
this.props.componentName = this.argv.c;
this.props.componentDir = this.argv.d;
return Promise.resolve(() => {
this.props = Object.assign({}, this.props, props)
});
}
validateProps() {
const { componentName, componentDir } = this.props
let errors = [];
if (!componentName) errors.push('Invalid component name.');
if (!componentDir) errors.push('Invalid component base directory.');
this.props.errors = errors;
}
prompting() {
return this.mapArgsToProps()
.then(this.validateProps.bind(this));
}
writing() {
if (this.props.errors.length > 0) {
return this.logger.logError(`${ this.props.errors.join(' ') } ${ help }`);
}
const name = this.props.componentName;
const dir = this.props.componentDir || process.cwd();
this.fs.copyTpl(
this.templatePath('./component.tmpl.js'),
this.destinationPath(`${dir}/${name}/${name}.js`),
{ ...this.props, componentSlugName: toSlugCase(this.props.componentName) }
);
this.fs.copyTpl(
this.templatePath('./component.tmpl.spec.js'),
this.destinationPath(`${dir}/${name}/tests/index.js`),
this.props
);
this.fs.copyTpl(
this.templatePath('./component.tmpl.story.js'),
this.destinationPath(`${dir}/${name}/${name}.story.js`),
this.props
);
this.fs.copyTpl(
this.templatePath('./example.tmpl.js'),
this.destinationPath(`${dir}/${name}/examples/index.js`),
this.props
);
this.fs.copyTpl(
this.templatePath('./index.tmpl.js'),
this.destinationPath(`${dir}/${name}/index.js`),
this.props
);
this.fs.copyTpl(
this.templatePath('./README.tmpl.md'),
this.destinationPath(`${dir}/${name}/README.md`),
this.props
);
}
}