import { codeFromAST, addDecl, addElementToVarDecl } from "./utils"; import cantinflas from "cantinflas"; export default function astTemplate({ uiAST, schemasAST, alias, componentTplFile, schemaTplFile, storiesTplFile, name, niceName, type }) { const astImport = addDecl({ type: "lazyImport", ast: uiAST, name, alias }); const astNamedExport = addDecl({ type: "namedExport", ast: astImport, name }); const astEXPORT = addElementToVarDecl( { ast: astNamedExport, name }, "templates" ); // SCHEMA const schemaImport = addDecl({ type: "import", ast: schemasAST, name }); const schemaNamedExport = addDecl({ type: "defaultExport", ast: schemaImport, name }); const uiCode = codeFromAST(astEXPORT); const schemaCode = codeFromAST(schemaNamedExport); const componentTpl = cantinflas(componentTplFile, { TEMPLATE_ALIAS: alias, NAME: name }); const schemaTpl = cantinflas(schemaTplFile, { DISPLAY_NAME: niceName, NAME: name, TEMPLATE_TYPE_LABEL: type.label, TEMPLATE_TYPE_VALUE: type.value || "", TEMPLATE_TYPE_MODE: type.mode || "" }); const storiesTpl = cantinflas(storiesTplFile, { NAME: name }); return { uiCode, schemaCode, componentTpl, schemaTpl, storiesTpl }; }