fnva 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fnva",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "跨平台环境切换工具,支持 Java 和 LLM 环境配置",
5
5
  "author": "protagonistss",
6
6
  "license": "MIT",
package/platforms/fnva CHANGED
Binary file
Binary file
@@ -32,15 +32,30 @@ function getPowerShellFunction() {
32
32
  # fnva 自动化函数 - 由 npm 安装自动添加
33
33
  function fnva {
34
34
  if ($args.Count -ge 2 -and ($args[0] -eq "java" -or $args[0] -eq "llm" -or $args[0] -eq "cc") -and ($args[1] -eq "use")) {
35
- $tempFile = "$env:TEMP\fnva_script_$(Get-Random).ps1"
35
+ $tempFile = Join-Path $env:TEMP ("fnva_script_" + (Get-Random) + ".ps1")
36
36
 
37
37
  $env:FNVAAUTOMODE = "1"
38
38
  try {
39
- cmd.exe /c "set FNVA_AUTO_MODE=%FNVAAUTOMODE% && fnva $args" | Out-File -FilePath $tempFile -Encoding UTF8
40
- & $tempFile
39
+ # 捕获 fnva 输出并保存到临时文件
40
+ $output = cmd.exe /c "set FNVA_AUTO_MODE=%FNVAAUTOMODE% && fnva $args" 2>&1
41
+
42
+ # 如果输出包含 PowerShell 脚本内容,保存并执行
43
+ if ($output -match '\$env:' -or $output -match 'Write-Host') {
44
+ $output | Out-File -FilePath $tempFile -Encoding UTF8
45
+ try {
46
+ & $tempFile
47
+ } catch {
48
+ Write-Host "执行脚本时出错: $_" -ForegroundColor Red
49
+ }
50
+ } else {
51
+ # 如果不是脚本内容,直接输出
52
+ $output
53
+ }
41
54
  } finally {
42
55
  $env:FNVAAUTOMODE = ""
43
- Remove-Item $tempFile -ErrorAction SilentlyContinue
56
+ if (Test-Path $tempFile) {
57
+ Remove-Item $tempFile -ErrorAction SilentlyContinue
58
+ }
44
59
  }
45
60
  } else {
46
61
  $env:FNVAAUTOMODE = "1"