Files
dawnline/web/tsup.config.ts
T
Aemeath 34293fb8e5
Build packages / Version (push) Waiting to run
Dawnline 0.4.0
- Components tab replaces Updates: Dawnline, the AmneziaWG build for this
  firmware (Slava-Shchipunov 2.0 or 2Grey 3.1, Russian translation) and
  the system packages Dawnline adds, each checked, installed, reinstalled
  or rolled back in place, with What's new, versions and an activity log
- Automatic updates: daily check, install at a set time or right away,
  per component; AmneziaWG is left out by default and an automatic run
  never switches its build or generation
- Downloads verified against GitHub's sha256; mirrors are used only when
  GitHub is unreachable and the hash is known
- New installer: checks firmware, clock, space and DNS, lets you pick a
  release, shows the plan and asks first; --dry-run
- New uninstaller removes everything Dawnline added (cron, nft, firewall,
  routing, interfaces, packages it installed); --dry-run
- Works without AmneziaWG on the router: Overview, the setup wizard,
  Health and Components say what is missing and offer to install it
- Overview shows failed health checks as notices with their fix
- People list no longer reads the config from the browser: private keys
  stay on the router; personal links are fetched on demand
- Config changes are serialized under one lock, the nft table loads
  atomically and fails closed, and Dawnline never touches network
  sections it did not create
- The portal never opens system ports, keeps disabled devices disabled,
  rate-limits per address and counts days by the router's clock
- Settings and Diagnostics load their heavy parts in the background
- Release notes are written from the commits since the previous release
- Backend and admin UI split into small single-purpose modules
2026-10-16 02:14:15 +03:00

106 lines
3.8 KiB
TypeScript

import { defineConfig } from 'tsup';
import { transform, type Plugin } from 'esbuild';
import fs from 'node:fs';
import path from 'node:path';
const PKG = '../package/luci-app-dawnline';
const ADMIN_OUT = `${PKG}/htdocs/luci-static/resources/dawnline`;
// Outside the web root: the portal CGI serves them only with a valid code.
const PORTAL_OUT = `${PKG}/root/usr/share/dawnline/portal/assets`;
// LuCI evaluates a module's source as a function body whose parameters are
// the `'require x'` directives; it must `return` its class. tsup emits ESM,
// so the trailing `export { ... }` is rewritten into a baseclass.
function patchForLuci(file: string) {
const code = fs.readFileSync(file, 'utf8');
const patched = code.replace(/export\s*{([\s\S]*?)};?\s*$/, (_m, body: string) => {
const props = body
.split(',')
.map((s) => s.trim())
.filter(Boolean)
.map((s) => {
const [local, exported] = s.split(/\s+as\s+/);
return exported ? `${exported}: ${local}` : local;
});
return `return baseclass.extend({ ${props.join(', ')} });\n`;
});
if (patched === code) throw new Error(`LuCI patch failed: no export block in ${file}`);
fs.writeFileSync(file, patched);
}
/** Minify CSS with esbuild (the same engine that bundles the scripts). */
async function minifyCss(css: string): Promise<string> {
return (await transform(css, { loader: 'css', minify: true, legalComments: 'none' })).code.trim();
}
// The admin styles are plain .css files under src/admin/styles, imported as
// text and joined in styles/index.ts (rendered inside each view): each is
// minified here. They get a namespace (and a path not ending in .css) of
// their own, so tsup's CSS handling, which would emit a stylesheet, never sees them.
const adminCss: Plugin = {
name: 'admin-css-text',
setup(build) {
build.onResolve({ filter: /\.css$/ }, (args) =>
/admin[\\/]styles$/.test(args.resolveDir)
? { path: `${path.join(args.resolveDir, args.path)}#text`, namespace: 'dl-css' }
: undefined,
);
build.onLoad({ filter: /.*/, namespace: 'dl-css' }, async (args) => ({
contents: await minifyCss(fs.readFileSync(args.path.replace(/#text$/, ''), 'utf8')),
loader: 'text',
}));
},
};
export default defineConfig([
{
entry: { app: 'src/admin/main.ts' },
format: ['esm'],
outDir: ADMIN_OUT,
outExtension: () => ({ js: '.js' }),
target: 'es2020',
clean: false,
sourcemap: false,
// Identifiers only: LuCI's require directives in the banner must stay as written.
minify: true,
noExternal: ['qrcode-generator'],
esbuildPlugins: [adminCss],
banner: {
js: [
'// Generated from dawnline/web — do not edit by hand.',
"'use strict';",
"'require baseclass';",
"'require dom';",
"'require poll';",
"'require rpc';",
"'require ui';",
].join('\n'),
},
esbuildOptions(o) {
o.legalComments = 'none';
o.charset = 'utf8';
},
onSuccess: async () => patchForLuci(path.join(ADMIN_OUT, 'app.js')),
},
{
entry: { portal: 'src/portal/main.ts' },
format: ['iife'],
outDir: PORTAL_OUT,
outExtension: () => ({ js: '.js' }),
target: 'es2019',
clean: false,
sourcemap: false,
minify: true,
noExternal: ['qrcode-generator'],
esbuildOptions(o) {
o.legalComments = 'none';
o.charset = 'utf8';
},
onSuccess: async () => {
fs.writeFileSync(path.join(PORTAL_OUT, 'portal.css'), (await minifyCss(fs.readFileSync('src/portal/portal.css', 'utf8'))) + '\n');
fs.copyFileSync('src/portal/icon.svg', path.join(PORTAL_OUT, 'icon.svg'));
for (const f of fs.readdirSync('src/portal/fonts')) fs.copyFileSync(path.join('src/portal/fonts', f), path.join(PORTAL_OUT, f));
},
},
]);