ami/build.js

50 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-06-11 00:43:42 +00:00
const assproc = require('@railcomm/assproc');
const { join: pathJoin } = require('path');
2024-01-18 19:51:52 +00:00
const fs = require('fs');
2024-06-11 00:43:42 +00:00
const exec = require('util').promisify(require('child_process').exec);
2024-01-18 19:51:52 +00:00
2024-06-11 00:43:42 +00:00
(async () => {
const isDebug = !!process.env.AMI_DEBUG;
2025-04-21 00:27:49 +00:00
const title = process.env.AMI_TITLE ?? 'Flashii Chat';
2024-06-11 00:43:42 +00:00
const env = {
root: __dirname,
source: pathJoin(__dirname, 'src'),
public: pathJoin(__dirname, 'public'),
debug: isDebug,
swc: { es: 'es5' },
housekeep: [ pathJoin(__dirname, 'public', 'assets') ],
2024-06-11 00:43:42 +00:00
vars: {
2025-04-21 00:27:49 +00:00
html: { title },
2024-06-11 00:43:42 +00:00
build: {
2025-04-21 00:27:49 +00:00
DEBUG: isDebug,
TITLE: title,
FII_URL: process.env.AMI_FII_URL ?? '//flashii.net',
FUTAMI_URL: process.env.FUTAMI_URL ?? '//futami.flashii.net/common.json',
2024-06-11 00:43:42 +00:00
GIT_HASH: (await exec('git log --pretty="%H" -n1 HEAD')).stdout,
},
},
};
2024-01-18 19:51:52 +00:00
2024-06-11 00:43:42 +00:00
const tasks = {
js: [
2024-06-11 00:43:42 +00:00
{ 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' },
],
2024-01-18 19:51:52 +00:00
};
if(process.argv.length > 2) {
const filter = process.argv.slice(2);
for(const name in tasks)
if(!filter.includes(name))
delete tasks[name];
}
2024-06-11 00:43:42 +00:00
await assproc.process(env, tasks);
2024-01-18 19:51:52 +00:00
})();