@echo off setlocal enabledelayedexpansion set "SCRIPT_DIR=%~dp0" set "ROOT_DIR=%SCRIPT_DIR%" pushd "%ROOT_DIR%" >nul set "PROJECT_VENV=%ROOT_DIR%.venv" if defined VIRTUAL_ENV ( if /I not "%VIRTUAL_ENV%"=="%PROJECT_VENV%" ( if /I not "%VIRTUAL_ENV%"=="%PROJECT_VENV%\" set "VIRTUAL_ENV=" ) ) set "COMMAND=%~1" if "%COMMAND%"=="" set "COMMAND=help" shift /1 if "%COMMAND%"=="help" goto help if "%COMMAND%"=="-h" goto help if "%COMMAND%"=="--help" goto help if "%COMMAND%"=="install" goto install if "%COMMAND%"=="test" goto test if "%COMMAND%"=="serve" goto serve if "%COMMAND%"=="migrate" goto migrate if "%COMMAND%"=="migration" goto migration if "%COMMAND%"=="heads" goto heads if "%COMMAND%"=="current" goto current {% if include_system %}if "%COMMAND%"=="system-sync" goto system_sync if "%COMMAND%"=="system-seed" goto system_seed if "%COMMAND%"=="init-system" goto init_system {% endif %}if "%COMMAND%"=="init" goto init echo 未知命令:%COMMAND% 1>&2 echo. 1>&2 goto help_error :help echo {{ project_name }} 项目脚本 echo. echo 用法: echo app.cmd ^<命令^> [参数] echo. echo 常用命令: echo help 显示帮助 echo install 安装开发依赖:uv sync --extra dev echo test 运行测试:uv run pytest -q echo serve [端口] 本地启动,默认 8000 echo migrate 执行 Alembic upgrade head echo migration ^<说明^> 生成 migration,说明建议以作者名开头 echo heads 查看 Alembic heads echo current 查看当前 Alembic 版本 {% if include_system %}echo system-sync 同步 iti-system migration 到当前项目 echo system-seed 初始化 / 更新系统 seed echo init-system system-sync + migrate + system-seed {% endif %}echo init install + migrate{% if include_system %} + system-seed{% endif %} echo. echo 示例: echo app.cmd install echo app.cmd serve 8000 echo app.cmd migration "alice add order table" {% if include_system %}echo app.cmd init-system {% endif %}popd >nul exit /b 0 :help_error call :help exit /b 2 :install uv sync --extra dev goto end :test uv run pytest -q goto end :serve set "PORT=%~1" if "%PORT%"=="" set "PORT=8000" uv run uvicorn app:app --reload --port "%PORT%" goto end :migrate uv run alembic upgrade head goto end :migration set "MESSAGE=%~1" if "%MESSAGE%"=="" ( echo 缺少 migration 说明。示例:app.cmd migration "alice add order table" 1>&2 exit /b 2 ) uv run alembic revision --autogenerate -m "%MESSAGE%" goto end :heads uv run alembic heads goto end :current uv run alembic current goto end {% if include_system %}:system_sync uv run iti-system migrations sync --target migrations/versions goto end :system_seed uv run iti-system seed system app:app goto end :init_system uv run iti-system migrations sync --target migrations/versions if errorlevel 1 goto end uv run alembic upgrade head if errorlevel 1 goto end uv run iti-system seed system app:app goto end {% endif %}:init uv sync --extra dev if errorlevel 1 goto end {% if include_system %}uv run iti-system migrations sync --target migrations/versions if errorlevel 1 goto end {% endif %}uv run alembic upgrade head if errorlevel 1 goto end {% if include_system %}uv run iti-system seed system app:app {% endif %}goto end :end set "EXIT_CODE=%ERRORLEVEL%" popd >nul exit /b %EXIT_CODE%