1
This commit is contained in:
@@ -9,7 +9,7 @@ param(
|
||||
[string]$SpacetimeHost = "127.0.0.1",
|
||||
[int]$SpacetimePort = 3101,
|
||||
[string]$SpacetimeRootDir = "",
|
||||
[string]$Database = "genarrative-dev",
|
||||
[string]$Database = "",
|
||||
[string]$Log = "info,tower_http=info",
|
||||
[int]$SpacetimeStartupTimeoutSeconds = 60,
|
||||
[switch]$SkipSpacetime,
|
||||
@@ -65,6 +65,28 @@ function Resolve-ClientHost {
|
||||
return $HostName
|
||||
}
|
||||
|
||||
function Read-LocalSpacetimeDatabase {
|
||||
param([string]$RepoRoot)
|
||||
|
||||
$localConfigPath = Join-Path $RepoRoot "spacetime.local.json"
|
||||
if (-not (Test-Path $localConfigPath)) {
|
||||
return ""
|
||||
}
|
||||
|
||||
try {
|
||||
$localConfig = Get-Content -Path $localConfigPath -Encoding UTF8 -Raw | ConvertFrom-Json
|
||||
$database = [string]$localConfig.database
|
||||
if (-not [string]::IsNullOrWhiteSpace($database)) {
|
||||
return $database.Trim()
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Host "[dev:rust] ignore invalid spacetime.local.json: $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
function Start-StackProcess {
|
||||
param(
|
||||
[string]$Name,
|
||||
@@ -165,6 +187,14 @@ if ([string]::IsNullOrWhiteSpace($SpacetimeRootDir)) {
|
||||
$SpacetimeRootDir = Join-Path $serverRsDir ".spacetimedb\local"
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Database)) {
|
||||
$Database = Read-LocalSpacetimeDatabase -RepoRoot $repoRoot
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Database)) {
|
||||
$Database = "genarrative-dev"
|
||||
}
|
||||
|
||||
if (-not (Test-Path $manifestPath)) {
|
||||
throw "Missing server-rs/Cargo.toml, cannot start Rust local stack."
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ WEB_PORT="3000"
|
||||
SPACETIME_HOST="127.0.0.1"
|
||||
SPACETIME_PORT="3101"
|
||||
SPACETIME_ROOT_DIR="${SERVER_RS_DIR}/.spacetimedb/local"
|
||||
DATABASE="genarrative-dev"
|
||||
DATABASE=""
|
||||
API_LOG="info,tower_http=info"
|
||||
SPACETIME_TIMEOUT_SECONDS="60"
|
||||
SKIP_SPACETIME=0
|
||||
@@ -108,6 +108,27 @@ CLEAR_DATABASE=0
|
||||
PIDS=()
|
||||
NAMES=()
|
||||
|
||||
read_local_spacetime_database() {
|
||||
local config_path="${REPO_ROOT}/spacetime.local.json"
|
||||
|
||||
if [[ ! -f "${config_path}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
node -e '
|
||||
const fs = require("fs");
|
||||
const path = process.argv[1];
|
||||
try {
|
||||
const value = JSON.parse(fs.readFileSync(path, "utf8")).database;
|
||||
if (typeof value === "string" && value.trim()) {
|
||||
process.stdout.write(value.trim());
|
||||
}
|
||||
} catch (error) {
|
||||
process.stderr.write(`[dev:rust] ignore invalid spacetime.local.json: ${error.message}\n`);
|
||||
}
|
||||
' "${config_path}"
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
@@ -174,6 +195,14 @@ while [[ $# -gt 0 ]]; do
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "${DATABASE//[[:space:]]/}" ]]; then
|
||||
DATABASE="$(read_local_spacetime_database)"
|
||||
fi
|
||||
|
||||
if [[ -z "${DATABASE//[[:space:]]/}" ]]; then
|
||||
DATABASE="genarrative-dev"
|
||||
fi
|
||||
|
||||
if [[ ! -f "${MANIFEST_PATH}" ]]; then
|
||||
echo "[dev:rust] 未找到 ${MANIFEST_PATH},无法启动 Rust 本地栈。" >&2
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user