jatg
Version:
Just Another Template Generator
45 lines • 1.5 kB
JavaScript
import { resolve } from 'node:path';
import prompts from 'prompts';
import { convertFileIntoTemplate } from '../utils/convertFileIntoTemplate.js';
import { JatgError } from '../models/jatg-error.js';
export async function convertTemplate(variables, outputPath, basePath, overwrite, spinner) {
if (variables.length === 0) {
return;
}
const { sourceTemplatePath } = await prompts([
{
name: 'sourceTemplatePath',
type: 'text',
message: 'What is the path where the files that will be converted are?',
},
], {
onCancel: () => {
throw new JatgError('Operation canceled');
}
});
if (!sourceTemplatePath) {
return;
}
const variableReplacements = [];
for (const item of variables) {
const { needle } = await prompts([
{
name: 'needle',
type: 'text',
message: 'What string will be replaced to %' + item.variable + '%?',
initial: item.variable,
}
], {
onCancel: () => {
throw new JatgError('Operation canceled');
}
});
variableReplacements.push({
...item,
needle,
});
}
console.log();
await convertFileIntoTemplate(resolve(basePath, sourceTemplatePath), resolve(basePath, outputPath), variableReplacements, overwrite, spinner);
}
//# sourceMappingURL=convertTemplate.js.map