Initial dashboard skill - Vite+React+Tailwind web UI
This commit is contained in:
101
scripts/autorun.sh
Normal file
101
scripts/autorun.sh
Normal file
@@ -0,0 +1,101 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
NODE_VERSION="${NODE_VERSION:-20}"
|
||||
SKILLS_DIR="${SKILLS_DIR:-/skills}"
|
||||
SKILL_DIR="$(dirname "$(dirname "$0")")"
|
||||
|
||||
# Idempotent Node.js installation
|
||||
install_node() {
|
||||
if command -v node &>/dev/null; then
|
||||
echo "Node.js already installed: $(node --version)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Installing Node.js ${NODE_VERSION}..."
|
||||
|
||||
# Install via NodeSource
|
||||
apt-get update
|
||||
apt-get install -y curl ca-certificates gnupg
|
||||
|
||||
mkdir -p /etc/apt/keyrings
|
||||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
|
||||
|
||||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" > /etc/apt/sources.list.d/nodesource.list
|
||||
|
||||
apt-get update
|
||||
apt-get install -y nodejs
|
||||
|
||||
echo "Node.js installed: $(node --version)"
|
||||
echo "npm installed: $(npm --version)"
|
||||
}
|
||||
|
||||
# Install UI dependencies
|
||||
install_deps() {
|
||||
local ui_dir="$SKILL_DIR/ui"
|
||||
|
||||
if [ -d "$ui_dir/node_modules" ]; then
|
||||
echo "Dependencies already installed"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Installing UI dependencies..."
|
||||
cd "$ui_dir"
|
||||
npm install
|
||||
|
||||
echo "Dependencies installed"
|
||||
}
|
||||
|
||||
# Build UI for production
|
||||
build_ui() {
|
||||
local ui_dir="$SKILL_DIR/ui"
|
||||
|
||||
if [ -d "$ui_dir/dist" ]; then
|
||||
echo "UI already built"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Building UI..."
|
||||
cd "$ui_dir"
|
||||
npm run build
|
||||
|
||||
echo "UI built"
|
||||
}
|
||||
|
||||
# Configure Caddy if domain set
|
||||
configure_caddy() {
|
||||
local caddy_dir="$SKILLS_DIR/caddy"
|
||||
local dashboard_domain="${DASHBOARD_DOMAIN:-}"
|
||||
local dashboard_port="${DASHBOARD_PORT:-3000}"
|
||||
|
||||
if [ ! -d "$caddy_dir" ]; then
|
||||
echo "Caddy not found - dashboard will run standalone"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -z "$dashboard_domain" ]; then
|
||||
echo "DASHBOARD_DOMAIN not set - skipping Caddy config"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Configuring Caddy for $dashboard_domain..."
|
||||
|
||||
local snippets_dir="$caddy_dir/snippets.d"
|
||||
mkdir -p "$snippets_dir"
|
||||
|
||||
cat > "$snippets_dir/dashboard.caddy" << EOF
|
||||
# Auto-generated by dashboard skill
|
||||
$dashboard_domain {
|
||||
reverse_proxy localhost:$dashboard_port
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "Caddy config: $dashboard_domain -> localhost:$dashboard_port"
|
||||
}
|
||||
|
||||
install_node
|
||||
install_deps
|
||||
build_ui
|
||||
configure_caddy
|
||||
|
||||
echo "Dashboard setup complete"
|
||||
28
scripts/run.sh
Normal file
28
scripts/run.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
DASHBOARD_PORT="${DASHBOARD_PORT:-3000}"
|
||||
SKILL_DIR="$(dirname "$(dirname "$0")")"
|
||||
UI_DIR="$SKILL_DIR/ui"
|
||||
|
||||
# Export environment for the app
|
||||
export DASHBOARD_PORT
|
||||
export SUPERVISOR_URL="${SUPERVISOR_URL:-http://localhost:9001}"
|
||||
export MEMORY_URL="${MEMORY_URL:-http://localhost:8081}"
|
||||
export SKILLS_DIR="${SKILLS_DIR:-/skills}"
|
||||
|
||||
echo "Starting Dashboard on port $DASHBOARD_PORT..."
|
||||
echo "Supervisor: $SUPERVISOR_URL"
|
||||
echo "Memory API: $MEMORY_URL"
|
||||
|
||||
cd "$UI_DIR"
|
||||
|
||||
# In production, serve built files
|
||||
# In development, run vite dev server
|
||||
if [ "${NODE_ENV:-production}" = "development" ]; then
|
||||
echo "Running in development mode..."
|
||||
exec npm run dev -- --port "$DASHBOARD_PORT" --host
|
||||
else
|
||||
echo "Running in production mode..."
|
||||
exec npm run preview -- --port "$DASHBOARD_PORT" --host
|
||||
fi
|
||||
Reference in New Issue
Block a user