-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateContainer.js
53 lines (39 loc) · 1.15 KB
/
generateContainer.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
const fs = require('fs');
const name = process.argv[2];
const nameCamelCase = name.replace(/^[A-Z]/, l => l.toLowerCase());
const componentName = name.replace(/Container$/, '');
if (!name) {
console.error('Missing container name as first and only command argument');
process.exit(1);
} else if (
!(name[0].charCodeAt() >= 65 && name[0].charCodeAt() <= 90) ||
!/Container$/.test(name)
) {
console.error('Container name must be PascalCase, start with a letter, and end in "Container"');
process.exit(1);
}
const containerTemplate = `\
import {
compose,
} from 'recompose';
import ${componentName} from '../../components/${componentName}';
export default compose()(${componentName});
`;
const indexTemplate = `\
import ${name} from './${nameCamelCase}';
export default ${name};
`;
fs.mkdir(`${__dirname}/app/containers/${name}`, (err) => {
if (err) {
console.error(err);
process.exit(1);
}
fs.writeFileSync(
`${__dirname}/app/containers/${name}/${nameCamelCase}.jsx`,
containerTemplate
);
fs.writeFileSync(
`${__dirname}/app/containers/${name}/index.js`,
indexTemplate
);
});