* Creates component Tree object for rendering by calling on methods defined in importPath.js
()
| 130 | * Creates component Tree object for rendering by calling on methods defined in importPath.js |
| 131 | */ |
| 132 | constructComponentTreeObj() { |
| 133 | const projInfo = JSON.parse(fs.readFileSync(path.join(__dirname, '../lib/projInfo.js'))); |
| 134 | //checks if there is react entry point by checking our properties in projinfo that is generated by file-tree.js |
| 135 | if (projInfo.reactEntry !== '') { |
| 136 | let rootPath = path.dirname(projInfo.reactEntry); |
| 137 | let fileName = path.basename(projInfo.reactEntry); |
| 138 | const componentObj = importPathFunctions.constructComponentTree(fileName, rootPath); |
| 139 | console.log('componentObj = ', componentObj) |
| 140 | this.setState({ |
| 141 | componentTreeObj: componentObj |
| 142 | }); |
| 143 | } else if (projInfo.reactEntry === '') { |
| 144 | let rootPath = path.dirname(projInfo.reactEntry); |
| 145 | let fileName = path.basename(projInfo.reactEntry); |
| 146 | const componentObj = importPathFunctions.constructComponentTree(fileName, rootPath); |
| 147 | this.setState({ |
| 148 | componentTreeObj: componentObj |
| 149 | }); |
| 150 | }//If there is no webpack, it checks if its create react app application |
| 151 | else if (projInfo.CRA === true) { |
| 152 | let rootPath = path.join(projInfo.rootPath, 'src'); |
| 153 | const componentObj = importPathFunctions.constructComponentTree('App.js', rootPath); |
| 154 | this.setState({ |
| 155 | componentTreeObj: componentObj |
| 156 | }); |
| 157 | } |
| 158 | else if (projInfo.reactEntry === '') { |
| 159 | let rootPath = path.dirname(projInfo.reactEntry); |
| 160 | let fileName = path.basename(projInfo.reactEntry); |
| 161 | const componentObj = importPathFunctions.constructComponentTree(fileName, rootPath); |
| 162 | console.log('componentObj = ', componentObj) |
| 163 | this.setState({ |
| 164 | componentTreeObj: componentObj |
| 165 | }) |
| 166 | } |
| 167 | // if neither Create React App or have webpack, then can't render it |
| 168 | else { |
| 169 | this.setState({ |
| 170 | componentTreeObj: {} |
| 171 | }); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Registers listeners for opening projects and new projects |