ami/build.js
2024-06-11 00:43:42 +00:00

45 lines
1.4 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 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,
},
},
};
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' },
],
};
await assproc.process(env, tasks);
})();