#!/usr/bin/env node const fs = require('fs'); const path = require('path'); const { execSync } = require('child_process'); console.log('šŸš€ CKEditor5 Migration Script'); console.log('============================\n'); // Check current setup const packageJsonPath = path.join(process.cwd(), 'package.json'); const vendorPath = path.join(process.cwd(), 'vendor', 'ckeditor5'); if (!fs.existsSync(packageJsonPath)) { console.error('āŒ package.json not found'); process.exit(1); } const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); const hasCustomBuild = fs.existsSync(vendorPath); const hasCKEditorReact = packageJson.dependencies && packageJson.dependencies['@ckeditor/ckeditor5-react']; console.log('šŸ“Š Current Setup Analysis:'); console.log(`- Custom CKEditor5 build: ${hasCustomBuild ? 'āœ… Found' : 'āŒ Not found'}`); console.log(`- CKEditor5 React: ${hasCKEditorReact ? 'āœ… Installed' : 'āŒ Not installed'}`); console.log(`- Bundle size: ${hasCustomBuild ? '~2.4MB' : 'Unknown'}\n`); // Show options console.log('šŸŽÆ Available Optimization Options:'); console.log('1. TinyMCE (Recommended) - 200KB bundle, 90% reduction'); console.log('2. CKEditor5 Classic - 800KB bundle, 67% reduction'); console.log('3. React Quill - 100KB bundle, 96% reduction'); console.log('4. Exit without changes\n'); // Get user choice const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.question('Choose your option (1-4): ', (choice) => { rl.close(); switch (choice.trim()) { case '1': migrateToTinyMCE(); break; case '2': migrateToCKEditorClassic(); break; case '3': migrateToReactQuill(); break; case '4': console.log('šŸ‘‹ Migration cancelled'); process.exit(0); default: console.log('āŒ Invalid choice'); process.exit(1); } }); function migrateToTinyMCE() { console.log('\nšŸ”„ Migrating to TinyMCE...'); try { // Remove old dependencies if (hasCKEditorReact) { console.log('šŸ“¦ Removing old CKEditor dependencies...'); execSync('npm uninstall @ckeditor/ckeditor5-react --legacy-peer-deps', { stdio: 'inherit' }); } // Install TinyMCE console.log('šŸ“¦ Installing TinyMCE...'); execSync('npm install @tinymce/tinymce-react --legacy-peer-deps', { stdio: 'inherit' }); // Remove custom build if (hasCustomBuild) { console.log('šŸ—‘ļø Removing custom CKEditor5 build...'); execSync('rm -rf vendor/ckeditor5', { stdio: 'inherit' }); } console.log('\nāœ… Migration to TinyMCE completed!'); console.log('šŸ“ Next steps:'); console.log('1. Update your editor components to use OptimizedEditor'); console.log('2. Test the new implementation'); console.log('3. Update any image upload handlers'); } catch (error) { console.error('āŒ Migration failed:', error.message); process.exit(1); } } function migrateToCKEditorClassic() { console.log('\nšŸ”„ Migrating to CKEditor5 Classic...'); try { // Remove custom build dependency if (packageJson.dependencies && packageJson.dependencies['ckeditor5-custom-build']) { console.log('šŸ“¦ Removing custom build dependency...'); execSync('npm uninstall ckeditor5-custom-build --legacy-peer-deps', { stdio: 'inherit' }); } // Install official builds console.log('šŸ“¦ Installing CKEditor5 Classic...'); execSync('npm install @ckeditor/ckeditor5-build-classic @ckeditor/ckeditor5-react --legacy-peer-deps', { stdio: 'inherit' }); // Remove custom build if (hasCustomBuild) { console.log('šŸ—‘ļø Removing custom CKEditor5 build...'); execSync('rm -rf vendor/ckeditor5', { stdio: 'inherit' }); } console.log('\nāœ… Migration to CKEditor5 Classic completed!'); console.log('šŸ“ Next steps:'); console.log('1. Update your editor components to use OptimizedCKEditor'); console.log('2. Test the new implementation'); console.log('3. Update any custom configurations'); } catch (error) { console.error('āŒ Migration failed:', error.message); process.exit(1); } } function migrateToReactQuill() { console.log('\nšŸ”„ Migrating to React Quill...'); try { // Remove old dependencies if (hasCKEditorReact) { console.log('šŸ“¦ Removing old CKEditor dependencies...'); execSync('npm uninstall @ckeditor/ckeditor5-react --legacy-peer-deps', { stdio: 'inherit' }); } // Install React Quill console.log('šŸ“¦ Installing React Quill...'); execSync('npm install react-quill --legacy-peer-deps', { stdio: 'inherit' }); // Remove custom build if (hasCustomBuild) { console.log('šŸ—‘ļø Removing custom CKEditor5 build...'); execSync('rm -rf vendor/ckeditor5', { stdio: 'inherit' }); } console.log('\nāœ… Migration to React Quill completed!'); console.log('šŸ“ Next steps:'); console.log('1. Update your editor components to use MinimalEditor'); console.log('2. Test the new implementation'); console.log('3. Adjust any advanced features to basic ones'); } catch (error) { console.error('āŒ Migration failed:', error.message); process.exit(1); } }