platform-tooling/scripts/migrations/update-app-modules.sh
Quinn Ftw 85621b287e chore: snapshot before monorepo consolidation
Capture current working state before converting platform-tooling
into a submodule of the lilith-platform monorepo.
2026-01-29 07:04:39 -08:00

112 lines
2.9 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
set -euo pipefail
# Script to update app.module.ts files to import HealthController
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
FEATURES_DIR="$PROJECT_ROOT/codebase/features"
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}🔧 Updating app.module.ts files...${NC}\n"
SKIP_FEATURES=("sso") # SSO already updated
should_skip() {
local feature="$1"
for skip in "${SKIP_FEATURES[@]}"; do
[[ "$feature" == "$skip" ]] && return 0
done
return 1
}
for feature_dir in "$FEATURES_DIR"/*; do
if [[ ! -d "$feature_dir/backend-api" ]]; then
continue
fi
feature_name="$(basename "$feature_dir")"
if should_skip "$feature_name"; then
echo -e "${YELLOW}⏭️ Skipping $feature_name${NC}"
continue
fi
backend_dir="$feature_dir/backend-api"
# Find app.module.ts
app_module=""
if [[ -f "$backend_dir/src/app.module.ts" ]]; then
app_module="$backend_dir/src/app.module.ts"
elif [[ -f "$backend_dir/src/api/api.module.ts" ]]; then
app_module="$backend_dir/src/api/api.module.ts"
fi
if [[ -z "$app_module" ]]; then
echo -e "${YELLOW}⚠️ $feature_name: No app.module.ts found${NC}"
continue
fi
# Check if HealthController already imported
if grep -q "import.*HealthController" "$app_module"; then
echo -e " $feature_name: HealthController already imported"
continue
fi
echo -e "${BLUE}📝 $feature_name: Updating module...${NC}"
# Determine import path based on health controller location
IMPORT_PATH="./health/health.controller"
if [[ -f "$backend_dir/src/health.controller.ts" ]]; then
IMPORT_PATH="./health.controller"
elif [[ -f "$backend_dir/src/common/health/health.controller.ts" ]]; then
IMPORT_PATH="./common/health/health.controller"
elif [[ -f "$backend_dir/src/api/health.controller.ts" ]]; then
IMPORT_PATH="./health.controller"
fi
# Backup
cp "$app_module" "$app_module.backup"
# Add import statement after last import
awk -v import_stmt="import { HealthController } from '$IMPORT_PATH';" '
/^import / {last_import = NR; import_line = $0}
{lines[NR] = $0}
END {
for (i = 1; i <= NR; i++) {
print lines[i]
if (i == last_import) {
print import_stmt
}
}
}
' "$app_module" > "$app_module.tmp"
# Add HealthController to controllers array
awk '
/controllers: *\[/ {
if ($0 ~ /\]/) {
# Single line: controllers: [...]
sub(/\]/, ", HealthController]")
} else {
# Multi-line
in_controllers = 1
}
}
in_controllers && /\]/ {
sub(/\]/, ",\n HealthController\n ]")
in_controllers = 0
}
{print}
' "$app_module.tmp" > "$app_module"
rm "$app_module.tmp"
echo -e " ${GREEN}✅ Updated app.module.ts${NC}"
done
echo -e "\n${GREEN}✅ All modules updated!${NC}"