diff --git a/apps/internal-tool/package.json b/apps/internal-tool/package.json index 41f51b147..98e4b49b4 100644 --- a/apps/internal-tool/package.json +++ b/apps/internal-tool/package.json @@ -4,7 +4,7 @@ "version": "2.8.80", "type": "module", "scripts": { - "dev": "pnpm spacetime:publish:local && next dev --turbopack --port ${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}41", + "dev": "node scripts/pre-dev.mjs && next dev --turbopack --port ${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}41", "build": "next build", "start": "next start --port ${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}41", "typecheck": "tsc --noEmit", diff --git a/apps/internal-tool/scripts/pre-dev.mjs b/apps/internal-tool/scripts/pre-dev.mjs new file mode 100644 index 000000000..f8de81e6b --- /dev/null +++ b/apps/internal-tool/scripts/pre-dev.mjs @@ -0,0 +1,23 @@ +#!/usr/bin/env node +// Runs before `next dev`. Publishes the SpacetimeDB module to the local server +// if the spacetime CLI is installed. Otherwise, warns and continues so the +// dev server still starts (useful in CI and for contributors who haven't +// installed the CLI yet). + +import { spawnSync } from "node:child_process"; + +const which = spawnSync(process.platform === "win32" ? "where" : "which", ["spacetime"], { + stdio: "ignore", +}); + +if (which.status !== 0) { + console.warn("\n[internal-tool] spacetime CLI not found, skipping publish."); + console.warn("[internal-tool] To install it: curl -sSf https://install.spacetimedb.com | sh\n"); + process.exit(0); +} + +const publish = spawnSync("pnpm", ["spacetime:publish:local"], { + stdio: "inherit", +}); + +process.exit(publish.status ?? 1);