(components: IComponents)
| 180 | } |
| 181 | |
| 182 | export const generateCode = async (components: IComponents) => { |
| 183 | let code = buildBlock({ component: components.root, components }) |
| 184 | let componentsCodes = buildComponents(components) |
| 185 | const iconImports = Array.from(new Set(getIconsImports(components))) |
| 186 | |
| 187 | const imports = [ |
| 188 | ...new Set( |
| 189 | Object.keys(components) |
| 190 | .filter(name => name !== 'root') |
| 191 | .map(name => components[name].type), |
| 192 | ), |
| 193 | ] |
| 194 | |
| 195 | code = `import React from 'react'; |
| 196 | import { |
| 197 | ChakraProvider, |
| 198 | ${imports.join(',')} |
| 199 | } from "@chakra-ui/react";${ |
| 200 | iconImports.length |
| 201 | ? ` |
| 202 | import { ${iconImports.join(',')} } from "@chakra-ui/icons";` |
| 203 | : '' |
| 204 | } |
| 205 | |
| 206 | ${componentsCodes} |
| 207 | |
| 208 | const App = () => ( |
| 209 | <ChakraProvider resetCSS> |
| 210 | ${code} |
| 211 | </ChakraProvider> |
| 212 | ); |
| 213 | |
| 214 | export default App;` |
| 215 | |
| 216 | return await formatCode(code) |
| 217 | } |
no test coverage detected