@clyde-code-ai/clyde-code
Version:
A CLI AI code assistant.
117 lines (101 loc) • 3.33 kB
JavaScript
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
const os = require('os');
function runCommand(command, args, options = {}) {
return new Promise((resolve, reject) => {
const child = spawn(command, args, { stdio: 'pipe', ...options });
let stdout = '';
let stderr = '';
child.stdout?.on('data', (data) => stdout += data);
child.stderr?.on('data', (data) => stderr += data);
child.on('close', (code) => {
resolve({ code, stdout, stderr });
});
});
}
async function uninstallWithPipx() {
try {
const result = await runCommand('pipx', ['uninstall', 'clyde-code']);
return result.code === 0;
} catch {
return false;
}
}
async function uninstallWithUv() {
try {
const result = await runCommand('uv', ['tool', 'uninstall', 'clyde-code']);
return result.code === 0;
} catch {
return false;
}
}
async function uninstallWithPip() {
try {
const result = await runCommand('pip', ['uninstall', '-y', 'clyde-code']);
return result.code === 0;
} catch {
return false;
}
}
async function main() {
console.log('Uninstalling clyde-code Python package...');
// Try all uninstall methods
const methods = [
{ name: 'pipx', fn: uninstallWithPipx },
{ name: 'uv', fn: uninstallWithUv },
{ name: 'pip', fn: uninstallWithPip }
];
let uninstalled = false;
for (const method of methods) {
const success = await method.fn();
if (success) {
console.log(`✅ Successfully uninstalled clyde-code using ${method.name}`);
uninstalled = true;
break;
}
}
if (!uninstalled) {
console.log('ℹ️ clyde-code may not have been installed or already removed');
}
// Remove config directory
const configDir = path.join(os.homedir(), '.clyde-code');
if (fs.existsSync(configDir)) {
try {
fs.rmSync(configDir, { recursive: true, force: true });
console.log('✅ Removed configuration directory ~/.clyde-code');
} catch (error) {
console.log('⚠️ Could not remove configuration directory:', error.message);
}
}
// Clean up remaining symlinks and directories
const cleanupPaths = [
path.join(os.homedir(), '.local', 'bin', 'clyde-code'),
path.join(os.homedir(), '.local', 'share', 'uv', 'tools', 'clyde-code'),
path.join(os.homedir(), '.local', 'share', 'pipx', 'venvs', 'clyde-code')
];
for (const cleanupPath of cleanupPaths) {
if (fs.existsSync(cleanupPath)) {
try {
const stat = fs.lstatSync(cleanupPath);
if (stat.isSymbolicLink()) {
fs.unlinkSync(cleanupPath);
console.log(`✅ Removed symlink: ${cleanupPath}`);
} else if (stat.isDirectory()) {
fs.rmSync(cleanupPath, { recursive: true, force: true });
console.log(`✅ Removed directory: ${cleanupPath}`);
} else {
fs.unlinkSync(cleanupPath);
console.log(`✅ Removed file: ${cleanupPath}`);
}
} catch (error) {
console.log(`⚠️ Could not remove ${cleanupPath}: ${error.message}`);
}
}
}
}
main().catch((error) => {
console.error('Uninstall script failed:', error.message);
// Don't exit with error code - npm uninstall should still succeed
});