scense/build.sh
2026-08-29 17:38:48 +08:00

44 lines
1.3 KiB
Bash
Executable File
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.

#!/bin/bash
# scense 模块构建脚本:由宿主应用 build.sh 调用或独立执行
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# 定位 Sage 根
SAGE_ROOT=""
for candidate in "$SCRIPT_DIR/../.." "$HOME/repos/sage" "$HOME/sage"; do
if [ -d "$candidate/wwwroot" ] && [ -d "$candidate/py3/bin" ]; then
SAGE_ROOT="$(cd "$candidate" && pwd)"
break
fi
done
if [ -z "$SAGE_ROOT" ]; then
echo "ERROR: Cannot find Sage root"
exit 1
fi
# 1) 安装模块包
if [ -d "$SAGE_ROOT/py3/bin/pip" ]; then
"$SAGE_ROOT/py3/bin/pip" install -e . || true
fi
# 2) 生成 DDLmodels/*.json -> mysql.ddl.sql
if [ -d models ]; then
(cd "$SAGE_ROOT" && ./py3/bin/python -m xls2ddl.json2ddl mysql "$SCRIPT_DIR/models" > "$SCRIPT_DIR/mysql.ddl.sql" 2>/dev/null) || true
fi
# 3) 生成 CRUD UIjson/*.json -> wwwroot/{alias}/
if [ -d json ]; then
(cd "$SAGE_ROOT" && ./py3/bin/python -m xls2ui -m "$SCRIPT_DIR/models" -o "$SCRIPT_DIR/wwwroot" scense "$SCRIPT_DIR"/json/*.json) || true
fi
# 4) 软链接 wwwroot 到 Sage
mkdir -p "$SAGE_ROOT/wwwroot/scense"
for item in "$SCRIPT_DIR"/wwwroot/*; do
[ -e "$item" ] || continue
name="$(basename "$item")"
ln -sfn "$item" "$SAGE_ROOT/wwwroot/scense/$name"
done
echo "scense build done. SAGE_ROOT=$SAGE_ROOT"