const assproc = require('@railcomm/assproc');
const { join: pathJoin } = require('path');
const fs = require('fs');

(async () => {
    const isDebug = fs.existsSync(pathJoin(__dirname, '.debug'));

    const env = {
        root: __dirname,
        source: pathJoin(__dirname, 'assets'),
        public: pathJoin(__dirname, 'public'),
        debug: isDebug,
        swc: {
            es: 'es2021',
            jsx: '$element',
            jsxf: '$fragment',
        },
    };

    const tasks = {
        js: [
            { source: 'makai.js', target: '/assets', name: 'makai.{hash}.js', },
        ],
        css: [
            { source: 'errors.css', target: '/', name: 'errors.css', },
            { source: 'makai.css', target: '/assets', name: 'makai.{hash}.css', },
        ],
        twig: [
            { source: 'errors/401', target: '/', name: 'error-401.html', },
            { source: 'errors/403', target: '/', name: 'error-403.html', },
            { source: 'errors/404', target: '/', name: 'error-404.html', },
            { source: 'errors/500', target: '/', name: 'error-500.html', },
            { source: 'errors/503', target: '/', name: 'error-503.html', },
        ],
    };

    const files = await assproc.process(env, tasks);

    fs.writeFileSync(pathJoin(__dirname, 'assets/current.json'), JSON.stringify(files));
})();