2019-12-04 03:51:28 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const { watch } = require('chokidar');
|
|
|
|
const { debounce } = require('lodash');
|
2020-02-08 23:26:57 +01:00
|
|
|
const minimist = require('minimist');
|
2020-11-12 21:09:43 +01:00
|
|
|
const templating = require('../templates');
|
2019-12-04 03:51:28 +01:00
|
|
|
|
2020-05-14 21:15:59 +02:00
|
|
|
/** @var {Object} argv */
|
2019-12-04 03:51:28 +01:00
|
|
|
const argv = minimist(process.argv);
|
|
|
|
|
|
|
|
function buildIndexHtml() {
|
2021-07-25 20:38:51 +02:00
|
|
|
const html = templating.compile();
|
2019-12-04 03:51:28 +01:00
|
|
|
|
2021-07-25 20:38:51 +02:00
|
|
|
fs.writeFileSync(path.resolve('index.html'), html);
|
2019-12-04 03:51:28 +01:00
|
|
|
console.log('compiled index.html');
|
|
|
|
}
|
|
|
|
|
|
|
|
const debouncedBuildIndexHtml = debounce(buildIndexHtml, 100, { leading: true, trailing: false });
|
|
|
|
|
|
|
|
function build() {
|
|
|
|
if (argv.watch) {
|
|
|
|
const templatesWatcher = watch('./templates/**/*');
|
2021-07-25 20:38:51 +02:00
|
|
|
templatesWatcher.on('all', () => debouncedBuildIndexHtml());
|
2019-12-04 03:51:28 +01:00
|
|
|
} else {
|
|
|
|
buildIndexHtml();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
build();
|