#!/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 = ` NomiFun — dev placeholder NomiFun dev placeholder — run bun run build:ui for the real bundle. `; 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);