You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iTi-Flask/copier-template/app.cmd.jinja

153 lines
4.1 KiB
Django/Jinja

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

@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%"=="framework-sync" goto framework_sync
if "%COMMAND%"=="template-check" goto template_check
if "%COMMAND%"=="template-update" goto template_update
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 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
:framework_sync
uv sync --extra dev --upgrade-package iti-flask{% if include_system %} --upgrade-package iti-system{% endif %}
goto end
:template_check
uvx copier update --defaults --pretend --vcs-ref HEAD "%ROOT_DIR%"
goto end
:template_update
uvx copier update --defaults --vcs-ref HEAD "%ROOT_DIR%"
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%