-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.js
More file actions
64 lines (52 loc) · 1.53 KB
/
template.js
File metadata and controls
64 lines (52 loc) · 1.53 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
59
60
61
62
63
64
function makeHookTemplate(componentName, config) {
const cssTemplate = config["module-css"]
? ImportModuleCss(componentName, config["css-prefix"])
: "";
const scriptTemplate = ImportScript(componentName, config["script-type"]);
const baseTemplate = "import * as React from 'react';";
const template = joinEscape(baseTemplate, cssTemplate, scriptTemplate);
return template;
}
const joinEscape = (...templates) => {
return templates.join("\n");
};
const makeCamelCase = (name) => {
const words = name.split("-");
const camelWords = words.map((word) => {
return word[0].toUpperCase() + word.slice(1);
});
return camelWords.join("");
};
const scssTemplate = `@import "/mixin"`;
const tsHookTemplate = (componentName) => {
const camelComponentName = makeCamelCase(componentName);
return `
interface ${camelComponentName}Props{
}
export default function ${camelComponentName} (props:${camelComponentName}Props) {
return (
);
}`;
};
const jsHookTemplate = (componentName) => {
const camelComponentName = makeCamelCase(componentName);
return `
export default function ${camelComponentName} (props) {
return (
);
}`;
};
function ImportModuleCss(componentName, prefix) {
return `import styles from './${componentName}.module.${prefix}'`;
}
function ImportScript(componentName, prefix) {
if (prefix === "ts") {
return tsHookTemplate(componentName);
} else if (prefix === "js") {
return jsHookTemplate(componentName);
}
}
module.exports = {
makeHookTemplate,
scssTemplate,
};