import * as plugins from './smarthbs.plugins.js'; /** * compiles a directory and outputs it */ export let compileDirectory = async ( originDirPathArg: string, destinationDirPathArg: string, dataFileNameArg: string ) => { const originDirPath = plugins.path.resolve(originDirPathArg); const destinationDirPath = plugins.path.resolve(destinationDirPathArg); const hbsFileArray = await plugins.smartFs.directory(originDirPath) .filter((entry) => entry.isFile && entry.name.endsWith('.hbs')) .list(); const dataFileString = await plugins.smartFs.file( plugins.path.join(originDirPath, dataFileNameArg) ).encoding('utf8').read() as string; const data = JSON.parse(dataFileString) as Record; for (const hbsFile of hbsFileArray) { const parsedPath = plugins.path.parse(hbsFile.path); const hbsFileString = await plugins.smartFs.file(hbsFile.path).encoding('utf8').read() as string; const template = plugins.handlebars.compile(hbsFileString); const output = template(data); console.log('hi ' + output + ' hi'); await plugins.smartFs.directory(destinationDirPath).create(); await plugins.smartFs.file( plugins.path.join(destinationDirPath, parsedPath.name + '.html') ).encoding('utf8').write(output); } };