#!/usr/bin/env node const fs = require('fs'); const path = require('path'); const readline = require('readline'); console.log('šŸ”‘ TinyMCE API Key Setup'); console.log('========================\n'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); // Check if .env.local exists const envPath = path.join(process.cwd(), '.env.local'); const envExists = fs.existsSync(envPath); console.log('šŸ“‹ Current Status:'); console.log(`- .env.local file: ${envExists ? 'āœ… Found' : 'āŒ Not found'}`); if (envExists) { const envContent = fs.readFileSync(envPath, 'utf8'); const hasApiKey = envContent.includes('NEXT_PUBLIC_TINYMCE_API_KEY'); console.log(`- API key configured: ${hasApiKey ? 'āœ… Yes' : 'āŒ No'}`); } console.log('\nšŸŽÆ Setup Options:'); console.log('1. Add API key to .env.local'); console.log('2. Create new .env.local file'); console.log('3. Check current configuration'); console.log('4. Exit\n'); rl.question('Choose an option (1-4): ', (choice) => { switch (choice.trim()) { case '1': addApiKeyToEnv(); break; case '2': createNewEnvFile(); break; case '3': checkConfiguration(); break; case '4': console.log('šŸ‘‹ Setup cancelled'); rl.close(); break; default: console.log('āŒ Invalid choice'); rl.close(); } }); function addApiKeyToEnv() { rl.question('\nšŸ”‘ Enter your TinyMCE API key: ', (apiKey) => { if (!apiKey.trim()) { console.log('āŒ API key cannot be empty'); rl.close(); return; } try { let envContent = ''; if (envExists) { envContent = fs.readFileSync(envPath, 'utf8'); // Check if API key already exists if (envContent.includes('NEXT_PUBLIC_TINYMCE_API_KEY')) { // Replace existing key envContent = envContent.replace( /NEXT_PUBLIC_TINYMCE_API_KEY=.*/g, `NEXT_PUBLIC_TINYMCE_API_KEY=${apiKey}` ); } else { // Add new key envContent += `\nNEXT_PUBLIC_TINYMCE_API_KEY=${apiKey}`; } } else { envContent = `NEXT_PUBLIC_TINYMCE_API_KEY=${apiKey}`; } fs.writeFileSync(envPath, envContent); console.log('āœ… API key added to .env.local'); console.log('šŸ”„ Please restart your development server'); } catch (error) { console.error('āŒ Error writing to .env.local:', error.message); } rl.close(); }); } function createNewEnvFile() { rl.question('\nšŸ”‘ Enter your TinyMCE API key: ', (apiKey) => { if (!apiKey.trim()) { console.log('āŒ API key cannot be empty'); rl.close(); return; } try { const envContent = `# TinyMCE Configuration NEXT_PUBLIC_TINYMCE_API_KEY=${apiKey} # Other environment variables can be added here `; fs.writeFileSync(envPath, envContent); console.log('āœ… Created .env.local with API key'); console.log('šŸ”„ Please restart your development server'); } catch (error) { console.error('āŒ Error creating .env.local:', error.message); } rl.close(); }); } function checkConfiguration() { console.log('\nšŸ“Š Configuration Check:'); // Check .env.local if (envExists) { const envContent = fs.readFileSync(envPath, 'utf8'); const apiKeyMatch = envContent.match(/NEXT_PUBLIC_TINYMCE_API_KEY=(.+)/); if (apiKeyMatch) { const apiKey = apiKeyMatch[1]; const maskedKey = apiKey.substring(0, 8) + '...' + apiKey.substring(apiKey.length - 4); console.log(`āœ… API key found: ${maskedKey}`); } else { console.log('āŒ API key not found in .env.local'); } } else { console.log('āŒ .env.local file not found'); } // Check package.json const packagePath = path.join(process.cwd(), 'package.json'); if (fs.existsSync(packagePath)) { const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8')); const hasTinyMCE = packageJson.dependencies && packageJson.dependencies['@tinymce/tinymce-react']; console.log(`āœ… TinyMCE package: ${hasTinyMCE ? 'Installed' : 'Not installed'}`); } // Check editor components const editorPath = path.join(process.cwd(), 'components', 'editor'); if (fs.existsSync(editorPath)) { const files = fs.readdirSync(editorPath); const editorFiles = files.filter(file => file.includes('editor')); console.log(`āœ… Editor components: ${editorFiles.length} found`); } console.log('\nšŸ“ Next steps:'); console.log('1. Get API key from https://www.tiny.cloud/auth/signup/'); console.log('2. Add to .env.local file'); console.log('3. Restart development server'); console.log('4. Test editor functionality'); rl.close(); }