Skip to content

Commit

Permalink
🗃️feat: support rename tpl Files
Browse files Browse the repository at this point in the history
  • Loading branch information
LHammer committed May 10, 2018
1 parent 1ed97cf commit 8f311bf
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8f311bf

Please sign in to comment.