200 lines
7.1 KiB
JavaScript
200 lines
7.1 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { execSync } = require('child_process');
|
|
|
|
console.log('🚀 CKEditor5 Migration to Official Packages');
|
|
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'];
|
|
const hasCustomBuildDep = packageJson.dependencies && packageJson.dependencies['ckeditor5-custom-build'];
|
|
|
|
console.log('📊 Current Setup Analysis:');
|
|
console.log(`- Custom CKEditor5 build: ${hasCustomBuild ? '✅ Found' : '❌ Not found'}`);
|
|
console.log(`- CKEditor5 React: ${hasCKEditorReact ? '✅ Installed' : '❌ Not installed'}`);
|
|
console.log(`- Custom build dependency: ${hasCustomBuildDep ? '✅ Found' : '❌ Not found'}`);
|
|
console.log(`- Bundle size: ${hasCustomBuild ? '~2.4MB' : 'Unknown'}\n`);
|
|
|
|
// Show available official builds
|
|
console.log('🎯 Available Official CKEditor5 Builds:');
|
|
console.log('1. Classic Build - Full-featured editor (800KB)');
|
|
console.log('2. Decoupled Document - Document-style editor (1MB)');
|
|
console.log('3. Inline Build - Inline editing (600KB)');
|
|
console.log('4. Super Build - All features (1.5MB)');
|
|
console.log('5. 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 build (1-5): ', (choice) => {
|
|
rl.close();
|
|
|
|
switch (choice.trim()) {
|
|
case '1':
|
|
migrateToClassic();
|
|
break;
|
|
case '2':
|
|
migrateToDecoupled();
|
|
break;
|
|
case '3':
|
|
migrateToInline();
|
|
break;
|
|
case '4':
|
|
migrateToSuper();
|
|
break;
|
|
case '5':
|
|
console.log('👋 Migration cancelled');
|
|
process.exit(0);
|
|
default:
|
|
console.log('❌ Invalid choice');
|
|
process.exit(1);
|
|
}
|
|
});
|
|
|
|
function migrateToClassic() {
|
|
console.log('\n🔄 Migrating to CKEditor5 Classic Build...');
|
|
|
|
try {
|
|
// Remove custom build dependency
|
|
if (hasCustomBuildDep) {
|
|
console.log('📦 Removing custom build dependency...');
|
|
execSync('npm uninstall ckeditor5-custom-build', { stdio: 'inherit' });
|
|
}
|
|
|
|
// Install official classic build
|
|
console.log('📦 Installing CKEditor5 Classic Build...');
|
|
execSync('npm install @ckeditor/ckeditor5-build-classic', { stdio: 'inherit' });
|
|
|
|
// Remove custom build directory
|
|
if (hasCustomBuild) {
|
|
console.log('🗑️ Removing custom CKEditor5 build...');
|
|
execSync('rm -rf vendor/ckeditor5', { stdio: 'inherit' });
|
|
}
|
|
|
|
console.log('\n✅ Migration to Classic Build completed!');
|
|
console.log('📝 Next steps:');
|
|
console.log('1. Update your editor components to use ImprovedCKEditor');
|
|
console.log('2. Replace imports from "ckeditor5-custom-build" to "@ckeditor/ckeditor5-build-classic"');
|
|
console.log('3. Test the new implementation');
|
|
console.log('4. Update any custom configurations');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Migration failed:', error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
function migrateToDecoupled() {
|
|
console.log('\n🔄 Migrating to CKEditor5 Decoupled Document Build...');
|
|
|
|
try {
|
|
// Remove custom build dependency
|
|
if (hasCustomBuildDep) {
|
|
console.log('📦 Removing custom build dependency...');
|
|
execSync('npm uninstall ckeditor5-custom-build', { stdio: 'inherit' });
|
|
}
|
|
|
|
// Install official decoupled build
|
|
console.log('📦 Installing CKEditor5 Decoupled Document Build...');
|
|
execSync('npm install @ckeditor/ckeditor5-build-decoupled-document', { stdio: 'inherit' });
|
|
|
|
// Remove custom build directory
|
|
if (hasCustomBuild) {
|
|
console.log('🗑️ Removing custom CKEditor5 build...');
|
|
execSync('rm -rf vendor/ckeditor5', { stdio: 'inherit' });
|
|
}
|
|
|
|
console.log('\n✅ Migration to Decoupled Document Build completed!');
|
|
console.log('📝 Next steps:');
|
|
console.log('1. Update your editor components to use ImprovedCKEditor with features="document"');
|
|
console.log('2. Replace imports from "ckeditor5-custom-build" to "@ckeditor/ckeditor5-build-decoupled-document"');
|
|
console.log('3. Test the new implementation');
|
|
console.log('4. Update any custom configurations');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Migration failed:', error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
function migrateToInline() {
|
|
console.log('\n🔄 Migrating to CKEditor5 Inline Build...');
|
|
|
|
try {
|
|
// Remove custom build dependency
|
|
if (hasCustomBuildDep) {
|
|
console.log('📦 Removing custom build dependency...');
|
|
execSync('npm uninstall ckeditor5-custom-build', { stdio: 'inherit' });
|
|
}
|
|
|
|
// Install official inline build
|
|
console.log('📦 Installing CKEditor5 Inline Build...');
|
|
execSync('npm install @ckeditor/ckeditor5-build-inline', { stdio: 'inherit' });
|
|
|
|
// Remove custom build directory
|
|
if (hasCustomBuild) {
|
|
console.log('🗑️ Removing custom CKEditor5 build...');
|
|
execSync('rm -rf vendor/ckeditor5', { stdio: 'inherit' });
|
|
}
|
|
|
|
console.log('\n✅ Migration to Inline Build completed!');
|
|
console.log('📝 Next steps:');
|
|
console.log('1. Update your editor components to use ImprovedCKEditor with features="inline"');
|
|
console.log('2. Replace imports from "ckeditor5-custom-build" to "@ckeditor/ckeditor5-build-inline"');
|
|
console.log('3. Test the new implementation');
|
|
console.log('4. Update any custom configurations');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Migration failed:', error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
function migrateToSuper() {
|
|
console.log('\n🔄 Migrating to CKEditor5 Super Build...');
|
|
|
|
try {
|
|
// Remove custom build dependency
|
|
if (hasCustomBuildDep) {
|
|
console.log('📦 Removing custom build dependency...');
|
|
execSync('npm uninstall ckeditor5-custom-build', { stdio: 'inherit' });
|
|
}
|
|
|
|
// Install official super build
|
|
console.log('📦 Installing CKEditor5 Super Build...');
|
|
execSync('npm install @ckeditor/ckeditor5-build-super-build', { stdio: 'inherit' });
|
|
|
|
// Remove custom build directory
|
|
if (hasCustomBuild) {
|
|
console.log('🗑️ Removing custom CKEditor5 build...');
|
|
execSync('rm -rf vendor/ckeditor5', { stdio: 'inherit' });
|
|
}
|
|
|
|
console.log('\n✅ Migration to Super Build completed!');
|
|
console.log('📝 Next steps:');
|
|
console.log('1. Update your editor components to use ImprovedCKEditor with features="full"');
|
|
console.log('2. Replace imports from "ckeditor5-custom-build" to "@ckeditor/ckeditor5-build-super-build"');
|
|
console.log('3. Test the new implementation');
|
|
console.log('4. Update any custom configurations');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Migration failed:', error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|