update-file-references.shโข10.3 kB
#!/bin/bash
# EuConquisto Composer MCP - Comprehensive File Reference Update Script
# This script updates ALL inter-file references after reorganization
set -e
PROJECT_ROOT="/Users/ricardokawasaki/Desktop/euconquisto-composer-mcp-poc"
UPDATE_LOG="${PROJECT_ROOT}/reference-updates.log"
cd "$PROJECT_ROOT"
echo "๐ EuConquisto Composer MCP - Comprehensive Reference Updates"
echo "============================================================"
echo "๐ Log: $UPDATE_LOG"
echo ""
# Initialize log
echo "Reference updates started at $(date)" > "$UPDATE_LOG"
# Function to log and update
log_and_update() {
echo "๐ $1" | tee -a "$UPDATE_LOG"
eval "$2"
}
# Function to update file with backup
update_file() {
local file="$1"
local description="$2"
if [ -f "$file" ]; then
# Create backup
cp "$file" "${file}.ref-backup"
# Apply all the sed commands passed as additional arguments
shift 2
for sed_cmd in "$@"; do
eval "sed -i.tmp '$sed_cmd' '$file'"
rm -f "${file}.tmp"
done
echo "โ
Updated: $file ($description)" | tee -a "$UPDATE_LOG"
else
echo "โ ๏ธ File not found: $file" | tee -a "$UPDATE_LOG"
fi
}
# Phase 1: Update TypeScript/JavaScript Import Statements
echo "๐ฆ Phase 1: Updating Import/Require Statements"
echo "=============================================="
# Update relative imports in src/ files that reference other src/ files
find src -name "*.ts" -o -name "*.js" | while read -r file; do
if grep -q "from ['\"]\./" "$file" || grep -q "require(['\"]\./" "$file"; then
# Since we're not moving files within src/, most imports should still work
# But update any references to moved directories
update_file "$file" "Import statements" \
"s|from ['\"]\.\/lib\/|from \"./lib/|g" \
"s|from ['\"]\.\/interfaces\/|from \"./interfaces/|g" \
"s|from ['\"]\.\/utils\/|from \"./utils/|g"
fi
done
# Phase 2: Update Package.json References
echo "โ๏ธ Phase 2: Updating Package.json References"
echo "============================================="
update_file "package.json" "Main entry and scripts" \
"s|\"main\": \"dist/browser-automation-api-direct-save-v4.0.3-FIXED.js\"|\"main\": \"dist/browser-automation-api-direct-save-v4.0.3.js\"|" \
"s|\"mcp:start\": \"node --max-old-space-size=4096 dist/index.js\"|\"mcp:start\": \"node --max-old-space-size=4096 dist/index.js\"|" \
"s|\"jwt:server\": \"node tools/servers/jwt-redirect-server-v1.0.2.js\"|\"jwt:server\": \"node tools/servers/jwt-redirect-server-v1.0.2.js\"|" \
"s|\"mcp:browser-automation\": \"node --loader ts-node/esm src/browser-automation-mcp-server.ts\"|\"mcp:browser-automation\": \"node --loader ts-node/esm src/browser-automation-mcp-server.ts\"|" \
"s|\"start:all\": \"npm run jwt:server & npm run mcp:browser-automation\"|\"start:all\": \"npm run jwt:server & npm run mcp:browser-automation\"|"
# Phase 3: Update Shell Scripts References
echo "๐ง Phase 3: Updating Shell Script References"
echo "============================================"
# Update all shell scripts in root that reference files
for script in *.sh; do
if [ -f "$script" ]; then
update_file "$script" "Shell script paths" \
"s|node dist/|node dist/|g" \
"s|npx tsx src/|npx tsx src/|g" \
"s|node tools/servers/|node tools/servers/|g"
fi
done
# Update shell scripts in bin/ directory
if [ -d "bin" ]; then
for script in bin/*.sh; do
if [ -f "$script" ]; then
update_file "$script" "Bin script paths" \
"s|node dist/|node ../dist/|g" \
"s|npx tsx src/|npx tsx ../src/|g" \
"s|node tools/servers/|node ../tools/servers/|g" \
"s|tools/servers/jwt-redirect-server-v1.0.2.js|../tools/servers/jwt-redirect-server-v1.0.2.js|g"
fi
done
fi
# Phase 4: Update Configuration Files
echo "๐ง Phase 4: Updating Configuration Files"
echo "======================================="
# Update Claude Desktop configurations
for config in config/*.json; do
if [ -f "$config" ]; then
update_file "$config" "Claude Desktop config" \
"s|/start-working-implementation.sh|/bin/start-working-implementation.sh|g" \
"s|/start-mcp-|/bin/start-mcp-|g" \
"s|\"command\": \"/|\"command\": \"/|g"
fi
done
# Update any remaining config files in docs/ (if they exist)
for config in docs/claude-desktop-config*.json; do
if [ -f "$config" ]; then
update_file "$config" "Legacy config in docs" \
"s|/dist/browser-automation-|/dist/browser-automation-|g" \
"s|/src/|/src/|g"
fi
done
# Phase 5: Update Tool Scripts
echo "๐จ Phase 5: Updating Tool Scripts"
echo "================================"
# Update validation and debugging tools
for tool in tools/**/*.js tools/**/*.ts tools/*.js; do
if [ -f "$tool" ]; then
update_file "$tool" "Tool script references" \
"s|import.*from.*'\.\/dist\/|import.*from.*'../../dist/|g" \
"s|require.*'\.\/dist\/|require('../../dist/|g" \
"s|import.*from.*'\.\/src\/|import.*from.*'../../src/|g" \
"s|require.*'\.\/src\/|require('../../src/|g"
fi
done
# Update specific tools with hardcoded paths
if [ -f "tools/validate-mcp-server.js" ]; then
update_file "tools/validate-mcp-server.js" "MCP server validation" \
"s|dist/index.js|../dist/index.js|g" \
"s|dist/core/|../dist/core/|g" \
"s|src/index.ts|../src/index.ts|g" \
"s|src/core/|../src/core/|g" \
"s|src/interfaces/|../src/interfaces/|g"
fi
# Phase 6: Update Test Files
echo "๐งช Phase 6: Updating Test File References"
echo "========================================="
# Update test files that import from src/
for test in tests/**/*.js tests/**/*.ts tests/*.js tests/*.ts; do
if [ -f "$test" ]; then
update_file "$test" "Test file imports" \
"s|import.*from.*'\.\.\/src\/|import.*from.*'../src/|g" \
"s|require.*'\.\.\/src\/|require('../src/|g" \
"s|import.*from.*'\.\.\/dist\/|import.*from.*'../dist/|g" \
"s|require.*'\.\.\/dist\/|require('../dist/|g"
fi
done
# Phase 7: Update Documentation References
echo "๐ Phase 7: Updating Documentation References"
echo "============================================="
# Update markdown files with file structure references
for doc in docs/**/*.md *.md; do
if [ -f "$doc" ] && [ "$doc" != "reference-updates.log" ]; then
update_file "$doc" "Documentation file references" \
"s|\`src/|\`src/|g" \
"s|\`dist/|\`dist/|g" \
"s|\`bin/|\`bin/|g" \
"s|\`config/|\`config/|g" \
"s|/src/|/src/|g" \
"s|/dist/|/dist/|g" \
"s|start-working-implementation.sh|bin/start-working-implementation.sh|g"
fi
done
# Phase 8: Update TypeScript Configuration
echo "๐ Phase 8: Updating TypeScript Configuration"
echo "============================================="
update_file "tsconfig.json" "TypeScript configuration" \
"s|\"rootDir\": \"\.\/src\"|\"rootDir\": \"./src\"|g" \
"s|\"outDir\": \"\.\/dist\"|\"outDir\": \"./dist\"|g" \
"s|\"include\": \[\"src\/\*\*\/\*\"\]|\"include\": [\"src/**/*\"]|g"
# Phase 9: Update Project-Specific Files
echo "๐ฏ Phase 9: Updating Project-Specific Files"
echo "==========================================="
# Update any remaining project files with hardcoded paths
if [ -f "project.json" ]; then
update_file "project.json" "Project configuration" \
"s|\"src\": \"src\/\"|\"src\": \"src/\"|g" \
"s|\"dist\": \"dist\/\"|\"dist\": \"dist/\"|g"
fi
# Update this migration script itself for consistency
update_file "migrate-project-structure.sh" "Migration script references" \
"s|bin/start-working-implementation.sh|bin/start-working-implementation.sh|g" \
"s|config/claude-desktop-working.json|config/claude-desktop-working.json|g"
# Phase 10: Validate Critical References
echo "โ
Phase 10: Validating Critical References"
echo "=========================================="
echo "Checking critical file references..."
# Check if main entry point exists
main_entry=$(node -p "require('./package.json').main" 2>/dev/null)
if [ -f "$main_entry" ]; then
echo "โ
Package.json main entry point exists: $main_entry"
else
echo "โ Package.json main entry point missing: $main_entry"
fi
# Check if Claude Desktop config references valid paths
for config in config/*.json; do
if [ -f "$config" ]; then
command_path=$(jq -r '.mcpServers[].command' "$config" 2>/dev/null)
if [ -f "$command_path" ]; then
echo "โ
Claude Desktop config references valid path: $command_path"
else
echo "โ Claude Desktop config references invalid path: $command_path"
fi
fi
done
# Check if startup scripts exist and are executable
for script in bin/*.sh; do
if [ -f "$script" ]; then
if [ -x "$script" ]; then
echo "โ
Startup script is executable: $script"
else
echo "โ Startup script not executable: $script"
fi
fi
done
# Phase 11: Clean Up Backup Files
echo "๐งน Phase 11: Cleaning Up Backup Files"
echo "===================================="
# Remove temporary backup files (keep .ref-backup for safety)
find . -name "*.tmp" -delete 2>/dev/null || true
echo "โ
Temporary files cleaned up"
# Phase 12: Summary Report
echo ""
echo "๐ Reference Update Summary"
echo "=========================="
updated_files=$(find . -name "*.ref-backup" | wc -l)
echo "โ
Files updated: $updated_files"
echo "โ
Backup files created: $updated_files (.ref-backup)"
echo "โ
Log file: $UPDATE_LOG"
echo ""
echo "๐ Reference updates completed successfully!"
echo "๐ Full log available at: $UPDATE_LOG"
echo ""
echo "โ ๏ธ IMPORTANT: Test all functionality before removing backup files"
echo "๐ To revert changes: rename .ref-backup files back to original names"
echo "๐งน To clean backups after testing: find . -name '*.ref-backup' -delete"
echo ""
echo "Reference updates completed at $(date)" >> "$UPDATE_LOG"