mami/build.js

51 lines
1.9 KiB
JavaScript
Raw Normal View History

2024-06-24 21:36:07 +00:00
const assproc = require('@railcomm/assproc');
const { join: pathJoin } = require('path');
2024-01-18 19:50:37 +00:00
const fs = require('fs');
2024-06-24 21:36:07 +00:00
const exec = require('util').promisify(require('child_process').exec);
2024-01-18 19:50:37 +00:00
(async () => {
2024-06-24 21:36:07 +00:00
const config = JSON.parse(fs.readFileSync(pathJoin(__dirname, 'config/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: 'es2020',
},
vars: {
html: {
title: config.title,
},
build: {
FUTAMI_DEBUG: isDebug,
FUTAMI_URL: config.common_url,
MAMI_URL: config.modern_url,
AMI_URL: config.compat_url,
GIT_HASH: (await exec('git log --pretty="%H" -n1 HEAD')).stdout,
},
},
2024-01-18 19:50:37 +00:00
};
2024-06-24 21:36:07 +00:00
const tasks = {
js: [
{ source: 'proto.js', target: '/assets', name: 'proto.{hash}.js', vars: { build: 'MAMI_PROTO_JS', html: ':source' } },
{ source: 'mami.js', target: '/assets', name: 'mami.{hash}.js', vars: { build: 'MAMI_MAIN_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: config.title, short_name: config.title } }
],
html: [
{ source: 'mami.html', target: '/', name: 'index.html', template: 'html' },
],
};
2024-02-11 01:42:39 +00:00
2024-06-24 21:36:07 +00:00
await assproc.process(env, tasks);
2024-01-18 19:50:37 +00:00
})();