30 lines
752 B
JavaScript
30 lines
752 B
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const { watch } = require('chokidar');
|
|
const { debounce } = require('lodash');
|
|
const minimist = require('minimist');
|
|
const templating = require('../templates');
|
|
|
|
/** @var {Object} argv */
|
|
const argv = minimist(process.argv);
|
|
|
|
function buildIndexHtml() {
|
|
const html = templating.compile();
|
|
|
|
fs.writeFileSync(path.resolve('index.html'), html);
|
|
console.log('compiled index.html');
|
|
}
|
|
|
|
const debouncedBuildIndexHtml = debounce(buildIndexHtml, 100, { leading: true, trailing: false });
|
|
|
|
function build() {
|
|
if (argv.watch) {
|
|
const templatesWatcher = watch('./templates/**/*');
|
|
templatesWatcher.on('all', () => debouncedBuildIndexHtml());
|
|
} else {
|
|
buildIndexHtml();
|
|
}
|
|
}
|
|
|
|
build();
|