MCPcopy
hub / github.com/premieroctet/openchakra / generateCode

Function generateCode

src/utils/code.ts:182–217  ·  view source on GitHub ↗
(components: IComponents)

Source from the content-addressed store, hash-verified

180}
181
182export 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';
196import {
197 ChakraProvider,
198 ${imports.join(',')}
199} from "@chakra-ui/react";${
200 iconImports.length
201 ? `
202import { ${iconImports.join(',')} } from "@chakra-ui/icons";`
203 : ''
204 }
205
206${componentsCodes}
207
208const App = () => (
209 <ChakraProvider resetCSS>
210 ${code}
211 </ChakraProvider>
212);
213
214export default App;`
215
216 return await formatCode(code)
217}

Callers 3

getCodeFunction · 0.90
exportToCodeSandboxFunction · 0.90
code.test.tsFile · 0.90

Calls 4

buildBlockFunction · 0.85
buildComponentsFunction · 0.85
getIconsImportsFunction · 0.85
formatCodeFunction · 0.85

Tested by

no test coverage detected