now supports frontmatter for advanced file templating

This commit is contained in:
2017-05-27 23:52:58 +02:00
parent fa961f86b8
commit b9a346c5d7
8 changed files with 77 additions and 11 deletions

View File

@ -69,12 +69,22 @@ export class ScafTemplate {
async writeToDisk (destinationDirArg) {
let smartfileArrayToWrite = plugins.lodash.cloneDeep(this.templateSmartfileArray)
for (let smartfile of smartfileArrayToWrite) {
// render the template
let template = await plugins.smarthbs.getTemplateForString(
smartfile.contents.toString()
)
let renderedTemplateString = template(this.suppliedVariables)
smartfile.contents = Buffer.from(renderedTemplateString)
// handle frontmatter
let parsedTemplate = plugins.smartfm.parse(renderedTemplateString)
if (parsedTemplate.data.fileName) {
smartfile.updateFileName(parsedTemplate.data.fileName)
}
smartfile.contents = Buffer.from(parsedTemplate.content)
}
await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg)
}

View File

@ -2,6 +2,7 @@ import 'typings-global'
import * as lodash from 'lodash'
import * as path from 'path'
import * as smartfile from 'smartfile'
import * as smartfm from 'smartfm'
import * as smarthbs from 'smarthbs'
import * as smartinteract from 'smartinteract'
import * as smartq from 'smartq'
@ -11,6 +12,7 @@ export {
lodash,
path,
smartfile,
smartfm,
smarthbs,
smartinteract,
smartq,