ip.flash.moe/build.js

43 lines
1.4 KiB
JavaScript
Raw Normal View History

const assproc = require('@railcomm/assproc');
const { join: pathJoin } = require('path');
const fs = require('fs');
const exec = require('util').promisify(require('child_process').exec);
(async () => {
const config = JSON.parse(fs.readFileSync(pathJoin(__dirname, 'config.json')));
const isDebug = fs.existsSync(pathJoin(__dirname, '.debug'));
const env = {
root: __dirname,
source: pathJoin(__dirname, 'src'),
public: pathJoin(__dirname, 'public'),
debug: isDebug,
swc: {
es: 'es5',
},
vars: {
html: {}, // BUG: if this isn't definited prior, assproc will fail
build: {
DEBUG: isDebug,
IPV4_LOOKUP: config.ipv4_lookup,
IPV6_LOOKUP: config.ipv6_lookup,
GIT_HASH: (await exec('git log --pretty="%H" -n1 HEAD')).stdout.trim(),
},
},
};
const tasks = {
js: [
{ source: 'ipaddr.js', target: '/assets', name: 'ipaddr.{hash}.js', vars: { html: ':source' } },
],
css: [
{ source: 'ipaddr.css', target: '/assets', name: 'ipaddr.{hash}.css', vars: { html: ':source' } },
],
html: [
{ source: 'index.html', target: '/', name: 'index.html', template: 'html' },
],
};
await assproc.process(env, tasks);
})();