64 lines
2.1 KiB
JavaScript
64 lines
2.1 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 title = process.env.MAMI_TITLE ?? 'Flashii Chat';
|
|
const isDebug = !!process.env.MAMI_DEBUG;
|
|
|
|
const env = {
|
|
root: __dirname,
|
|
source: pathJoin(__dirname, 'src'),
|
|
public: pathJoin(__dirname, 'public'),
|
|
debug: isDebug,
|
|
swc: { es: 'es2021' },
|
|
housekeep: [ pathJoin(__dirname, 'public', 'assets') ],
|
|
vars: {
|
|
html: { title },
|
|
build: {
|
|
DEBUG: isDebug,
|
|
TITLE: title,
|
|
FII_URL: process.env.MAMI_FII_URL ?? '//flashii.net',
|
|
FUTAMI_URL: process.env.FUTAMI_URL ?? '//futami.flashii.net/common.json',
|
|
AMI_URL: process.env.AMI_URL ?? '//sockchat.flashii.net',
|
|
GIT_HASH: (await exec('git log --pretty="%H" -n1 HEAD')).stdout,
|
|
},
|
|
},
|
|
};
|
|
|
|
const tasks = {
|
|
js: [
|
|
{ source: 'mami.js', target: '/assets', name: 'mami.{hash}.js', vars: { build: 'MAMI_JS', html: ':source' } },
|
|
{ source: 'init.js', target: '/assets', name: 'init.{hash}.js', es: 'es5', vars: { html: ':source' } },
|
|
],
|
|
css: [
|
|
{ source: 'mami.css', target: '/assets', name: 'mami.{hash}.css', vars: { html: ':source' } },
|
|
],
|
|
webmanifest: [
|
|
{
|
|
source: 'mami.webmanifest',
|
|
target: '/',
|
|
name: 'mami.webmanifest',
|
|
icons: '/icons',
|
|
vars: { html: ':source' },
|
|
body: {
|
|
name: title,
|
|
short_name: title,
|
|
},
|
|
},
|
|
],
|
|
html: [
|
|
{ source: 'mami.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);
|
|
})();
|