jatg
Version:
Just Another Template Generator
17 lines • 996 B
JavaScript
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { replaceVariables } from './replaceVariables.js';
import { saveFile } from './listAllFiles.js';
export async function processTemplateFile(template, variables, inputPath, baseOutputPath, relativeOutputPath, overwrite, ora) {
if (relativeOutputPath.toLowerCase().endsWith('.template'))
relativeOutputPath = relativeOutputPath.substring(0, relativeOutputPath.length - '.template'.length);
relativeOutputPath = replaceVariables(relativeOutputPath, template.variables, variables, 'outputPath');
ora?.start(relativeOutputPath);
let contents = await readFile(inputPath, 'utf8');
contents = replaceVariables(contents, template.variables, variables, inputPath);
const outputPath = join(baseOutputPath, relativeOutputPath);
await saveFile(outputPath, contents, overwrite);
ora?.succeed(relativeOutputPath);
return outputPath;
}
//# sourceMappingURL=processTemplateFile.js.map