diff --git a/lib/generate.js b/lib/generate.js index a608c74..8cfed72 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -52,6 +52,33 @@ function filterFiles (filters) { } } +/** + * Create a middleware for rename files. + * + * @param {Object} filters meta.js中filters对象 + * @return {Function} + */ +function renameTplFiles () { + return (files, metalsmith, done) => { + const fileNames = Object.keys(files) + const metalsmithMetadata = metalsmith.metadata() + + fileNames.forEach(file => { + if (file === 'src/app/template/index.tpl') { + const newFile = `src/app/template/${metalsmithMetadata.name}.tpl` + files[newFile] = files[file] + delete files[file] + } + if (file === 'src/web/template.tpl') { + const newFile = `src/web/${metalsmithMetadata.name}.tpl` + files[newFile] = files[file] + delete files[file] + } + }) + done() + } +} + /** * Create a middleware for render template files. * @@ -108,6 +135,7 @@ module.exports = (name, src, dest, done) => { metalsmith .use(askQuestions(opts.prompts)) .use(filterFiles(opts.filters)) + .use(renameTplFiles(opts.filters)) .use(renderTemplateFiles(opts.skipInterpolation)) metalsmith