-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (43 loc) · 1.25 KB
/
index.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
#!/usr/bin/env node
const { makeHookTemplate, scssTemplate } = require("./template");
const fs = require("fs");
const path = require("path");
const option = require("./ComponentMaker.json");
const componentName = process.argv[2];
const PATH = `src/components/${componentName}`;
const makeComponentFolder = (componentName) => {
makeFolder("src");
makeFolder(`src/components`);
makeFolder(`src/components/${componentName}`);
};
const makeFolder = (dir) => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
};
const getScriptFileName = () => {
return componentName + `.${option["script-type"]}x`;
};
const makeScriptFile = () => {
const tsxFileName = getScriptFileName();
const script = makeHookTemplate(componentName, option);
makeFile(tsxFileName, script);
};
const makeModuleScss = () => {
const moduleScssFileName = componentName + ".module.scss";
makeFile(moduleScssFileName, scssTemplate);
};
const makeFile = (fileName, template) => {
const filePath = path.join(PATH, fileName);
if (!fs.existsSync(filePath)) {
fs.writeFileSync(filePath, template);
}
};
const program = (componentName) => {
makeComponentFolder(componentName);
makeScriptFile();
if (option["module-css"]) {
makeModuleScss();
}
};
program(componentName);