2020-09-13 19:28:38 +00:00
|
|
|
const fs = require('fs')
|
|
|
|
const Handlebars = require('handlebars')
|
|
|
|
|
|
|
|
module.exports = (defaults, templatesPath, destinationPath) => {
|
|
|
|
if (defaults.categories !== null) {
|
2020-11-27 12:45:16 +00:00
|
|
|
const categoryTemplate = fs.readFileSync(
|
|
|
|
`${templatesPath}/category.md.handlebars`,
|
|
|
|
'utf8'
|
|
|
|
)
|
2020-09-13 19:28:38 +00:00
|
|
|
const renderCategory = Handlebars.compile(categoryTemplate)
|
2020-11-27 12:45:16 +00:00
|
|
|
defaults.categories.forEach((category) => {
|
2020-09-13 19:28:38 +00:00
|
|
|
fs.mkdirSync(`${destinationPath}/${category.folder}`)
|
|
|
|
const categoryReadmeContent = renderCategory(category)
|
2020-11-27 12:45:16 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
`${destinationPath}/${category.folder}/readme.md`,
|
|
|
|
categoryReadmeContent
|
|
|
|
)
|
2020-09-13 19:28:38 +00:00
|
|
|
|
|
|
|
if (category.image !== undefined) {
|
|
|
|
fs.copyFileSync(
|
|
|
|
`../../images/${category.folder}/${category.image.filename}`,
|
|
|
|
`${destinationPath}/${category.folder}/${category.image.filename}`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|