From 8af982e706616679bb5fc79a2666d84c88336995 Mon Sep 17 00:00:00 2001 From: simosmik Date: Wed, 31 Dec 2025 07:59:13 +0000 Subject: [PATCH] feat: add update command to CLI for checking and installing the latest version --- README.md | 6 +++++ server/cli.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/README.md b/README.md index 1b8cbac..b01ce35 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,11 @@ claude-code-ui **To restart**: Stop with Ctrl+C and run `claude-code-ui` again. +**To update**: +```bash +cloudcli update +``` + ### CLI Usage After global installation, you have access to both `claude-code-ui` and `cloudcli` commands: @@ -97,6 +102,7 @@ After global installation, you have access to both `claude-code-ui` and `cloudcl | `cloudcli` or `claude-code-ui` | | Start the server (default) | | `cloudcli start` | | Start the server explicitly | | `cloudcli status` | | Show configuration and data locations | +| `cloudcli update` | | Update to the latest version | | `cloudcli help` | | Show help information | | `cloudcli version` | | Show version information | | `--port ` | `-p` | Set server port (default: 3001) | diff --git a/server/cli.js b/server/cli.js index f817dd7..ebff4a0 100755 --- a/server/cli.js +++ b/server/cli.js @@ -151,6 +151,7 @@ Usage: Commands: start Start the Claude Code UI server (default) status Show configuration and data locations + update Update to the latest version help Show this help information version Show version information @@ -186,8 +187,67 @@ function showVersion() { console.log(`${packageJson.version}`); } +// Compare semver versions, returns true if v1 > v2 +function isNewerVersion(v1, v2) { + const parts1 = v1.split('.').map(Number); + const parts2 = v2.split('.').map(Number); + for (let i = 0; i < 3; i++) { + if (parts1[i] > parts2[i]) return true; + if (parts1[i] < parts2[i]) return false; + } + return false; +} + +// Check for updates +async function checkForUpdates(silent = false) { + try { + const { execSync } = await import('child_process'); + const latestVersion = execSync('npm show @siteboon/claude-code-ui version', { encoding: 'utf8' }).trim(); + const currentVersion = packageJson.version; + + if (isNewerVersion(latestVersion, currentVersion)) { + console.log(`\n${c.warn('[UPDATE]')} New version available: ${c.bright(latestVersion)} (current: ${currentVersion})`); + console.log(` Run ${c.bright('cloudcli update')} to update\n`); + return { hasUpdate: true, latestVersion, currentVersion }; + } else if (!silent) { + console.log(`${c.ok('[OK]')} You are on the latest version (${currentVersion})`); + } + return { hasUpdate: false, latestVersion, currentVersion }; + } catch (e) { + if (!silent) { + console.log(`${c.warn('[WARN]')} Could not check for updates`); + } + return { hasUpdate: false, error: e.message }; + } +} + +// Update the package +async function updatePackage() { + try { + const { execSync } = await import('child_process'); + console.log(`${c.info('[INFO]')} Checking for updates...`); + + const { hasUpdate, latestVersion, currentVersion } = await checkForUpdates(true); + + if (!hasUpdate) { + console.log(`${c.ok('[OK]')} Already on the latest version (${currentVersion})`); + return; + } + + console.log(`${c.info('[INFO]')} Updating from ${currentVersion} to ${latestVersion}...`); + execSync('npm update -g @siteboon/claude-code-ui', { stdio: 'inherit' }); + console.log(`${c.ok('[OK]')} Update complete! Restart cloudcli to use the new version.`); + } catch (e) { + console.error(`${c.error('[ERROR]')} Update failed: ${e.message}`); + console.log(`${c.tip('[TIP]')} Try running manually: npm update -g @siteboon/claude-code-ui`); + } +} + // Start the server async function startServer() { + // Check for updates silently on startup + checkForUpdates(true); + // Import and run the server await import('./index.js'); } @@ -250,6 +310,9 @@ async function main() { case '--version': showVersion(); break; + case 'update': + await updatePackage(); + break; default: console.error(`\n❌ Unknown command: ${command}`); console.log(' Run "cloudcli help" for usage information.\n');