harnessed_agent/build.sh
2026-05-04 10:09:04 +08:00

53 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# harnessed_agent build script
# Follows module-development-spec: processes models/, json/, and wwwroot/
set -e
MODULE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MODULE_NAME="harnessed_agent"
echo "Building ${MODULE_NAME} module..."
# Step 1: Generate DDL from model JSON files
if [ -d "$MODULE_DIR/models" ] && ls "$MODULE_DIR/models"/*.json 1>/dev/null 2>&1; then
echo "Generating DDL from model definitions..."
cd "$MODULE_DIR/models"
if command -v json2ddl &>/dev/null; then
json2ddl mysql . > mysql.ddl.sql
echo "Generated mysql.ddl.sql from models/"
else
echo "Warning: json2ddl not found, skipping DDL generation"
fi
cd "$MODULE_DIR"
fi
# Step 2: Generate CRUD UI from JSON definitions
if [ -d "$MODULE_DIR/json" ] && ls "$MODULE_DIR/json"/*.json 1>/dev/null 2>&1; then
echo "Generating CRUD UI files from JSON definitions..."
cd "$MODULE_DIR/json"
if command -v xls2ui &>/dev/null; then
for f in *.json; do
xls2ui -m ../models -o ../wwwroot "${MODULE_NAME}" "$f" 2>/dev/null || true
done
echo "Generated CRUD UI files in wwwroot/"
else
echo "Warning: xls2ui not found, skipping UI generation"
fi
cd "$MODULE_DIR"
fi
# Step 3: Link wwwroot files to main application wwwroot
MAIN_WWWROOT="$MODULE_DIR/../wwwroot"
mkdir -p "$MAIN_WWWROOT"
for file in "$MODULE_DIR"/wwwroot/*; do
if [ -f "$file" ]; then
filename=$(basename "$file")
ln -sf "$file" "$MAIN_WWWROOT/${MODULE_NAME}_${filename}"
echo "Linked $filename to main wwwroot"
fi
done
echo "${MODULE_NAME} module build completed successfully!"