build: add spacetime local dev scripts

This commit is contained in:
2026-04-21 01:58:46 +08:00
parent c9850c8caf
commit a1a02eee7d
7 changed files with 138 additions and 6 deletions

View File

@@ -0,0 +1,67 @@
[CmdletBinding()]
param(
[Alias("h")]
[switch]$Help,
[string]$ListenHost = "127.0.0.1",
[int]$Port = 3001,
[string]$RootDir = ""
)
$ErrorActionPreference = "Stop"
function Write-Usage {
@(
'Usage:'
' ./server-rs/scripts/spacetime-dev.ps1'
' ./server-rs/scripts/spacetime-dev.ps1 -ListenHost 127.0.0.1 -Port 3101'
''
'Notes:'
' 1. Start local standalone SpacetimeDB for the Genarrative Rust backend'
' 2. Store local SpacetimeDB state in server-rs/.spacetimedb/local by default'
' 3. Current stage only boots the standalone server and does not publish a module yet'
) -join [Environment]::NewLine
}
if ($Help) {
Write-Usage
exit 0
}
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$serverRsDir = Split-Path -Parent $scriptDir
if ([string]::IsNullOrWhiteSpace($RootDir)) {
$RootDir = Join-Path $serverRsDir ".spacetimedb\local"
}
if (-not (Test-Path (Join-Path $serverRsDir "apps\spacetime-module\README.md"))) {
throw "Missing server-rs/apps/spacetime-module/README.md, cannot start SpacetimeDB local dev script."
}
$spacetimeCommand = Get-Command spacetime -ErrorAction SilentlyContinue
if ($null -eq $spacetimeCommand) {
throw @(
"Missing 'spacetime' CLI.",
"Install guide: https://spacetimedb.com/install",
"Windows PowerShell: iwr https://windows.spacetimedb.com -useb | iex"
) -join " "
}
New-Item -ItemType Directory -Force -Path $RootDir | Out-Null
$listenAddress = "$ListenHost`:$Port"
Write-Host "[server-rs:spacetime-dev] working dir: $serverRsDir"
Write-Host "[server-rs:spacetime-dev] root dir: $RootDir"
Write-Host "[server-rs:spacetime-dev] listen addr: $listenAddress"
Write-Host "[server-rs:spacetime-dev] mode: standalone"
Write-Host "[server-rs:spacetime-dev] note: module publish is deferred until apps/spacetime-module scaffold lands"
Push-Location $serverRsDir
try {
& $spacetimeCommand.Source --root-dir $RootDir start --edition standalone --listen-addr $listenAddress
}
finally {
Pop-Location
}