magicciv/scripts/run/dev.sh

124 lines
3.6 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Dev commands: play, editor, lint, format, test, verify, screenshot
cmd_play() {
echo -e "${BLUE}Launching Magic Civilization...${NC}"
WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-wayland-0}" \
XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" \
$GODOT_BIN --path "$GAME_DIR" --rendering-method gl_compatibility "$@"
}
cmd_editor() {
echo -e "${BLUE}Opening Godot editor...${NC}"
WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-wayland-0}" \
XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" \
$GODOT_BIN --path "$GAME_DIR" -e --rendering-method gl_compatibility "$@" &
}
cmd_lint() {
local exit_code=0
echo -e "${BLUE}[1/3] GDScript lint...${NC}"
lilith-gdtoolkit-sync --check || {
echo -e "${YELLOW}Config drift detected — syncing...${NC}"
lilith-gdtoolkit-sync
}
gdlint "$GAME_DIR/engine/src/" || exit_code=$?
echo ""
echo -e "${BLUE}[2/3] Rust lint (fmt + clippy)...${NC}"
(cd "$SIMULATOR_DIR" && cargo fmt --check --all) || exit_code=$?
(cd "$SIMULATOR_DIR" && cargo clippy --workspace --all-targets -- -D warnings) || exit_code=$?
echo ""
echo -e "${BLUE}[3/3] Guide lint (ESLint)...${NC}"
pnpm --prefix "$GUIDE_DIR" lint || exit_code=$?
return $exit_code
}
cmd_format() {
echo -e "${BLUE}[1/3] GDScript format...${NC}"
lilith-gdtoolkit-sync --check || {
echo -e "${YELLOW}Config drift detected — syncing...${NC}"
lilith-gdtoolkit-sync
}
gdformat "$GAME_DIR/engine/src/"
echo ""
echo -e "${BLUE}[2/3] Rust format...${NC}"
(cd "$SIMULATOR_DIR" && cargo fmt --all)
echo ""
echo -e "${BLUE}[3/3] Guide format (ESLint --fix)...${NC}"
pnpm --prefix "$GUIDE_DIR" lint:fix
}
cmd_test() {
local exit_code=0
echo -e "${BLUE}Running GUT tests (GDScript)...${NC}"
WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-wayland-0}" \
XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" \
$GODOT_BIN --path "$GAME_DIR" --headless --script res://addons/gut/gut_cmdln.gd \
-gexit "$@" || exit_code=$?
echo ""
echo -e "${BLUE}Running Rust tests (simulator)...${NC}"
(cd "$SIMULATOR_DIR" && cargo test --workspace) || exit_code=$?
echo ""
echo -e "${BLUE}Running vitest (guide)...${NC}"
pnpm --prefix "$GUIDE_DIR" test || exit_code=$?
return $exit_code
}
cmd_verify() {
local exit_code=0
echo -e "${BLUE}[1/7] GDScript lint...${NC}"
gdlint "$GAME_DIR/engine/src/" || exit_code=$?
echo ""
echo -e "${BLUE}[2/7] Guide typecheck...${NC}"
pnpm --prefix "$GUIDE_DIR" typecheck || exit_code=$?
echo ""
echo -e "${BLUE}[3/7] Guide lint (ESLint)...${NC}"
pnpm --prefix "$GUIDE_DIR" lint || exit_code=$?
echo ""
echo -e "${BLUE}[4/7] Rust fmt check...${NC}"
(cd "$SIMULATOR_DIR" && cargo fmt --check --all) || exit_code=$?
echo ""
echo -e "${BLUE}[5/7] Rust clippy...${NC}"
(cd "$SIMULATOR_DIR" && cargo clippy --workspace --all-targets -- -D warnings) || exit_code=$?
echo ""
echo -e "${BLUE}[6/7] Rust build check...${NC}"
(cd "$SIMULATOR_DIR" && cargo check --workspace) || exit_code=$?
echo ""
echo -e "${BLUE}[7/7] Tests (GUT + Rust + vitest)...${NC}"
cmd_test || exit_code=$?
echo ""
if [ "$exit_code" -eq 0 ]; then
echo -e "${GREEN}✓ All checks passed${NC}"
else
echo -e "${RED}✗ One or more checks failed${NC}"
fi
return $exit_code
}
cmd_screenshot() {
"$REPO_ROOT/tools/screenshot.sh" "$@"
}
cmd_guide() {
echo -e "${BLUE}Starting guide dev server (port 5800)...${NC}"
pnpm --prefix "$GUIDE_DIR" dev
}