// ************************************************************************* // * (C)opyright 2026 by Ruben Carlo Benante * // * * // * This program is free software; you can redistribute it and/or modify * // * it under the terms of the GNU General Public License as published by * // * the Free Software Foundation, either version 3 of the License, or * // * (at your option) any later version. * // * * // * This program is distributed in the hope that it will be useful, * // * but WITHOUT ANY WARRANTY; without even the implied warranty of * // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * // * GNU General Public License for more details. * // * * // * You should have received a copy of the GNU General Public License * // * along with this program. If not, see http://www.gnu.org/licenses/. * // * * // * Contact author at: * // * Ruben Carlo Benante * // * rcb@beco.cc * // ************************************************************************* import esbuild from 'esbuild'; import process from 'process'; import { cp, mkdir, readdir } from 'node:fs/promises'; const banner = `/* * logsdu - fills and submits a three-field academic portal login. * Copyright (C) 2026 Ruben Carlo Benante (Dr. Beco) * Licensed under the GNU General Public License v3.0 or later. * See https://www.gnu.org/licenses/ and the LICENSE file. * * THIS IS A GENERATED/BUNDLED FILE BY ESBUILD. * To view the source, visit the repository of this extension. */ `; const prod = process.argv[2] === 'production'; const outdir = 'build'; // Everything that is not TypeScript is copied verbatim into build/, so that // the directory can be handed straight to about:debugging. async function copyStatic() { await mkdir(outdir, { recursive: true }); for (const name of await readdir('src')) { if (name.endsWith('.json') || name.endsWith('.html') || name.endsWith('.css')) { await cp(`src/${name}`, `${outdir}/${name}`); } } await cp('icons', `${outdir}/icons`, { recursive: true }); } await copyStatic(); // In watch mode the static files must follow every rebuild, otherwise editing // manifest.json or a .html file silently changes nothing in build/. const staticPlugin = { name: 'copy-static', setup(build) { build.onEnd(() => copyStatic()); }, }; const context = await esbuild.context({ banner: { js: banner, }, plugins: [staticPlugin], // Four independent entry points: no shared runtime, no imports at load // time. Content scripts and page-world scripts cannot be ES modules, so // every bundle has to stand alone. entryPoints: [ 'src/content.ts', 'src/injected.ts', 'src/options.ts', 'src/popup.ts', ], bundle: true, format: 'iife', target: 'es2021', logLevel: 'info', sourcemap: prod ? false : 'inline', treeShaking: true, outdir, minify: prod, }); if (prod) { await context.rebuild(); process.exit(0); } else { await context.watch(); }