import * as esbuild from 'esbuild';

const srcDir = 'media_server/static';
const outDir = `${srcDir}/dist`;

const watch = process.argv.includes('--watch');

/** @type {esbuild.BuildOptions} */
const jsOpts = {
    entryPoints: [`${srcDir}/js/app.js`],
    bundle: true,
    format: 'iife',
    outfile: `${outDir}/app.bundle.js`,
    minify: true,
    sourcemap: true,
    target: ['es2020'],
    logLevel: 'info',
};

if (watch) {
    const jsCtx = await esbuild.context(jsOpts);
    await jsCtx.watch();
    console.log('Watching for changes...');
} else {
    await esbuild.build(jsOpts);
}
