-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-rc-folder.js
More file actions
executable file
·58 lines (47 loc) · 1.46 KB
/
create-rc-folder.js
File metadata and controls
executable file
·58 lines (47 loc) · 1.46 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
const fs = require('fs');
// type createRCFolderArgs = {
// componentName: string;
// type?: 'atoms' | 'molecules' | 'organisms';
// customDir?: string | null;
// };
const createRCFolder = (
{ componentName, type = 'atoms', customDir = null } /*: createRCFolderArgs*/
) => {
const DEFAULT_DIR = 'apps/root/src/components/UI';
const DEFAULT_COMPONENT = `${type}/${componentName}`;
const selectedDir = `${
!customDir ? DEFAULT_DIR : customDir
}/${DEFAULT_COMPONENT}`;
!fs.existsSync(selectedDir) && fs.mkdirSync(selectedDir, { recursive: true });
/* Creating index export React Component File */
fs.writeFile(
`${selectedDir}/index.ts`,
`export { default } from './${componentName}';\n`,
(err) => {
if (err) throw err;
}
);
/* Creating React Component File */
fs.writeFile(
`${selectedDir}/${componentName}.tsx`,
`import css from './${componentName}.module.scss';
type ${componentName}Props = {};
const ${componentName} = (props: ${componentName}Props) => {
const {} = props;
return (<div className={css.${componentName.toLowerCase()}}></div>);
};
export default ${componentName};\n`,
(err) => {
if (err) throw err;
}
);
/* Creating SCSS Modules React Component File */
fs.writeFile(
`${selectedDir}/${componentName}.module.scss`,
`.${componentName.toLowerCase()}{};\n`,
(err) => {
if (err) throw err;
}
);
};
module.exports = { createRCFolder };