stack/apps/internal-tool/scripts/spacetime-publish.mjs
Mantra 000634607a
fix(internal-tool): continue dev startup when spacetime publish fails (#1371)
## Summary
- pre-dev.mjs now warns and exits 0 when the local SpacetimeDB publish
fails, instead of aborting `next dev`
- Lets contributors without a running local SpacetimeDB server still
start the internal-tool dev server
- Updates the header comment to reflect the new behavior

## Test plan
- [ ] Run `pnpm dev` in `apps/internal-tool` with no SpacetimeDB server
running — dev server should still start, with a warning
- [ ] Run with SpacetimeDB server running and `spacetime` CLI installed
— publish still runs and dev proceeds
- [ ] Run without `spacetime` CLI installed — existing warn-and-continue
path still works

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Chores**
* Updated local publishing configuration to derive server settings from
environment variables for improved flexibility and easier customization.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-22 22:35:27 +00:00

60 lines
1.7 KiB
JavaScript

#!/usr/bin/env node
// Cross-platform SpacetimeDB publish that injects the token, publishes, and
// always restores the original file — even on failure.
import { spawnSync } from "node:child_process";
const target = process.argv[2]; // "local" or "prod"
/** HTTP API for 'spacetime publish' (matches docker/dependencies/docker.compose.yaml host port ...39). */
function localPublishServerUrl() {
if (process.env.STACK_SPACETIME_PUBLISH_URL) {
return process.env.STACK_SPACETIME_PUBLISH_URL;
}
const prefix = process.env.NEXT_PUBLIC_STACK_PORT_PREFIX ?? "81";
return `http://127.0.0.1:${prefix}39`;
}
const configs = {
local: [
"publish",
"stack-auth-llm",
"--server",
localPublishServerUrl(),
"-p",
"spacetimedb",
"--yes",
"--no-config",
"--delete-data=on-conflict",
],
prod: ["publish", "stack-auth-llm", "--server", "maincloud", "-p", "spacetimedb", "--yes", "--no-config"],
};
const args = configs[target];
if (!args) {
console.error("Usage: node scripts/spacetime-publish.mjs <local|prod>");
process.exit(1);
}
if (target === "prod" && !process.env.STACK_MCP_LOG_TOKEN) {
console.error("Error: STACK_MCP_LOG_TOKEN must be set for prod publish");
process.exit(1);
}
let exitCode = 1;
try {
const inject = spawnSync("node", ["scripts/spacetime-token.mjs", "inject"], { stdio: "inherit" });
if (inject.status !== 0) {
exitCode = inject.status ?? 1;
} else {
const publish = spawnSync("spacetime", args, { stdio: "inherit" });
exitCode = publish.status ?? 1;
}
} finally {
const restore = spawnSync("node", ["scripts/spacetime-token.mjs", "restore"], { stdio: "inherit" });
if (restore.status !== 0 && exitCode === 0) {
exitCode = restore.status ?? 1;
}
process.exitCode = exitCode;
}