import { codeFromAST, addElementToVarDecl, addDecl, addTypeReference } from "./utils"; import cantinflas from "cantinflas"; export default function astComponent({ uiAST, schemasAST, alias, componentTplFile, schemaTplFile, storiesTplFile, name, niceName }) { const astImport = addDecl({ type: "lazyImport", ast: uiAST, name, alias }); const astEXPORT = addElementToVarDecl( { ast: astImport, name }, "components" ); const astNamedExport = addDecl({ type: "namedExport", ast: astEXPORT, name }); const astTypeRef = addTypeReference({ ast: astNamedExport, name }); // SCHEMA const schemaImport = addDecl({ type: "import", ast: schemasAST, name }); const schemaNamedExport = addDecl({ type: "defaultExport", ast: schemaImport, name }); const uiCode = codeFromAST(astTypeRef); const schemaCode = codeFromAST(schemaNamedExport); const componentTpl = cantinflas(componentTplFile, { NAME: name }); const schemaTpl = cantinflas(schemaTplFile, { DISPLAY_NAME: niceName, NAME: name }); const storiesTpl = cantinflas(storiesTplFile, { NAME: name }); return { uiCode, schemaCode, componentTpl, schemaTpl, storiesTpl }; }