added getTemplateForFile

This commit is contained in:
2017-02-26 02:08:25 +01:00
parent 25c959d12d
commit a0e8deca39
4 changed files with 550 additions and 6 deletions

View File

@@ -4,6 +4,9 @@ import * as smartfile from 'smartfile'
import * as path from 'path'
export type TTemplateStringType = 'filePath' | 'code'
/**
* registers a directory of partials to make them available within handlebars compilation
*/
export let registerPartialDir = (dirPathArg: string) => {
smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then(hbsFileArrayArg => {
for (let hbsFilePath of hbsFileArrayArg) {
@@ -18,7 +21,10 @@ export let registerPartialDir = (dirPathArg: string) => {
})
}
export let compileDirectory = (
/**
* compiles a directory and outputs it
*/
export let compileDirectory = async (
originDirPathArg: string,
destinationDirPathArg: string,
dataFileNameArg: string
@@ -33,4 +39,12 @@ export let compileDirectory = (
console.log('hi ' + output + ' hi')
smartfile.memory.toFsSync(output, path.join(destinationDirPathArg, parsedPath.name + '.html'))
}
}
}
/**
* get a template for a file on disk
*/
export let getTemplateForFile = async (filePathArg: string) => {
let filePathAbsolute = path.resolve(filePathArg)
return handlebars.compile(smartfile.fs.toStringSync(filePathAbsolute))
}