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/scripts/iti.cmd

156 lines
3.8 KiB
Batchfile

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 "ROOT_DIR=%CD%"
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%"=="check" goto check
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 "%COMMAND%"=="release" goto release
if "%COMMAND%"=="make-app" goto make_app
if "%COMMAND%"=="make-system-app" goto make_system_app
echo 未知命令:%COMMAND% 1>&2
echo. 1>&2
goto help_error
:help
echo iTi-Flask 开发脚本
echo.
echo 用法:
echo iti.cmd ^<命令^> [参数]
echo.
echo 常用命令:
echo help 显示帮助
echo install 安装开发依赖uv sync --extra dev
echo test 运行测试uv run pytest -q
echo check 运行测试和 mypy
echo serve [端口] 启动框架示例应用,默认 8000
echo migrate 执行当前仓库 Alembic upgrade head
echo migration ^<说明^> 生成 migration说明建议以作者名开头
echo heads 查看 Alembic heads
echo current 查看当前 Alembic 版本
echo make-app ^<目录^> [发行名] 从当前框架仓库模板生成业务项目
echo make-system-app ^<目录^> [发行名] 生成带 iti-system 的业务项目
echo release [版本] 发布框架:测试、改版本、提交、打 tag、推送
echo.
echo 示例:
echo iti.cmd install
echo iti.cmd test
echo iti.cmd serve 8000
echo iti.cmd make-app ..\hsyh-erp-phase2 hsyh-erp-phase2
echo iti.cmd make-system-app ..\hsyh-mes-phase2 hsyh-mes-phase2
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
:check
uv run pytest -q
if errorlevel 1 goto end
uv run mypy
goto end
:serve
set "PORT=%~1"
if "%PORT%"=="" set "PORT=8000"
uv run uvicorn iti.app:create_app --factory --reload --port "%PORT%"
goto end
:migrate
uv run alembic upgrade head
goto end
:migration
set "MESSAGE=%~1"
if "%MESSAGE%"=="" (
echo 缺少 migration 说明。示例iti.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
:release
set "SHELL_CMD="
where sh >nul 2>nul && set "SHELL_CMD=sh"
if not defined SHELL_CMD (
where bash >nul 2>nul && set "SHELL_CMD=bash"
)
if not defined SHELL_CMD (
echo 找不到 sh 或 bash无法运行 release 脚本 1>&2
exit /b 1
)
if "%~1"=="" (
"%SHELL_CMD%" scripts/release.sh
) else (
"%SHELL_CMD%" scripts/release.sh %*
)
goto end
:make_app
set "INCLUDE_SYSTEM=false"
goto make_project
:make_system_app
set "INCLUDE_SYSTEM=true"
goto make_project
:make_project
set "TARGET=%~1"
set "DIST_NAME=%~2"
if "%TARGET%"=="" (
echo 缺少目标目录。示例iti.cmd make-app ..\my-app my-app 1>&2
exit /b 2
)
if "%DIST_NAME%"=="" (
for %%I in ("%TARGET%") do set "DIST_NAME=%%~nxI"
)
for %%I in ("%TARGET%") do set "PROJECT_NAME=%%~nxI"
uvx copier copy --defaults --vcs-ref HEAD "%CD%" "%TARGET%" -d project_name="!PROJECT_NAME!" -d project_slug="!DIST_NAME!" -d include_system="%INCLUDE_SYSTEM%"
goto end
:end
set "EXIT_CODE=%ERRORLEVEL%"
popd >nul
exit /b %EXIT_CODE%