added getTemplateForFile
This commit is contained in:
18
ts/index.ts
18
ts/index.ts
@@ -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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user