fnva 0.0.25 → 0.0.27
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 +2 -2
- package/platforms/fnva +0 -0
- package/platforms/fnva.exe +0 -0
- package/scripts/install-shell-integration.js +61 -55
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fnva",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"description": "跨平台环境切换工具,支持 Java 和 LLM 环境配置",
|
|
5
5
|
"author": "protagonistss",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"build": "scripts/build-local.sh",
|
|
16
16
|
"build:all": "scripts/build-all.sh",
|
|
17
17
|
"check-permissions": "node scripts/check-permissions.js",
|
|
18
|
-
"
|
|
18
|
+
"postuninstall": "echo 'Uninstalling fnva shell integration...' && node scripts/uninstall-shell-integration.js"
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"bin/",
|
package/platforms/fnva
CHANGED
|
Binary file
|
package/platforms/fnva.exe
CHANGED
|
Binary file
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const os = require('os');
|
|
6
|
-
const { spawn } = require('child_process');
|
|
7
6
|
|
|
8
7
|
function detectShell() {
|
|
9
8
|
if (process.platform === 'win32') {
|
|
@@ -29,7 +28,7 @@ function getShellConfigPath(shell) {
|
|
|
29
28
|
|
|
30
29
|
function getPowerShellFunction() {
|
|
31
30
|
return `
|
|
32
|
-
# fnva 自动化函数 -
|
|
31
|
+
# fnva 自动化函数 - 用 npm 安装自动添加
|
|
33
32
|
function fnva {
|
|
34
33
|
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
34
|
$tempFile = Join-Path $env:TEMP ("fnva_script_" + (Get-Random) + ".ps1")
|
|
@@ -39,7 +38,7 @@ function fnva {
|
|
|
39
38
|
# 捕获 fnva 输出并保存到临时文件
|
|
40
39
|
$output = cmd.exe /c "set FNVA_AUTO_MODE=%FNVAAUTOMODE% && fnva $args" 2>&1
|
|
41
40
|
|
|
42
|
-
# 如果输出包含 PowerShell
|
|
41
|
+
# 如果输出包含 PowerShell 脚本内容,则保存并执行
|
|
43
42
|
if ($output -match '\$env:' -or $output -match 'Write-Host') {
|
|
44
43
|
$output | Out-File -FilePath $tempFile -Encoding UTF8
|
|
45
44
|
try {
|
|
@@ -71,17 +70,25 @@ function fnva {
|
|
|
71
70
|
|
|
72
71
|
function getBashFunction() {
|
|
73
72
|
return `
|
|
74
|
-
# fnva 自动化函数 -
|
|
73
|
+
# fnva 自动化函数 - 用 npm 安装自动添加
|
|
75
74
|
fnva() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
local __fnva_bin
|
|
76
|
+
__fnva_bin="$(command -v fnva | head -n 1)"
|
|
77
|
+
if [[ -z "$__fnva_bin" ]]; then
|
|
78
|
+
echo "fnva: binary not found in PATH" >&2
|
|
79
|
+
return 127
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
if [[ $# -ge 2 && ("$1" == "java" || "$1" == "llm" || "$1" == "cc") && "$2" == "use" ]]; then
|
|
83
|
+
local temp_file
|
|
84
|
+
temp_file="$(mktemp)"
|
|
85
|
+
chmod +x "$temp_file"
|
|
79
86
|
|
|
80
|
-
FNVA_AUTO_MODE=1
|
|
81
|
-
source "
|
|
82
|
-
rm -f "
|
|
87
|
+
FNVA_AUTO_MODE=1 "$__fnva_bin" "$@" > "$temp_file"
|
|
88
|
+
source "$temp_file"
|
|
89
|
+
rm -f "$temp_file"
|
|
83
90
|
else
|
|
84
|
-
FNVA_AUTO_MODE=1
|
|
91
|
+
FNVA_AUTO_MODE=1 "$__fnva_bin" "$@"
|
|
85
92
|
fi
|
|
86
93
|
}
|
|
87
94
|
`;
|
|
@@ -89,16 +96,22 @@ fnva() {
|
|
|
89
96
|
|
|
90
97
|
function getFishFunction() {
|
|
91
98
|
return `
|
|
92
|
-
# fnva 自动化函数 -
|
|
99
|
+
# fnva 自动化函数 - 用 npm 安装自动添加
|
|
93
100
|
function fnva
|
|
94
|
-
|
|
101
|
+
set __fnva_bin (command -v fnva | head -n 1)
|
|
102
|
+
if test -z "$__fnva_bin"
|
|
103
|
+
echo "fnva: binary not found in PATH" >&2
|
|
104
|
+
return 127
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
if test (count $argv) -ge 2; and string match -q -r "^(java|llm|cc)$" $argv[1]; and test $argv[2] = "use"
|
|
95
108
|
set temp_file (mktemp)
|
|
96
|
-
chmod +x
|
|
97
|
-
env FNVA_AUTO_MODE=1
|
|
98
|
-
source
|
|
99
|
-
rm -f
|
|
109
|
+
chmod +x $temp_file
|
|
110
|
+
env FNVA_AUTO_MODE=1 "$__fnva_bin" $argv > $temp_file
|
|
111
|
+
source $temp_file
|
|
112
|
+
rm -f $temp_file
|
|
100
113
|
else
|
|
101
|
-
env FNVA_AUTO_MODE=1
|
|
114
|
+
env FNVA_AUTO_MODE=1 "$__fnva_bin" $argv
|
|
102
115
|
end
|
|
103
116
|
end
|
|
104
117
|
`;
|
|
@@ -111,7 +124,7 @@ function getShellFunction(shell) {
|
|
|
111
124
|
case 'bash':
|
|
112
125
|
return getBashFunction();
|
|
113
126
|
case 'zsh':
|
|
114
|
-
return getBashFunction(); // zsh
|
|
127
|
+
return getBashFunction(); // zsh 使用与 bash 相同的函数
|
|
115
128
|
case 'fish':
|
|
116
129
|
return getFishFunction();
|
|
117
130
|
default:
|
|
@@ -119,13 +132,13 @@ function getShellFunction(shell) {
|
|
|
119
132
|
}
|
|
120
133
|
}
|
|
121
134
|
|
|
122
|
-
function isFunctionInstalled(configPath
|
|
135
|
+
function isFunctionInstalled(configPath) {
|
|
123
136
|
if (!fs.existsSync(configPath)) {
|
|
124
137
|
return false;
|
|
125
138
|
}
|
|
126
139
|
|
|
127
140
|
const content = fs.readFileSync(configPath, 'utf8');
|
|
128
|
-
return content.includes('fnva 自动化函数 -
|
|
141
|
+
return content.includes('fnva 自动化函数 - 用 npm 安装自动添加');
|
|
129
142
|
}
|
|
130
143
|
|
|
131
144
|
function installShellIntegration() {
|
|
@@ -133,27 +146,24 @@ function installShellIntegration() {
|
|
|
133
146
|
const configPath = getShellConfigPath(shell);
|
|
134
147
|
|
|
135
148
|
if (!configPath) {
|
|
136
|
-
console.log(
|
|
137
|
-
console.log('请手动配置 fnva
|
|
149
|
+
console.log(`⚠️ 不支持的 shell: ${shell}`);
|
|
150
|
+
console.log('请手动配置 fnva,详见 README');
|
|
138
151
|
return false;
|
|
139
152
|
}
|
|
140
153
|
|
|
141
|
-
if (isFunctionInstalled(configPath
|
|
142
|
-
console.log(`✅ fnva shell
|
|
154
|
+
if (isFunctionInstalled(configPath)) {
|
|
155
|
+
console.log(`✅ fnva shell 集成已存在: ${configPath}`);
|
|
143
156
|
return true;
|
|
144
157
|
}
|
|
145
158
|
|
|
146
159
|
try {
|
|
147
|
-
// 确保目录存在
|
|
148
160
|
const dir = path.dirname(configPath);
|
|
149
161
|
if (!fs.existsSync(dir)) {
|
|
150
162
|
fs.mkdirSync(dir, { recursive: true });
|
|
151
163
|
}
|
|
152
164
|
|
|
153
|
-
// 获取函数定义
|
|
154
165
|
const functionCode = getShellFunction(shell);
|
|
155
166
|
|
|
156
|
-
// 添加到配置文件
|
|
157
167
|
if (fs.existsSync(configPath)) {
|
|
158
168
|
const content = fs.readFileSync(configPath, 'utf8');
|
|
159
169
|
fs.writeFileSync(configPath, content + '\n' + functionCode);
|
|
@@ -187,7 +197,6 @@ function installShellIntegration() {
|
|
|
187
197
|
}
|
|
188
198
|
}
|
|
189
199
|
|
|
190
|
-
// 询问用户是否安装
|
|
191
200
|
function promptInstallation() {
|
|
192
201
|
if (process.env.FNVA_SKIP_SHELL_SETUP === '1') {
|
|
193
202
|
console.log('⏭️ 跳过 shell 集成安装');
|
|
@@ -195,47 +204,44 @@ function promptInstallation() {
|
|
|
195
204
|
}
|
|
196
205
|
|
|
197
206
|
const shell = detectShell();
|
|
198
|
-
console.log(
|
|
199
|
-
console.log('
|
|
207
|
+
console.log(`🔍 检测到 shell: ${shell}`);
|
|
208
|
+
console.log('❓ 是否安装 fnva shell 集成? (y/N)');
|
|
200
209
|
|
|
201
|
-
|
|
202
|
-
|
|
210
|
+
const readline = require('readline');
|
|
211
|
+
const rl = readline.createInterface({
|
|
212
|
+
input: process.stdin,
|
|
213
|
+
output: process.stdout
|
|
214
|
+
});
|
|
203
215
|
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
if (
|
|
216
|
+
rl.question('> ', (answer) => {
|
|
217
|
+
const normalized = answer.trim().toLowerCase();
|
|
218
|
+
if (normalized === 'y' || normalized === 'yes') {
|
|
207
219
|
installShellIntegration();
|
|
208
220
|
} else {
|
|
209
|
-
console.log('
|
|
210
|
-
console.log('📖 手动配置指南: https://github.com/your-repo/fnva');
|
|
221
|
+
console.log('⏩ 已跳过 shell 集成安装');
|
|
211
222
|
}
|
|
212
|
-
|
|
223
|
+
rl.close();
|
|
213
224
|
});
|
|
214
|
-
|
|
215
|
-
// 10秒后自动跳过
|
|
216
|
-
setTimeout(() => {
|
|
217
|
-
console.log('⏭️ 超时,跳过 shell 集成安装');
|
|
218
|
-
console.log('📖 手动配置指南: https://github.com/your-repo/fnva');
|
|
219
|
-
process.exit(0);
|
|
220
|
-
}, 10000);
|
|
221
225
|
}
|
|
222
226
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
console.log(
|
|
226
|
-
console.log(`📍
|
|
227
|
-
console.log(`📂 工作目录: ${process.cwd()}`);
|
|
228
|
-
console.log(`🎯 参数: ${process.argv.join(' ')}`);
|
|
227
|
+
function main() {
|
|
228
|
+
console.log('🛠️ fnva shell 集成安装器');
|
|
229
|
+
console.log(`📦 Node.js 版本: ${process.version}`);
|
|
230
|
+
console.log(`📍 进程工作目录: ${process.cwd()}`);
|
|
229
231
|
|
|
230
232
|
if (process.argv.includes('--auto') || process.argv.includes('--yes')) {
|
|
231
|
-
console.log('
|
|
233
|
+
console.log('🤖 自动模式启动安装...');
|
|
232
234
|
const result = installShellIntegration();
|
|
233
|
-
console.log(
|
|
235
|
+
console.log(`📄 安装结果: ${result ? '成功' : '失败'}`);
|
|
234
236
|
} else {
|
|
235
237
|
promptInstallation();
|
|
236
238
|
}
|
|
237
239
|
}
|
|
238
240
|
|
|
241
|
+
if (require.main === module) {
|
|
242
|
+
main();
|
|
243
|
+
}
|
|
244
|
+
|
|
239
245
|
module.exports = {
|
|
240
246
|
detectShell,
|
|
241
247
|
getShellConfigPath,
|