migrate-project-structure.shā¢9.77 kB
#!/bin/bash
# EuConquisto Composer MCP - Project Structure Migration Script
# This script safely reorganizes the project following best practices
set -e # Exit on any error
PROJECT_ROOT="/Users/ricardokawasaki/Desktop/euconquisto-composer-mcp-poc"
BACKUP_DIR="${PROJECT_ROOT}_backup_$(date +%Y%m%d_%H%M%S)"
MIGRATION_LOG="${PROJECT_ROOT}/migration.log"
echo "š EuConquisto Composer MCP - Project Reorganization"
echo "=================================================="
echo "š Project: $PROJECT_ROOT"
echo "š¾ Backup: $BACKUP_DIR"
echo "š Log: $MIGRATION_LOG"
echo ""
# Initialize log
echo "Migration started at $(date)" > "$MIGRATION_LOG"
# Function to log and execute
log_and_do() {
echo "š $1" | tee -a "$MIGRATION_LOG"
eval "$2"
}
# Function to create directory if it doesn't exist
ensure_dir() {
if [ ! -d "$1" ]; then
mkdir -p "$1"
echo "ā
Created directory: $1" | tee -a "$MIGRATION_LOG"
fi
}
# Phase 1: Backup and Preparation
echo "š Phase 1: Creating Backup and Preparing Structure"
echo "=================================================="
log_and_do "Creating full project backup" "cp -r '$PROJECT_ROOT' '$BACKUP_DIR'"
cd "$PROJECT_ROOT"
# Initialize git if not already initialized
if [ ! -d ".git" ]; then
log_and_do "Initializing git repository" "git init"
log_and_do "Adding initial commit" "git add -A && git commit -m 'Pre-reorganization snapshot'"
else
log_and_do "Creating pre-migration commit" "git add -A && git commit -m 'Pre-reorganization snapshot' || true"
fi
# Tag current state
log_and_do "Tagging current state" "git tag v4.0.3-pre-reorganization || true"
# Create new directory structure
echo ""
echo "š Creating Clean Directory Structure"
echo "===================================="
# Create main directories
ensure_dir "bin"
ensure_dir "config"
ensure_dir "archive/legacy"
ensure_dir "logs"
ensure_dir "temp"
# src/ already exists, but ensure subdirectories
ensure_dir "src/server"
ensure_dir "src/content"
ensure_dir "src/browser"
ensure_dir "src/auth"
ensure_dir "src/types"
ensure_dir "src/utils"
# tests/ already exists, ensure proper structure
ensure_dir "tests/unit"
ensure_dir "tests/integration"
ensure_dir "tests/e2e"
# Phase 2: File Migration
echo ""
echo "š¦ Phase 2: Migrating Files"
echo "========================="
# Migrate executable scripts to bin/
echo "š Migrating executable scripts to bin/"
for script in start-*.sh; do
if [ -f "$script" ]; then
log_and_do "Moving $script to bin/" "mv '$script' bin/"
fi
done
# Migrate configuration files to config/
echo "š Migrating configuration files to config/"
if [ -f "claude-desktop-config.json" ]; then
log_and_do "Moving main claude-desktop config" "mv claude-desktop-config.json config/"
fi
if [ -f "claude-desktop-config-working.json" ]; then
log_and_do "Moving working claude-desktop config" "mv claude-desktop-config-working.json config/claude-desktop-working.json"
fi
# Archive versioned configuration files
echo "š Archiving versioned configuration files"
for config in claude-desktop-config-*.json; do
if [ -f "$config" ] && [[ "$config" != "claude-desktop-config-working.json" ]]; then
log_and_do "Archiving $config" "mv '$config' archive/legacy/"
fi
done
# Archive versioned implementation files from dist/
echo "š Archiving versioned implementation files"
if [ -d "dist" ]; then
for impl in dist/*-v*.js dist/*-fixed.js dist/*-clean.js dist/*-BACKUP.js; do
if [ -f "$impl" ]; then
filename=$(basename "$impl")
log_and_do "Archiving $filename" "mv '$impl' archive/legacy/"
fi
done
fi
# Archive versioned TypeScript files from src/
echo "š Archiving versioned TypeScript files"
for ts_file in src/*-v*.ts src/*-fixed.ts src/*-clean.ts src/*-backup.ts; do
if [ -f "$ts_file" ]; then
filename=$(basename "$ts_file")
log_and_do "Archiving $filename" "mv '$ts_file' archive/legacy/"
fi
done
# Move test files from root to tests/
echo "š Moving test files to tests/"
for test_file in test-*.js test-*.json; do
if [ -f "$test_file" ]; then
log_and_do "Moving $test_file to tests/" "mv '$test_file' tests/"
fi
done
# Move composition files to archive (these are examples/outputs)
echo "š Moving composition files to archive"
for comp_file in *composition*.js *composition*.json; do
if [ -f "$comp_file" ]; then
log_and_do "Moving $comp_file to archive/" "mv '$comp_file' archive/"
fi
done
# Move debug files and screenshots to logs/ (they'll be gitignored)
echo "š Moving debug files to logs/"
for debug_file in debug-*.png *.webm; do
if [ -f "$debug_file" ]; then
log_and_do "Moving $debug_file to logs/" "mv '$debug_file' logs/"
fi
done
# Archive old directories that are poorly organized
echo "š Archiving old directories"
for old_dir in dist-clean dist-test fixes integration preview; do
if [ -d "$old_dir" ]; then
log_and_do "Archiving directory $old_dir" "mv '$old_dir' archive/"
fi
done
# Move miscellaneous files to appropriate locations
echo "š Organizing miscellaneous files"
if [ -f "final-validation-test.js" ]; then
log_and_do "Moving final validation test" "mv final-validation-test.js tests/"
fi
if [ -f "create-ballistics-lesson.js" ]; then
log_and_do "Moving ballistics lesson to archive" "mv create-ballistics-lesson.js archive/"
fi
if [ -f "project.json" ]; then
log_and_do "Moving project.json to config/" "mv project.json config/"
fi
# Archive multiple documentation files in root
echo "š Archiving duplicate documentation files"
for doc_file in CLAUDE-DESKTOP-*.md MIGRATION-STATUS.md PRODUCTION-READY.md PROJECT-ORGANIZATION.md REFERENCE-FIXES.md; do
if [ -f "$doc_file" ]; then
log_and_do "Archiving $doc_file" "mv '$doc_file' archive/"
fi
done
# Phase 3: Create proper .gitignore
echo ""
echo "š« Phase 3: Creating .gitignore"
echo "==============================="
cat > .gitignore << 'EOF'
# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Build outputs
dist/
build/
# Runtime data
logs/
*.log
temp/
*.tmp
# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
# IDE files
.vscode/
.idea/
*.swp
*.swo
*~
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Debug files
debug-*.png
*.webm
screenshots/
# Test outputs
coverage/
.nyc_output/
# Temporary test files
test-composition-*.json
*-temp.*
# Browser automation artifacts
playwright-report/
test-results/
# JWT tokens (security)
*jwt*.txt
*.pem
*.key
# Backup files
*-backup.*
*.backup
EOF
log_and_do "Created .gitignore" "echo '.gitignore created'"
# Phase 4: Update package.json
echo ""
echo "āļø Phase 4: Updating package.json"
echo "================================="
# Create backup of package.json
cp package.json package.json.backup
# Update main entry point to use working implementation
log_and_do "Updating package.json main entry" "sed -i.bak 's|\"main\": \".*\"|\"main\": \"dist/browser-automation-api-direct-save-v4.0.3.js\"|' package.json"
# Update scripts to use bin/ directory
log_and_do "Updating package.json scripts" "sed -i.bak 's|start-|bin/start-|g' package.json"
# Phase 5: Update configuration files
echo ""
echo "š§ Phase 5: Updating Configuration Files"
echo "======================================="
# Update Claude Desktop config to use bin/start-working-implementation.sh
if [ -f "config/claude-desktop-config-working.json" ]; then
log_and_do "Updating Claude Desktop config path" "sed -i.bak 's|/start-working-implementation.sh|/bin/start-working-implementation.sh|' config/claude-desktop-config-working.json"
fi
# Phase 6: Git commit reorganized structure
echo ""
echo "š¾ Phase 6: Committing Reorganized Structure"
echo "==========================================="
# Add all changes
log_and_do "Staging reorganized files" "git add -A"
# Commit reorganization
log_and_do "Committing reorganization" "git commit -m 'feat: reorganize project structure following best practices
- Move executable scripts to bin/
- Move configurations to config/
- Archive versioned files to archive/legacy/
- Create proper .gitignore
- Update package.json entry points
- Organize files by purpose and maintainability
Refs: PROJECT_REORGANIZATION_PLAN.md'"
# Tag the reorganized version
log_and_do "Tagging reorganized version" "git tag v4.1.0-reorganized"
# Phase 7: Cleanup and Verification
echo ""
echo "ā
Phase 7: Cleanup and Verification"
echo "=================================="
# Remove backup files created during sed operations
rm -f package.json.bak config/*.bak 2>/dev/null || true
# Create summary
echo ""
echo "š Reorganization Summary"
echo "========================"
echo "ā
Backup created: $BACKUP_DIR"
echo "ā
Files archived: $(find archive/legacy -type f | wc -l) files"
echo "ā
Configuration files organized: $(find config -type f | wc -l) files"
echo "ā
Executable scripts in bin/: $(find bin -type f | wc -l) files"
echo "ā
Git tags created: v4.0.3-pre-reorganization, v4.1.0-reorganized"
echo "ā
.gitignore created with proper exclusions"
echo ""
echo "š Project reorganization completed successfully!"
echo "š Full log available at: $MIGRATION_LOG"
echo ""
echo "š Next Steps:"
echo "1. Test the reorganized structure with: bin/start-working-implementation.sh"
echo "2. Update Claude Desktop config to use: config/claude-desktop-working.json"
echo "3. Verify all functionality works as expected"
echo "4. Remove backup directory after verification: rm -rf '$BACKUP_DIR'"
echo ""
echo "Migration completed at $(date)" >> "$MIGRATION_LOG"