mirror of
https://github.com/trycua/computer.git
synced 2026-05-07 23:51:55 -05:00
Fix yargs --version implementation printing "unknown" for built .exe's
This commit is contained in:
@@ -22,6 +22,27 @@ export async function runCli() {
|
|||||||
'\n' +
|
'\n' +
|
||||||
'Documentation: https://docs.cua.ai/libraries/cua-cli/commands'
|
'Documentation: https://docs.cua.ai/libraries/cua-cli/commands'
|
||||||
);
|
);
|
||||||
|
// version command
|
||||||
|
argv = argv.command(
|
||||||
|
'version',
|
||||||
|
'Show CUA CLI version',
|
||||||
|
(y) => y,
|
||||||
|
async () => {
|
||||||
|
try {
|
||||||
|
const home = process.env.HOME || process.env.USERPROFILE || '';
|
||||||
|
const path = `${home}/.cua/bin/.version`;
|
||||||
|
const version = await Bun.file(path).text();
|
||||||
|
const v = version.trim();
|
||||||
|
if (v) {
|
||||||
|
console.log(v);
|
||||||
|
} else {
|
||||||
|
console.log('unknown');
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
console.log('unknown');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
argv = registerAuthCommands(argv);
|
argv = registerAuthCommands(argv);
|
||||||
argv = registerSandboxCommands(argv);
|
argv = registerSandboxCommands(argv);
|
||||||
await argv.demandCommand(1).strict().help().parseAsync();
|
await argv.demandCommand(1).strict().help().parseAsync();
|
||||||
|
|||||||
@@ -32,11 +32,29 @@ function Install-WithBun {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
bun add -g @trycua/cli
|
bun add -g @trycua/cli
|
||||||
|
# Determine installed version from npm registry
|
||||||
|
try {
|
||||||
|
$bunVersion = (npm view @trycua/cli version) 2>$null
|
||||||
|
if (-not $bunVersion) { $bunVersion = "unknown" }
|
||||||
|
} catch { $bunVersion = "unknown" }
|
||||||
|
# Ensure install dir and write version file
|
||||||
|
$installDir = "$env:USERPROFILE\.cua\bin"
|
||||||
|
if (-not (Test-Path $installDir)) { New-Item -ItemType Directory -Path $installDir -Force | Out-Null }
|
||||||
|
Set-Content -Path (Join-Path $installDir ".version") -Value $bunVersion -NoNewline
|
||||||
return $true
|
return $true
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Warning: Failed to install with Bun, trying npm..." -ForegroundColor Yellow
|
Write-Host "Warning: Failed to install with Bun, trying npm..." -ForegroundColor Yellow
|
||||||
try {
|
try {
|
||||||
npm install -g @trycua/cli
|
npm install -g @trycua/cli
|
||||||
|
# Determine installed version from npm registry
|
||||||
|
try {
|
||||||
|
$npmVersion = (npm view @trycua/cli version) 2>$null
|
||||||
|
if (-not $npmVersion) { $npmVersion = "unknown" }
|
||||||
|
} catch { $npmVersion = "unknown" }
|
||||||
|
# Ensure install dir and write version file
|
||||||
|
$installDir = "$env:USERPROFILE\.cua\bin"
|
||||||
|
if (-not (Test-Path $installDir)) { New-Item -ItemType Directory -Path $installDir -Force | Out-Null }
|
||||||
|
Set-Content -Path (Join-Path $installDir ".version") -Value $npmVersion -NoNewline
|
||||||
return $true
|
return $true
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Error: Installation failed with npm as well." -ForegroundColor Red
|
Write-Host "Error: Installation failed with npm as well." -ForegroundColor Red
|
||||||
@@ -106,6 +124,13 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Write version file for binary install
|
||||||
|
try {
|
||||||
|
Set-Content -Path (Join-Path $installDir ".version") -Value $version -NoNewline
|
||||||
|
} catch {
|
||||||
|
# Non-fatal
|
||||||
|
}
|
||||||
|
|
||||||
# Add to PATH if not already there
|
# Add to PATH if not already there
|
||||||
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
||||||
if ($currentPath -notlike "*$installDir*") {
|
if ($currentPath -notlike "*$installDir*") {
|
||||||
|
|||||||
+13
-2
@@ -63,8 +63,15 @@ install_with_bun() {
|
|||||||
elif [ -f "$HOME/.profile" ]; then
|
elif [ -f "$HOME/.profile" ]; then
|
||||||
config_file="$HOME/.profile"
|
config_file="$HOME/.profile"
|
||||||
fi
|
fi
|
||||||
|
# Determine installed version via npm registry (fallback to unknown)
|
||||||
print_success "cua" "$VERSION" "$config_file"
|
local VERSION_BUN
|
||||||
|
VERSION_BUN=$(npm view @trycua/cli version 2>/dev/null || echo "unknown")
|
||||||
|
# Write version file to ~/.cua/bin/.version
|
||||||
|
local INSTALL_DIR="$HOME/.cua/bin"
|
||||||
|
mkdir -p "$INSTALL_DIR"
|
||||||
|
echo "$VERSION_BUN" > "$INSTALL_DIR/.version"
|
||||||
|
# Print success and exit
|
||||||
|
print_success "$(command -v cua)" "$VERSION_BUN" "$config_file"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
echo "❌ Installation failed. Please try installing manually:"
|
echo "❌ Installation failed. Please try installing manually:"
|
||||||
@@ -114,6 +121,7 @@ VERSION=${TAG_NAME#cua-v}
|
|||||||
# Find the binary URL in the release assets
|
# Find the binary URL in the release assets
|
||||||
BINARY_URL=$(echo "$LATEST_RELEASE" | grep -o 'https://.*/download/[^"]*/'${BINARY_NAME}'"' | head -1)
|
BINARY_URL=$(echo "$LATEST_RELEASE" | grep -o 'https://.*/download/[^"]*/'${BINARY_NAME}'"' | head -1)
|
||||||
BINARY_URL="${BINARY_URL%\"}"
|
BINARY_URL="${BINARY_URL%\"}"
|
||||||
|
printf "\033[90mBINARY_URL: %s\033[0m\n" "$BINARY_URL"
|
||||||
|
|
||||||
if [ -z "$BINARY_URL" ]; then
|
if [ -z "$BINARY_URL" ]; then
|
||||||
echo "⚠️ Could not find ${BINARY_NAME} in release assets, falling back to Bun installation"
|
echo "⚠️ Could not find ${BINARY_NAME} in release assets, falling back to Bun installation"
|
||||||
@@ -136,6 +144,9 @@ fi
|
|||||||
# Make the binary executable
|
# Make the binary executable
|
||||||
chmod +x "$INSTALL_DIR/cua"
|
chmod +x "$INSTALL_DIR/cua"
|
||||||
|
|
||||||
|
# Write version file
|
||||||
|
echo "$VERSION" > "$INSTALL_DIR/.version"
|
||||||
|
|
||||||
# Add ~/.cua/bin to PATH if not already in PATH
|
# Add ~/.cua/bin to PATH if not already in PATH
|
||||||
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
|
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
|
||||||
# Add to .bashrc, .zshrc, or .profile
|
# Add to .bashrc, .zshrc, or .profile
|
||||||
|
|||||||
Reference in New Issue
Block a user