links/compile.js

31 lines
971 B
JavaScript
Raw Normal View History

2022-12-21 15:57:06 -06:00
const { parse } = require('@ltd/j-toml');
const { render } = require('mustache');
const { readFile, writeFile } = require('node:fs/promises');
const { resolve } = require('node:path');
2023-01-01 18:59:56 -06:00
const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec);
2022-12-21 15:57:06 -06:00
async function compile() {
2023-01-01 18:59:56 -06:00
const { stdout, stderr } = await exec('git rev-parse --short @');
2022-12-21 15:57:06 -06:00
const confPath = resolve('./config.toml');
const confToml = await readFile(confPath, { encoding: 'utf8' });
const config = parse(confToml);
2023-01-01 18:59:56 -06:00
config.version = stdout.trim();
2023-01-01 16:46:05 -06:00
config.text = function () {
const string = this.icon;
return string.charAt(0).toUpperCase() + string.slice(1);
};
2022-12-21 15:57:06 -06:00
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();