UNPKG

wordlift-cli

Version:

WordLift CLI - Your AI SEO Assistant powered by Google Gemini. Agentic SEO workflows with Agent Skills support, WordLift MCP integration, knowledge graphs, and intelligent content optimization for modern content creators.

177 lines (148 loc) • 5.62 kB
#!/usr/bin/env node /** * Patch script to replace Gemini ASCII art with WordLift branding */ const fs = require('fs'); const path = require('path'); const os = require('os'); const { execSync } = require('child_process'); console.log('šŸ” Starting WordLift ASCII art patch script...'); // WordLift ASCII art const WORDLIFT_ASCII = ` ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆā–ˆ ā–ˆā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ `; // Find all Gemini CLI installation paths function findGeminiInstallations() { console.log('šŸ” Searching for Gemini CLI installations...'); const paths = []; // Use find command to search for all AsciiArt.js files in gemini packages try { const homeDir = os.homedir(); // Search in common package manager directories const searchDirs = [ path.join(homeDir, 'Library/pnpm'), path.join(homeDir, '.nvm'), path.join(homeDir, '.npm'), '/usr/local/lib', '/opt' ]; for (const searchDir of searchDirs) { if (fs.existsSync(searchDir)) { const findCommand = `find "${searchDir}" -name "AsciiArt.js" -path "*gemini*" 2>/dev/null`; console.log(`Searching in: ${searchDir}`); try { const findResults = execSync(findCommand, { encoding: 'utf8' }).trim(); if (findResults) { const foundPaths = findResults.split('\n').filter(p => p.trim()); console.log(`Found ${foundPaths.length} files in ${searchDir}`); paths.push(...foundPaths); } } catch (err) { console.log(`Search failed in ${searchDir}: ${err.message}`); } } } } catch (error) { console.log('Find command failed:', error.message); } // Try to find installations using npm global root try { console.log('Checking npm global root...'); const npmRoot = execSync('npm root -g', { encoding: 'utf8' }).trim(); const npmPaths = [ path.join(npmRoot, '@google/gemini-cli/dist/src/ui/components/AsciiArt.js'), path.join(npmRoot, '@gemini-cli/cli/dist/src/ui/components/AsciiArt.js'), ]; for (const p of npmPaths) { if (fs.existsSync(p)) { console.log(`Found via npm root: ${p}`); paths.push(p); } } } catch (error) { console.log('Could not find npm global root:', error.message); } return [...new Set(paths)]; // Remove duplicates } function applyPatch(filePath) { try { console.log(`šŸ“ Reading file: ${filePath}`); const content = fs.readFileSync(filePath, 'utf8'); // Check if already patched if (content.includes('ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ')) { console.log(`āœ… Already patched: ${filePath}`); return true; } console.log(`šŸ”§ Applying patch to: ${filePath}`); // Create backup const backupPath = filePath + '.wordlift-backup'; if (!fs.existsSync(backupPath)) { fs.copyFileSync(filePath, backupPath); console.log(`šŸ’¾ Created backup: ${backupPath}`); } // Apply patch - replace both short and long ASCII logos let patched = content .replace(/export const shortAsciiLogo = `[\s\S]*?`;/g, `export const shortAsciiLogo = \`${WORDLIFT_ASCII}\`;`) .replace(/export const longAsciiLogo = `[\s\S]*?`;/g, `export const longAsciiLogo = \`${WORDLIFT_ASCII}\`;`); fs.writeFileSync(filePath, patched); console.log(`āœ… Patch applied successfully: ${filePath}`); return true; } catch (error) { console.log(`āŒ Failed to patch: ${filePath} - ${error.message}`); return false; } } function restorePatch(filePath) { try { const backupPath = filePath + '.wordlift-backup'; if (fs.existsSync(backupPath)) { fs.copyFileSync(backupPath, filePath); console.log(`āœ… Original restored: ${filePath}`); return true; } else { console.log(`āŒ No backup found: ${filePath}`); return false; } } catch (error) { console.log(`āŒ Failed to restore: ${filePath} - ${error.message}`); return false; } } // Main execution const isRestore = process.argv.includes('--restore'); if (isRestore) { console.log('šŸ”„ Restore mode activated'); } else { console.log('šŸ”§ Patch mode activated'); } const installations = findGeminiInstallations(); if (installations.length === 0) { console.log('āŒ No Gemini CLI installations found'); process.exit(1); } console.log(`šŸ“¦ Found ${installations.length} Gemini CLI installation(s):`); installations.forEach(filePath => console.log(` ${filePath}`)); console.log(''); let successCount = 0; for (const installation of installations) { console.log(`šŸ”§ Processing: ${installation}`); if (isRestore) { if (restorePatch(installation)) successCount++; } else { if (applyPatch(installation)) successCount++; } } console.log(''); if (isRestore) { console.log(`šŸŽÆ Restored ${successCount}/${installations.length} installations`); } else { console.log(`šŸŽÆ Patched ${successCount}/${installations.length} installations`); } console.log('✨ Script completed!'); if (successCount === 0) { process.exit(1); }