UNPKG

@gent-js/gent

Version:

template-based data generator.

27 lines (26 loc) 1.41 kB
import * as nodePath from "node:path"; import { buildCommandDocumentFragments } from "./commandDocument/index.js"; import { parseAndEmbedCommandExpression } from "./commandTemplate/index.js"; import { debugFileWriter } from "./debugFileWriter.js"; import { parseTemplate } from "./template/index.js"; import { isStringOnlyTemplateFragments } from "./template/utils.js"; export function buildDocumentFromTextTemplate(templateString, commandManager, documentOptions) { const templateFragments = parseTemplate(templateString); const fileName = nodePath.basename(documentOptions.path); if (fileName !== undefined) { debugFileWriter.writeFile(`${fileName}.parsed-template.json`, JSON.stringify(templateFragments, undefined, 2)); } const isStringOnly = isStringOnlyTemplateFragments(templateFragments); // output original string if (isStringOnly) { if (fileName !== undefined) { debugFileWriter.writeFile(`${fileName}.parsed-expression.json`, templateString); } return templateString; } const parsedTemplateFragments = parseAndEmbedCommandExpression(templateFragments); if (fileName !== undefined) { debugFileWriter.writeFile(`${fileName}.parsed-expression.json`, JSON.stringify(parsedTemplateFragments, undefined, 2)); } return buildCommandDocumentFragments(parsedTemplateFragments, commandManager, documentOptions); }