Files
freedak f7a720204a Update: 将子项目从 submodule 转为完整内容
- 移除 GovAI, nomifun-tauri, 算力盒子 的 submodule 引用
- 添加所有子项目的完整源代码
- 保留原始 .git 为 .git.bak 备份
2026-07-04 19:20:46 +08:00

71 lines
2.8 KiB
JavaScript

#!/usr/bin/env bun
/**
* ensure-ui-dist — dev preflight that guarantees ui/dist exists.
*
* Why this exists:
* tauri.conf.json declares `bundle.resources: ["../../ui/dist"]`. tauri-build
* resolves & VALIDATES every resource path at compile time — even for
* `tauri dev`, which otherwise serves the UI live from the Vite dev server
* (devUrl :5173) and never reads ui/dist at all. So on a fresh clone (where
* ui/dist has never been built) `bun run dev` dies in the build script with:
* resource path `..\..\ui\dist` doesn't exist
* The fix used to be a hidden manual step: run `bun run build:ui` once before
* the first `bun run dev`. This script removes that footgun.
*
* What it does:
* If ui/dist is missing (or empty), create it with a tiny placeholder
* index.html so the resource path resolves. We DON'T do a real `vite build`
* here: in dev the page comes from Vite, so the contents are irrelevant — only
* the path's existence matters. A real production build still happens via
* tauri's beforeBuildCommand (`bun run build:ui`), which overwrites this
* placeholder. ui/dist is gitignored, so this is a local, regenerable artifact.
*
* Invariants: idempotent (no-op when a populated ui/dist already exists), cross-
* platform (node:fs only, no shell), and never fatal to the dev chain.
*/
import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
const DIST = join(ROOT, 'ui', 'dist');
const TAG = '[ensure-ui-dist]';
const log = (msg) => console.log(`${TAG} ${msg}`);
/** True when DIST exists and has at least one entry. */
function populated() {
try {
return existsSync(DIST) && readdirSync(DIST).length > 0;
} catch {
return false;
}
}
const PLACEHOLDER = `<!doctype html>
<meta charset="utf-8">
<title>NomiFun — dev placeholder</title>
<!--
Auto-generated by scripts/ensure-ui-dist.mjs so tauri-build's resource-path
validation passes during \`tauri dev\`. In dev the real UI is served by Vite
(http://localhost:5173); this file is never loaded. \`bun run build:ui\`
(and \`bun run build\`) overwrite ui/dist with the real production bundle.
-->
<body>NomiFun dev placeholder — run <code>bun run build:ui</code> for the real bundle.</body>
`;
try {
if (populated()) {
log('ui/dist present — ok');
} else {
mkdirSync(DIST, { recursive: true });
writeFileSync(join(DIST, 'index.html'), PLACEHOLDER);
log('ui/dist was missing — created placeholder (real bundle comes from `bun run build:ui`)');
}
} catch (e) {
// Never block the dev chain; surface the reason so a real failure is visible.
log(`WARN: could not ensure ui/dist (${e.message}) — continuing`);
}
process.exit(0);