mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-13 10:14:20 +00:00
* feat: rebuild plugin pages with host rendering and native settings * fix(plugins): contain host-view errors, isolate editing, and migrate fixtures * fix(plugins): migrate remaining permission fixture hosts
17 lines
1.2 KiB
JavaScript
17 lines
1.2 KiB
JavaScript
import { build } from 'esbuild';
|
|
import { mkdir, readFile, rm, copyFile, cp, stat } from 'node:fs/promises';
|
|
import { fileURLToPath } from 'node:url';
|
|
import path from 'node:path';
|
|
export async function buildHostViewExample(directory) {
|
|
const root = fileURLToPath(directory);
|
|
await build({ entryPoints: [path.join(root, 'host.js')], outfile: path.join(root, 'dist/host.js'), bundle: true, platform: 'browser', format: 'esm', loader: { '.html': 'text', '.css': 'text' }, minify: true });
|
|
const staging = path.join(root, '.package');
|
|
await rm(staging, { recursive: true, force: true });
|
|
await mkdir(path.join(staging, 'dist'), { recursive: true });
|
|
for (const file of ['netcatty.plugin.json', 'dist/host.js']) await copyFile(path.join(root, file), path.join(staging, file));
|
|
if (await stat(path.join(root, 'assets')).then((info) => info.isDirectory(), () => false)) await cp(path.join(root, 'assets'), path.join(staging, 'assets'), { recursive: true });
|
|
// Parse at build time so a forgotten view declaration fails before packaging.
|
|
const manifest = JSON.parse(await readFile(path.join(root, 'netcatty.plugin.json'), 'utf8'));
|
|
if (!manifest.contributes?.views?.length) throw new Error('Example has no declared view');
|
|
}
|