mediahub-fe/scripts/migrate-editor.js

158 lines
5.2 KiB
JavaScript

#!/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);
}
}