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
JavaScript
/**
* 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);
}