chore: update spacetime dev scripts
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
@@ -8,13 +8,13 @@ usage() {
|
||||
npm run dev:rust
|
||||
./scripts/dev-rust-stack.sh --api-port 8090 --spacetime-port 3110
|
||||
./scripts/dev-rust-stack.sh --skip-spacetime --skip-publish
|
||||
./scripts/dev-rust-stack.sh --clear-database
|
||||
./scripts/dev-rust-stack.sh --preserve-database
|
||||
npm run dev:rust:logs -- --follow
|
||||
|
||||
说明:
|
||||
1. 默认同时启动 SpacetimeDB standalone、Rust api-server 与 Vite 前端。
|
||||
2. 默认会 publish server-rs/crates/spacetime-module,但不会清空数据库。
|
||||
3. 只有显式传入 --clear-database 时,才会追加 spacetime publish --clear-database。
|
||||
2. 当前开发阶段默认 publish server-rs/crates/spacetime-module 时追加 -c=on-conflict 在结构冲突时清理旧模块数据。
|
||||
3. 只有显式传入 --preserve-database 时,才会跳过 -c=on-conflict。
|
||||
4. SpacetimeDB 默认使用 server-rs/.spacetimedb/local 作为本地数据与日志目录。
|
||||
EOF
|
||||
}
|
||||
@@ -67,7 +67,8 @@ cleanup() {
|
||||
wait_for_spacetime() {
|
||||
local server="$1"
|
||||
local timeout_seconds="$2"
|
||||
local process_pid="${3:-}"
|
||||
local root_dir="$3"
|
||||
local process_pid="${4:-}"
|
||||
local deadline=$((SECONDS + timeout_seconds))
|
||||
|
||||
while ((SECONDS < deadline)); do
|
||||
@@ -76,7 +77,7 @@ wait_for_spacetime() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if spacetime server ping "${server}" >/dev/null 2>&1; then
|
||||
if spacetime --root-dir="${root_dir}" server ping "${server}" >/dev/null 2>&1; then
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -87,6 +88,51 @@ wait_for_spacetime() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
sync_local_spacetime_install() {
|
||||
local root_dir="$1"
|
||||
|
||||
# SpacetimeDB standalone 会在 --root-dir 下回调 bin/current/spacetimedb-cli.exe;
|
||||
# Windows 本地开发使用工程内 root-dir 时,需要把用户级安装目录同步进来。
|
||||
if [[ "${OSTYPE:-}" != msys* && "${OSTYPE:-}" != cygwin* ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local target_cli="${root_dir}/bin/current/spacetimedb-cli.exe"
|
||||
if [[ -f "${target_cli}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local spacetime_command
|
||||
spacetime_command="$(command -v spacetime || true)"
|
||||
if [[ -z "${spacetime_command}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local install_dir
|
||||
install_dir="$(cd -- "$(dirname -- "${spacetime_command}")" && pwd)"
|
||||
if [[ ! -d "${install_dir}/bin" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
echo "[dev:rust] 同步本机 SpacetimeDB 安装到 ${root_dir}"
|
||||
mkdir -p "${root_dir}"
|
||||
cp -a "${install_dir}/bin" "${root_dir}/"
|
||||
if [[ -f "${install_dir}/spacetime.exe" ]]; then
|
||||
cp -f "${install_dir}/spacetime.exe" "${root_dir}/spacetime.exe"
|
||||
fi
|
||||
|
||||
# Git Bash 复制 Windows junction 时可能不会生成可执行的 current 目录;
|
||||
# 若 current 缺失,则用最新版本目录复制出一个真实目录,满足 standalone 回调路径。
|
||||
if [[ ! -f "${target_cli}" ]]; then
|
||||
local version_dir
|
||||
version_dir="$(find "${root_dir}/bin" -mindepth 1 -maxdepth 1 -type d ! -name current | sort -V | tail -n 1)"
|
||||
if [[ -n "${version_dir}" && -f "${version_dir}/spacetimedb-cli.exe" ]]; then
|
||||
rm -rf "${root_dir}/bin/current"
|
||||
cp -a "${version_dir}" "${root_dir}/bin/current"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
|
||||
SERVER_RS_DIR="${REPO_ROOT}/server-rs"
|
||||
@@ -106,7 +152,7 @@ API_LOG="info,tower_http=info"
|
||||
SPACETIME_TIMEOUT_SECONDS="60"
|
||||
SKIP_SPACETIME=0
|
||||
SKIP_PUBLISH=0
|
||||
CLEAR_DATABASE=0
|
||||
PRESERVE_DATABASE=0
|
||||
PIDS=()
|
||||
NAMES=()
|
||||
|
||||
@@ -186,7 +232,11 @@ while [[ $# -gt 0 ]]; do
|
||||
shift
|
||||
;;
|
||||
--clear-database)
|
||||
CLEAR_DATABASE=1
|
||||
PRESERVE_DATABASE=0
|
||||
shift
|
||||
;;
|
||||
--preserve-database)
|
||||
PRESERVE_DATABASE=1
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
@@ -242,6 +292,7 @@ echo "[dev:rust] spacetime root: ${SPACETIME_ROOT_DIR}"
|
||||
|
||||
if [[ "${SKIP_SPACETIME}" -ne 1 ]]; then
|
||||
mkdir -p "${SPACETIME_ROOT_DIR}"
|
||||
sync_local_spacetime_install "${SPACETIME_ROOT_DIR}"
|
||||
echo "[dev:rust] 启动 spacetimedb"
|
||||
(
|
||||
cd "${SERVER_RS_DIR}"
|
||||
@@ -257,7 +308,7 @@ fi
|
||||
|
||||
if [[ "${SKIP_PUBLISH}" -ne 1 ]]; then
|
||||
echo "[dev:rust] 等待 SpacetimeDB 就绪"
|
||||
wait_for_spacetime "${SPACETIME_SERVER}" "${SPACETIME_TIMEOUT_SECONDS}" "${PIDS[0]:-}"
|
||||
wait_for_spacetime "${SPACETIME_SERVER}" "${SPACETIME_TIMEOUT_SECONDS}" "${SPACETIME_ROOT_DIR}" "${PIDS[0]:-}"
|
||||
|
||||
PUBLISH_ARGS=(
|
||||
publish
|
||||
@@ -266,14 +317,14 @@ if [[ "${SKIP_PUBLISH}" -ne 1 ]]; then
|
||||
--module-path "${MODULE_PATH}"
|
||||
)
|
||||
|
||||
if [[ "${CLEAR_DATABASE}" -eq 1 ]]; then
|
||||
PUBLISH_ARGS+=(--clear-database)
|
||||
if [[ "${PRESERVE_DATABASE}" -ne 1 ]]; then
|
||||
PUBLISH_ARGS+=(-c=on-conflict)
|
||||
fi
|
||||
|
||||
PUBLISH_ARGS+=(--yes)
|
||||
|
||||
echo "[dev:rust] 发布 SpacetimeDB 模块: ${DATABASE}"
|
||||
spacetime "${PUBLISH_ARGS[@]}"
|
||||
spacetime --root-dir="${SPACETIME_ROOT_DIR}" "${PUBLISH_ARGS[@]}"
|
||||
fi
|
||||
|
||||
echo "[dev:rust] 启动 api-server"
|
||||
|
||||
Reference in New Issue
Block a user