UNPKG

gen-jhipster

Version:

VHipster - Spring Boot + Angular/React/Vue in one handy generator

26 lines (25 loc) 973 B
import { transform } from 'p-transform'; import TemplateFileFs from "./template-file-fs.js"; export const createMultiStepTransform = (templateData = {}) => { const templateFileFs = new TemplateFileFs({}); const templateFiles = []; const duplex = transform((file) => { if (!templateFileFs.isTemplate(file.path)) { throw new Error(`File ${file.path} is not supported`); } const templateFile = templateFileFs.add(file); if (templateFile.rootTemplate) { templateFiles.push(templateFile); } return undefined; }, async function () { for (const templateFile of templateFiles) { const file = templateFile.file; file.path = templateFile.basePath; file.contents = Buffer.from(templateFile.render(templateData).concat('\n')); this.push(templateFile.file); } }); duplex.templateFileFs = templateFileFs; return duplex; };