【发布时间】:2020-04-28 06:33:05
【问题描述】:
我尝试复制和替换多个文件中的一些变量。为此,我使用esj 模块替换我的变量。
但我不知道 ejs 模块是否适合我的情况。我只想复制“模板”初始文件并替换文件中的变量。
我使用 NodeJS 的例子:
const symfonyPluginPath = path.join(
__dirname,
'../plugins/symfony/template'
);
const testPath = path.join(__dirname, '../plugins/test');
shell.rm('-rf', testPath);
shell.mkdir(testPath);
shell.cp('-r', `${symfonyPluginPath}/*`, testPath);
shell.cp('-r', `${symfonyPluginPath}/.*`, testPath);
shell.cd(testPath);
// @ts-ignore
fs.readdir(testPath, (error, files) => {
files.forEach((file) => {
const compiled = ejs.compile(
fs.readFileSync(`${testPath}/${file}`, 'utf8')
);
const test = compiled({ appName: 'test' });
console.log(test);
});
});
此代码仅适用于 1 个文件,但在 forEach 我有一个错误 EISDIR: illegal operation on a directory, read。
我不知道我的方法是否良好,以及 ejs 是否是正确的模块。
谁能帮帮我?
感谢社区!
【问题讨论】:
标签: node.js command-line-interface ejs