in packages/create-element/src/base.ts [58:87]
renderTpl() {
const templatePath = path.join(this.installPath, 'node_modules', this.templatePkg, 'proj');
const setterName = this.addPrefix(this.answers.projectName);
const setterComponentName = pascal(setterName);
const renderData = {
...this.answers,
name: setterName,
componentName: setterComponentName,
version: '1.0.0',
nowDate: dayjs().format('YYYY-MM-DD'),
};
fs.ensureDirSync(this.copyPath);
if (!this.isDirEmpty(this.copyPath)) {
console.log(chalk.red('需要初始化的项目目录不为空,请清空后重试'));
return;
}
glob.sync('**', {
cwd: templatePath,
nodir: true,
dot: true,
ignore: ['node_modules/**'],
}).forEach((fileName) => {
const filePath = path.join(templatePath, fileName);
const fileTpl = fs.readFileSync(filePath, 'utf-8');
const fileContent = ejs.render(fileTpl, renderData);
const copyPath = path.join(this.copyPath, transformFileName(fileName));
fs.ensureFileSync(copyPath);
fs.writeFileSync(copyPath, fileContent);
});
}