pbl_blueprint/build.sh

67 lines
2.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# pbl_blueprint 模块构建脚本(由宿主应用 apps/pbls/build.sh 调用)
# 步骤:① json2ddl 生成 DDL ② xls2ui 生成 CRUD UI ③ 软链 wwwroot 到宿主
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MOD_NAME="pbl_blueprint"
# ---- 定位宿主应用根(不假设相对层级)
APP_ROOT=""
for candidate in "$SCRIPT_DIR/../../apps/pbls" "$SCRIPT_DIR/../.." "$PBL_APP_ROOT" "$SAGE_ROOT"; do
if [ -n "$candidate" ] && [ -d "$candidate/wwwroot" ]; then
APP_ROOT="$(cd "$candidate" && pwd)"
break
fi
done
echo "[${MOD_NAME}] module dir: $SCRIPT_DIR"
echo "[${MOD_NAME}] app root : ${APP_ROOT:-<未找到,仅生成本地产物>}"
# ---- ① 表定义 -> DDL
if [ -d "$SCRIPT_DIR/models" ]; then
if command -v json2ddl >/dev/null 2>&1; then
cd "$SCRIPT_DIR/models"
json2ddl mysql . > "$SCRIPT_DIR/mysql.ddl.sql"
echo "[${MOD_NAME}] mysql.ddl.sql 已生成"
cd "$SCRIPT_DIR"
else
echo "[${MOD_NAME}] WARN: json2ddl 未安装,使用 models/pbl_blueprint.subobjects.sql 作为 DDL 基线"
cp -f "$SCRIPT_DIR/models/pbl_blueprint.subobjects.sql" "$SCRIPT_DIR/mysql.ddl.sql"
fi
fi
# ---- ② CRUD 定义 -> UI
if [ -d "$SCRIPT_DIR/json" ] && command -v xls2ui >/dev/null 2>&1; then
cd "$SCRIPT_DIR/json"
xls2ui -m ../models -o ../wwwroot "${MOD_NAME}" *.json || \
echo "[${MOD_NAME}] WARN: xls2ui 生成失败CRUD 页面需手工核对"
cd "$SCRIPT_DIR"
fi
# ---- ③ 软链 wwwroot 到宿主应用
if [ -n "$APP_ROOT" ]; then
mkdir -p "$APP_ROOT/wwwroot/${MOD_NAME}"
for f in "$SCRIPT_DIR"/wwwroot/*.ui "$SCRIPT_DIR"/wwwroot/*.js "$SCRIPT_DIR"/wwwroot/*.css; do
[ -e "$f" ] || continue
ln -sf "$f" "$APP_ROOT/wwwroot/${MOD_NAME}/"
done
[ -d "$SCRIPT_DIR/wwwroot/api" ] && {
mkdir -p "$APP_ROOT/wwwroot/${MOD_NAME}/api"
for f in "$SCRIPT_DIR"/wwwroot/api/*.dspy; do
[ -e "$f" ] || continue
ln -sf "$f" "$APP_ROOT/wwwroot/${MOD_NAME}/api/"
done
}
# CRUD 生成子目录整体软链(排除 api/styles/scripts
for d in "$SCRIPT_DIR"/wwwroot/*/; do
[ -d "$d" ] || continue
bn="$(basename "$d")"
case "$bn" in api|styles|scripts) continue ;; esac
ln -sfn "${d%/}" "$APP_ROOT/wwwroot/${MOD_NAME}/$bn"
done
echo "[${MOD_NAME}] wwwroot 已链接到 $APP_ROOT/wwwroot/${MOD_NAME}"
fi
echo "[${MOD_NAME}] build done"