Last active
June 27, 2022 19:12
-
-
Save Luna-Klatzer/4661ec5eaf6cdaa55e5614cfc7f90d4d to your computer and use it in GitHub Desktop.
Simple script for buidling dot.js template files (`.jst`) and generating the js template functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as dot from 'dot'; | |
import * as fs from "fs"; | |
import * as rimraf from 'rimraf'; | |
const source: string = `${__dirname }/templates`; | |
const destination: string = `${__dirname}/dot-build`; | |
// Generate destination files from source template files | |
(async () => { | |
// If the destination folder exists, remove it to ensure it does not contain old files | |
if (fs.existsSync(destination)){ | |
rimraf.sync(destination, {}); | |
} | |
// Create new empty destination directory | |
await fs.promises.mkdir(destination); | |
dot.process({ | |
destination: destination, | |
path: source, | |
}); | |
let templates = {}; | |
for (const file of fs.readdirSync(destination)) { | |
if (file.endsWith(".js")) { | |
const fileName = file.split('.')[0]; | |
templates[fileName] = await import(`${destination}/${file}`); | |
// Log file | |
console.log(`Loaded template '${fileName}'`); | |
} | |
} | |
return; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment