#!/bin/bash # Supplychain module build script # Links wwwroot files to Sage and generates DDL/CRUD UI files set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Find Sage root 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: Sage root not found" exit 1 fi echo "Sage root: $SAGE_ROOT" # Generate DDL from models if present if [ -d "$SCRIPT_DIR/models" ]; then echo "Generating DDL from models..." cd "$SCRIPT_DIR/models" if ls *.xlsx 1>/dev/null 2>&1; then "$SAGE_ROOT/py3/bin/xls2ddl" mysql . > mysql.ddl.sql echo "DDL generated: models/mysql.ddl.sql" elif ls *.json 1>/dev/null 2>&1; then "$SAGE_ROOT/py3/bin/json2ddl" mysql . > mysql.ddl.sql echo "DDL generated: models/mysql.ddl.sql" fi fi # Generate CRUD UI from json definitions if present if [ -d "$SCRIPT_DIR/json" ]; then echo "Generating CRUD UI files..." cd "$SCRIPT_DIR/json" if [ -d "$SCRIPT_DIR/models" ]; then "$SAGE_ROOT/py3/bin/xls2ui" -m "$SCRIPT_DIR/models" -o "$SCRIPT_DIR/wwwroot" supplychain *.json echo "CRUD UI files generated in wwwroot/" fi fi # Link wwwroot to Sage echo "Linking wwwroot to Sage..." rm -f "$SAGE_ROOT/wwwroot/supplychain" ln -sf "$SCRIPT_DIR/wwwroot" "$SAGE_ROOT/wwwroot/supplychain" echo "Supplychain module build complete."