ami/build.js

49 lines
1.6 KiB
JavaScript

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 isDebug = !!process.env.AMI_DEBUG;
const title = process.env.AMI_TITLE ?? 'Flashii Chat';
const env = {
root: __dirname,
source: pathJoin(__dirname, 'src'),
public: pathJoin(__dirname, 'public'),
debug: isDebug,
swc: { es: 'es5' },
housekeep: [ pathJoin(__dirname, 'public', 'assets') ],
vars: {
html: { title },
build: {
DEBUG: isDebug,
TITLE: title,
FII_URL: process.env.AMI_FII_URL ?? '//flashii.net',
FUTAMI_URL: process.env.FUTAMI_URL ?? '//futami.flashii.net/common.json',
GIT_HASH: (await exec('git log --pretty="%H" -n1 HEAD')).stdout,
},
},
};
const tasks = {
js: [
{ source: 'ami.js', target: '/assets', name: 'ami.{hash}.js', vars: { html: ':source' } },
],
css: [
{ source: 'ami.css', target: '/assets', name: 'ami.{hash}.css', vars: { html: ':source' } },
],
html: [
{ source: 'ami.html', target: '/', name: 'index.html', template: 'html' },
],
};
if(process.argv.length > 2) {
const filter = process.argv.slice(2);
for(const name in tasks)
if(!filter.includes(name))
delete tasks[name];
}
await assproc.process(env, tasks);
})();