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/scripts/app.sh.jinja

95 lines
2.5 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.

#!/usr/bin/env sh
set -eu
ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$ROOT_DIR"
show_help() {
cat <<'EOF'
{{ project_name }} 项目脚本
用法:
./scripts/app.sh <命令> [参数]
常用命令:
help 显示帮助
install 安装开发依赖uv sync --extra dev
test 运行测试uv run pytest -q
serve [端口] 本地启动,默认 8000
migrate 执行 Alembic upgrade head
migration <说明> 生成 migration说明建议以作者名开头
heads 查看 Alembic heads
current 查看当前 Alembic 版本
{% if include_system %} system-sync 同步 iti-system migration 到当前项目
system-seed 初始化 / 更新系统 seed
init-system system-sync + migrate + system-seed
{% endif %} init install + migrate{% if include_system %} + system-seed{% endif %}
示例:
./scripts/app.sh install
./scripts/app.sh serve 8000
./scripts/app.sh migration "alice add order table"
{% if include_system %} ./scripts/app.sh init-system
{% endif %}
EOF
}
command=${1:-help}
shift || true
case "$command" in
help|-h|--help)
show_help
;;
install)
uv sync --extra dev
;;
test)
uv run pytest -q
;;
serve)
port=${1:-8000}
uv run uvicorn app:app --reload --port "$port"
;;
migrate)
uv run alembic upgrade head
;;
migration)
message=${1:-}
if [ -z "$message" ]; then
echo "缺少 migration 说明。示例:./scripts/app.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
;;
{% if include_system %} system-sync)
uv run iti-system migrations sync --target migrations/versions
;;
system-seed)
uv run iti-system seed system app:app
;;
init-system)
uv run iti-system migrations sync --target migrations/versions
uv run alembic upgrade head
uv run iti-system seed system app:app
;;
{% endif %} init)
uv sync --extra dev
{% if include_system %} uv run iti-system migrations sync --target migrations/versions
{% endif %} uv run alembic upgrade head
{% if include_system %} uv run iti-system seed system app:app
{% endif %} ;;
*)
echo "未知命令:$command" >&2
echo >&2
show_help >&2
exit 2
;;
esac