forked from ReactPrimer/ReactPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileContent.js
33 lines (26 loc) · 976 Bytes
/
fileContent.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
//this function will return the component template to be populated in the project folder
function fileContent(component) {
let content = "";
const cache = {};
content += "import React, { Component } from 'react';\n";
for (let i = 0; i < component.children.length; i++) {
if (!cache[component.children[i].title]) {
cache[component.children[i].title] = true;
content += `import ${component.children[i].title} from './${component.children[i].title}.jsx'\n`;
}
}
content += `\nclass ${component.title} extends Component {\n`;
content += ` render() {\n`;
content += ` return (\n`;
content += ` <div>\n`;
for (let i = 0; i < component.children.length; i++) {
content += ` <${component.children[i].title} />\n`;
}
content += ` </div>\n`;
content += ` );\n`;
content += ` };\n`;
content += `}\n`;
content += `export default ${component.title};`;
return content;
}
module.exports = fileContent;