@echo off setlocal enabledelayedexpansion set "SCRIPT_DIR=%~dp0" set "ROOT_DIR=%SCRIPT_DIR%" pushd "%ROOT_DIR%" >nul set "UV_NO_SOURCES_PACKAGE=iti-flask" 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%"=="framework-sync" goto framework_sync if "%COMMAND%"=="template-check" ( call uvx copier update --defaults --pretend --vcs-ref HEAD "%ROOT_DIR%" set "EXIT_CODE=!ERRORLEVEL!" popd >nul exit /b !EXIT_CODE! ) if "%COMMAND%"=="template-update" ( call uvx copier update --defaults --vcs-ref HEAD "%ROOT_DIR%" set "EXIT_CODE=!ERRORLEVEL!" popd >nul exit /b !EXIT_CODE! ) 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 framework-sync 同步 iTi-Flask{% if include_system %} / iTi-System{% endif %} 依赖 echo template-check 检查 Copier 模板是否有更新 echo template-update 按 Copier 模板更新项目骨架 echo test 运行测试:uv run --extra dev pytest -q echo serve [环境] [端口] 本地启动,默认 dev / 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 echo app.cmd serve test 8000 echo set APP_ENV=prod ^&^& app.cmd migrate 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 :framework_sync uv sync --extra dev --upgrade-package iti-flask{% if include_system %} --upgrade-package iti-system{% endif %} goto end :test uv run --extra dev pytest -q goto end :serve set "ENV_NAME=%APP_ENV%" if not defined ENV_NAME set "ENV_NAME=%ITI_ENV%" if not defined ENV_NAME set "ENV_NAME=dev" set "PORT=8000" set "ARG1=%~1" if /I "%ARG1%"=="dev" ( set "ENV_NAME=dev" set "PORT=%~2" ) else if /I "%ARG1%"=="test" ( set "ENV_NAME=test" set "PORT=%~2" ) else if /I "%ARG1%"=="prod" ( set "ENV_NAME=prod" set "PORT=%~2" ) else if /I "%ARG1%"=="default" ( set "ENV_NAME=dev" set "PORT=%~2" ) else if not "%ARG1%"=="" ( echo(%ARG1%| findstr /r "^[0-9][0-9]*$" >nul if errorlevel 1 ( set "ENV_NAME=%ARG1%" set "PORT=%~2" ) else ( set "PORT=%ARG1%" ) ) if "%PORT%"=="" set "PORT=8000" set "APP_ENV=%ENV_NAME%" set "ITI_ENV=%ENV_NAME%" uv run uvicorn main:app --reload --port "%PORT%" goto end :migrate uv run alembic -c migrations/alembic.ini 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 -c migrations/alembic.ini revision --autogenerate -m "%MESSAGE%" goto end :heads uv run alembic -c migrations/alembic.ini heads goto end :current uv run alembic -c migrations/alembic.ini 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 main:app goto end :init_system uv run iti-system migrations sync --target migrations/versions if errorlevel 1 goto end uv run alembic -c migrations/alembic.ini upgrade head if errorlevel 1 goto end uv run iti-system seed system main: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 -c migrations/alembic.ini upgrade head if errorlevel 1 goto end {% if include_system %}uv run iti-system seed system main:app {% endif %}goto end :end set "EXIT_CODE=%ERRORLEVEL%" popd >nul exit /b %EXIT_CODE%