links/compile.js
2023-01-03 14:47:27 -06:00

39 lines
1.2 KiB
JavaScript

/* global process */
const { parse } = require('@ltd/j-toml');
const { render } = require('mustache');
const { readFile, writeFile } = require('node:fs/promises');
const { resolve } = require('node:path');
const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec);
async function compile() {
const { stdout, stderr } = await exec('git rev-parse --short @');
const confPath = resolve('./config.toml');
const confToml = await readFile(confPath, { encoding: 'utf8' });
const config = parse(confToml);
config.version = stdout.trim();
config.slug = function () {
return this.text ? this.text.toLowerCase() : this.icon;
};
config.text = function () {
const string = this.icon;
return string.charAt(0).toUpperCase() + string.slice(1);
};
if (process.argv[2] === 'dev') {
config.umami.website_id = config.umami.dev_website_id;
}
const tempPath = resolve('./index.html');
const template = await readFile(tempPath, { encoding: 'utf8' });
const out = render(template, config);
const outPath = resolve('./build/index.html');
await writeFile(outPath, out);
}
compile();