import { transform } from 'p-transform';
import TemplateFileFs from './template-file-fs.mjs';
export const createMultiStepTransform = () => {
    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().concat('\n'));
            this.push(templateFile.file);
        }
    });
    duplex.templateFileFs = templateFileFs;
    return duplex;
};
