ami/build.js

46 lines
1.4 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 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: 'es5',
2024-06-11 00:43:42 +00:00
},
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:51:52 +00:00
2024-06-11 00:43:42 +00:00
const tasks = {
2024-01-18 19:51:52 +00:00
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
};
2024-06-11 00:43:42 +00:00
await assproc.process(env, tasks);
2024-01-18 19:51:52 +00:00
})();