Private
Public Access
1
0

fix: replace claude setup symlinks with files

This commit is contained in:
2025-12-26 15:32:05 +08:00
parent 096437cc8d
commit d8440a1ccf
11 changed files with 1931 additions and 203 deletions

177
setup.ps1
View File

@@ -49,6 +49,10 @@ Options:
-ApiKey <KEY> API
-Help
:
- Node.js >= 20.x
- Node.js fnm Node.js 24.x
使:
`$key='YOUR_API_KEY'; iwr -useb https://gitea.sususu.cf/sususu/xcodecli-shells/raw/branch/main/setup.ps1 | iex
"@
@@ -65,91 +69,144 @@ function Refresh-Path {
$env:Path = [Environment]::GetEnvironmentVariable("Path", "User") + ";" + [Environment]::GetEnvironmentVariable("Path", "Machine")
}
# ========== 包管理器检测 ==========
function Get-PackageManager {
# 优先检测 Node.js/npm
# ========== Node.js 版本检测 ==========
function Get-NodeVersion {
if (Test-Command "node") {
try {
$nodeVersion = (& node --version 2>$null) -replace 'v', ''
Write-Info "检测到 Node.js v$nodeVersion"
return @{ Type = "npm"; Cmd = "npm install -g" }
$versionStr = (& node --version 2>$null) -replace 'v', ''
$major = [int]($versionStr -split '\.')[0]
return @{ Version = $versionStr; Major = $major }
}
catch { }
}
# 其次检测 Bun
if (Test-Command "bun") {
try {
$bunVersion = & bun --version 2>$null
Write-Info "检测到 Bun v$bunVersion"
return @{ Type = "bun"; Cmd = "bun add -g" }
}
catch { }
}
return $null
}
# ========== Bun 安装引导 ==========
function Install-Bun {
Write-Host ""
Write-Warning "未检测到 Node.js 或 Bun"
Write-Info "推荐安装 Bun轻量级 JavaScript 运行时)"
Write-Host ""
Write-Host " 安装命令: " -NoNewline
Write-Host 'powershell -c "irm bun.sh/install.ps1|iex"' -ForegroundColor Cyan
Write-Host ""
Write-Host " 要求: Windows 10 version 1809 或更高" -ForegroundColor Gray
# ========== fnm 安装 ==========
function Install-Fnm {
Write-Host ""
Write-Info "正在安装 fnm (Fast Node Manager)..."
$install = Read-Host "是否立即安装 Bun? (Y/n)"
if ($install -eq "n" -or $install -eq "N") {
return $false
}
Write-Info "正在安装 Bun..."
try {
Invoke-Expression 'irm bun.sh/install.ps1 | iex'
# 使用 winget 安装 fnm
if (Test-Command "winget") {
Write-Info "使用 winget 安装 fnm..."
& winget install Schniz.fnm -e --accept-source-agreements --accept-package-agreements
}
else {
# 备选:使用 cargo 或手动下载
Write-Info "使用 PowerShell 脚本安装 fnm..."
Invoke-Expression "& { $(Invoke-RestMethod https://fnm.vercel.app/install.ps1) }"
}
Refresh-Path
if (Test-Command "bun") {
Write-Success "Bun 安装成功!"
# 配置 fnm 环境
if (Test-Command "fnm") {
Write-Success "fnm 安装成功!"
# 初始化 fnm
$fnmEnv = & fnm env --use-on-cd 2>$null
if ($fnmEnv) {
$fnmEnv | Out-String | Invoke-Expression
}
return $true
}
else {
Write-Warning "Bun 可能已安装,但需要重新打开终端才能生效"
Write-Warning "fnm 可能已安装,但需要重新打开终端才能生效"
Write-Info "请重新打开 PowerShell 后再运行此脚本"
return $false
}
}
catch {
Write-Error "Bun 安装失败: $($_.Exception.Message)"
Write-Error "fnm 安装失败: $($_.Exception.Message)"
return $false
}
}
# ========== 使用 fnm 安装 Node.js ==========
function Install-NodeWithFnm {
Write-Info "使用 fnm 安装 Node.js 24.x..."
try {
& fnm install 24
& fnm use 24
& fnm default 24
Refresh-Path
if (Test-Command "node") {
$nodeInfo = Get-NodeVersion
Write-Success "Node.js v$($nodeInfo.Version) 安装成功!"
return $true
}
else {
Write-Warning "Node.js 可能已安装,但需要重新打开终端才能生效"
return $false
}
}
catch {
Write-Error "Node.js 安装失败: $($_.Exception.Message)"
return $false
}
}
# ========== 确保 Node.js 环境就绪 ==========
function Ensure-NodeEnvironment {
$nodeInfo = Get-NodeVersion
if ($nodeInfo) {
Write-Info "检测到 Node.js v$($nodeInfo.Version)"
if ($nodeInfo.Major -lt 20) {
Write-Warning "Node.js 版本过低 (需要 >= 20.x)"
Write-Info "请升级 Node.js 或让脚本使用 fnm 安装新版本"
$upgrade = Read-Host "是否使用 fnm 安装 Node.js 24.x? (Y/n)"
if ($upgrade -eq "n" -or $upgrade -eq "N") {
Write-Error "Node.js 版本不满足要求,请手动升级后重试"
return $false
}
# 安装 fnm (如果未安装)
if (-not (Test-Command "fnm")) {
if (-not (Install-Fnm)) { return $false }
}
return Install-NodeWithFnm
}
return $true
}
# 未安装 Node.js
Write-Warning "未检测到 Node.js"
Write-Info "将使用 fnm 安装 Node.js 24.x"
$install = Read-Host "是否继续? (Y/n)"
if ($install -eq "n" -or $install -eq "N") {
return $false
}
# 安装 fnm
if (-not (Test-Command "fnm")) {
if (-not (Install-Fnm)) { return $false }
}
return Install-NodeWithFnm
}
# ========== 工具安装 ==========
function Install-Tool {
param(
[hashtable]$Tool
)
# 获取包管理器
$pm = Get-PackageManager
if (-not $pm) {
if (-not (Install-Bun)) {
return $false
}
Refresh-Path
$pm = Get-PackageManager
if (-not $pm) {
Write-Error "仍未检测到可用的包管理器"
return $false
}
# 确保 Node.js 环境就绪
if (-not (Ensure-NodeEnvironment)) {
return $false
}
Write-Info "使用 $($pm.Type) 安装 $($Tool.Name)..."
$installCmd = "$($pm.Cmd) $($Tool.Package)"
Write-Info "使用 npm 安装 $($Tool.Name)..."
$installCmd = "npm install -g $($Tool.Package)"
Write-Host " 执行: $installCmd" -ForegroundColor Gray
try {
@@ -157,7 +214,6 @@ function Install-Tool {
$exitCode = $LASTEXITCODE
Refresh-Path
# 检查安装命令退出码
if ($exitCode -ne 0) {
Write-Error "安装命令返回错误码: $exitCode"
return $false
@@ -236,6 +292,21 @@ function Show-Menu {
Write-Host " XCodeCLI Setup Launcher" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 显示 Node.js 环境状态
$nodeInfo = Get-NodeVersion
if ($nodeInfo) {
$nodeStatus = if ($nodeInfo.Major -ge 20) { "[OK]" } else { "[需升级]" }
$nodeColor = if ($nodeInfo.Major -ge 20) { "Green" } else { "Yellow" }
Write-Host " Node.js: v$($nodeInfo.Version) " -NoNewline
Write-Host $nodeStatus -ForegroundColor $nodeColor
}
else {
Write-Host " Node.js: " -NoNewline
Write-Host "[未安装]" -ForegroundColor Red
}
Write-Host ""
Write-Host "选择要安装和配置的工具:" -ForegroundColor Yellow
Write-Host ""