Files
scripts/dbis/automate-dbis-migration.sh
2026-02-09 21:51:52 -08:00

138 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
# Load shared libraries
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../lib/init.sh"
# Automated script to help migrate DBIS projects to monorepo
set -e
PROJECT_NAME="${1:-}"
MONOREPO_PATH="${2:-dbis_monorepo}"
TARGET_DIR="${3:-packages}"
if [ -z "$PROJECT_NAME" ]; then
echo "📦 DBIS Project Migration Automation"
echo ""
echo "Usage: $0 <project-name> [monorepo-path] [target-dir]"
echo ""
echo "Example: $0 dbis_core dbis_monorepo packages"
echo ""
echo "This script automates the migration of a DBIS project to the monorepo."
exit 1
fi
SOURCE_PATH="../${PROJECT_NAME}"
TARGET_PATH="${MONOREPO_PATH}/${TARGET_DIR}/${PROJECT_NAME}"
echo "📦 Migrating $PROJECT_NAME to DBIS monorepo..."
# Check if source project exists
if [ ! -d "$SOURCE_PATH" ]; then
echo "❌ Source project not found: $SOURCE_PATH"
exit 1
fi
# Check if monorepo exists
if [ ! -d "$MONOREPO_PATH" ]; then
echo "❌ Monorepo not found: $MONOREPO_PATH"
exit 1
fi
# Create target directory
echo "📁 Creating target directory..."
mkdir -p "$TARGET_PATH"
# Copy project files (excluding node_modules, .git, etc.)
echo "📋 Copying project files..."
rsync -av --exclude='node_modules' \
--exclude='.git' \
--exclude='dist' \
--exclude='build' \
--exclude='.next' \
--exclude='coverage' \
--exclude='.turbo' \
"$SOURCE_PATH/" "$TARGET_PATH/"
# Update package.json
if [ -f "$TARGET_PATH/package.json" ]; then
echo "📝 Updating package.json..."
# Create backup
cp "$TARGET_PATH/package.json" "$TARGET_PATH/package.json.bak"
# Update package name
if command -v jq &> /dev/null; then
jq ".name = \"@dbis/${PROJECT_NAME}\"" "$TARGET_PATH/package.json" > "$TARGET_PATH/package.json.tmp"
mv "$TARGET_PATH/package.json.tmp" "$TARGET_PATH/package.json"
else
echo "⚠️ jq not found, please manually update package.json name to @dbis/${PROJECT_NAME}"
fi
# Update dependencies to use workspace packages
echo "📝 Updating dependencies to use workspace packages..."
# This would need more sophisticated logic, but provides guidance
echo " → Review and update dependencies to use @dbis/* and @workspace/* packages"
fi
# Create migration notes
cat > "$TARGET_PATH/MIGRATION_NOTES.md" << EOF
# Migration Notes for ${PROJECT_NAME}
**Migrated**: $(date)
**Source**: ${SOURCE_PATH}
**Target**: ${TARGET_PATH}
## Changes Made
1. Project copied to monorepo
2. Package name updated to @dbis/${PROJECT_NAME}
3. Dependencies need manual review
## Next Steps
1. Review and update package.json dependencies:
- Replace local packages with @dbis/* packages
- Replace common packages with @workspace/* packages
2. Update imports:
- Update relative imports
- Use @dbis/* and @workspace/* packages
3. Update CI/CD:
- Remove individual CI/CD configs
- Use monorepo CI/CD
4. Test:
- Run \`pnpm install\` in monorepo root
- Run \`pnpm build\` to verify build
- Run \`pnpm test\` to verify tests
5. Update documentation:
- Update README
- Update any project-specific docs
## Verification
- [ ] Package.json updated
- [ ] Dependencies updated
- [ ] Imports updated
- [ ] Build successful
- [ ] Tests passing
- [ ] Documentation updated
EOF
echo "✅ Migration automation complete!"
echo ""
echo "📝 Project copied to: $TARGET_PATH"
echo "📝 Migration notes created: $TARGET_PATH/MIGRATION_NOTES.md"
echo ""
echo "📋 Next steps:"
echo " 1. Review $TARGET_PATH/MIGRATION_NOTES.md"
echo " 2. Update package.json dependencies"
echo " 3. Update imports"
echo " 4. Test build and tests"
echo " 5. Update documentation"