2018-08-27 21:04:15 +00:00
|
|
|
import * as plugins from './smarthbs.plugins';
|
2017-03-19 16:14:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* compiles a directory and outputs it
|
|
|
|
*/
|
|
|
|
export let compileDirectory = async (
|
|
|
|
originDirPathArg: string,
|
|
|
|
destinationDirPathArg: string,
|
|
|
|
dataFileNameArg: string
|
|
|
|
) => {
|
2018-08-27 21:04:15 +00:00
|
|
|
let hbsFilePathArray = plugins.smartfile.fs.listFilesSync(originDirPathArg, /.hbs/);
|
|
|
|
let data = plugins.smartfile.fs.toObjectSync(
|
|
|
|
plugins.path.join(originDirPathArg, dataFileNameArg)
|
|
|
|
);
|
2017-03-19 16:14:28 +00:00
|
|
|
for (let hbsFilePath of hbsFilePathArray) {
|
2018-08-27 21:04:15 +00:00
|
|
|
let parsedPath = plugins.path.parse(hbsFilePath);
|
|
|
|
let hbsFileString = plugins.smartfile.fs.toStringSync(
|
|
|
|
plugins.path.join(originDirPathArg, hbsFilePath)
|
|
|
|
);
|
|
|
|
let template = plugins.handlebars.compile(hbsFileString);
|
|
|
|
let output = template(data);
|
|
|
|
console.log('hi ' + output + ' hi');
|
|
|
|
await plugins.smartfile.fs.ensureDir(destinationDirPathArg);
|
|
|
|
plugins.smartfile.memory.toFsSync(
|
|
|
|
output,
|
|
|
|
plugins.path.join(destinationDirPathArg, parsedPath.name + '.html')
|
|
|
|
);
|
2017-03-19 16:14:28 +00:00
|
|
|
}
|
2018-08-27 21:04:15 +00:00
|
|
|
};
|