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.sh

117 lines
2.9 KiB
Bash

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.

#!/usr/bin/env sh
set -eu
ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$ROOT_DIR"
PROJECT_VENV="$ROOT_DIR/.venv"
case "${VIRTUAL_ENV:-}" in
""|"$PROJECT_VENV"|"$PROJECT_VENV/")
;;
*)
unset VIRTUAL_ENV
;;
esac
show_help() {
cat <<'EOF'
iTi-Flask 开发脚本
用法:
./scripts/iti.sh <命令> [参数]
常用命令:
help 显示帮助
install 安装开发依赖uv sync --extra dev
test 运行测试uv run pytest -q
check 运行测试和 mypy
serve [端口] 启动框架示例应用,默认 8000
migrate 执行当前仓库 Alembic upgrade head
migration <说明> 生成 migration说明建议以作者名开头
heads 查看 Alembic heads
current 查看当前 Alembic 版本
make-app <目录> [包名] 从当前框架仓库模板生成业务项目
make-system-app <目录> [包名] 生成带 iti-system 的业务项目
release [版本] 发布框架:测试、改版本、提交、打 tag、推送
示例:
./scripts/iti.sh install
./scripts/iti.sh test
./scripts/iti.sh serve 8000
./scripts/iti.sh make-app ../hsyh-erp hsyh_erp
./scripts/iti.sh make-system-app ../hsyh-mes-phase2 hsyh_mes_phase2
说明:
- 默认生成项目使用 copier-template 里的 Git 依赖配置。
- 临时本地验证可在生成时按 copier 交互改成 file://。
EOF
}
command=${1:-help}
shift || true
case "$command" in
help|-h|--help)
show_help
;;
install)
uv sync --extra dev
;;
test)
uv run pytest -q
;;
check)
uv run pytest -q
uv run mypy
;;
serve)
port=${1:-8000}
uv run uvicorn iti.app:create_app --factory --reload --port "$port"
;;
migrate)
uv run alembic upgrade head
;;
migration)
message=${1:-}
if [ -z "$message" ]; then
echo "缺少 migration 说明。示例:./scripts/iti.sh migration \"alice add order table\"" >&2
exit 2
fi
uv run alembic revision --autogenerate -m "$message"
;;
heads)
uv run alembic heads
;;
current)
uv run alembic current
;;
release)
sh scripts/release.sh "$@"
;;
make-app|make-system-app)
target=${1:-}
package=${2:-}
if [ -z "$target" ]; then
echo "缺少目标目录。示例:./scripts/iti.sh make-app ../my-app my_app" >&2
exit 2
fi
if [ -z "$package" ]; then
package=$(basename "$target" | tr '-' '_')
fi
include_system=false
if [ "$command" = "make-system-app" ]; then
include_system=true
fi
uvx copier copy --defaults --vcs-ref HEAD "$ROOT_DIR" "$target" \
-d project_name="$(basename "$target")" \
-d project_slug="$package" \
-d include_system="$include_system"
;;
*)
echo "未知命令:$command" >&2
echo >&2
show_help >&2
exit 2
;;
esac