fnva 0.0.11 → 0.0.13
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/bin/fnva.js +111 -0
- package/package.json +1 -1
- package/platforms/fnva +0 -0
- package/platforms/fnva.exe +0 -0
package/bin/fnva.js
CHANGED
|
@@ -38,6 +38,11 @@ function platformBinaryPath(platformOverride) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function buildBinaryPath() {
|
|
41
|
+
// 如果设置了 FNVA_SKIP_NATIVE,跳过原生二进制查找
|
|
42
|
+
if (process.env.FNVA_SKIP_NATIVE === '1') {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
41
46
|
const platform = resolvePlatform();
|
|
42
47
|
const binaryCandidates = [];
|
|
43
48
|
|
|
@@ -272,16 +277,122 @@ function generateSimpleScript(envVars, envType, envName) {
|
|
|
272
277
|
return lines.join('\n');
|
|
273
278
|
}
|
|
274
279
|
|
|
280
|
+
function handleNodeOnlyMode(args) {
|
|
281
|
+
const fs = require('fs');
|
|
282
|
+
const path = require('path');
|
|
283
|
+
const os = require('os');
|
|
284
|
+
|
|
285
|
+
// 简单的命令处理
|
|
286
|
+
if (args.length === 0) {
|
|
287
|
+
console.log('fnva - 环境管理工具 (Node.js 模式)');
|
|
288
|
+
console.log('');
|
|
289
|
+
console.log('支持的命令:');
|
|
290
|
+
console.log(' java list - 列出 Java 环境');
|
|
291
|
+
console.log(' java use <n> - 切换 Java 环境');
|
|
292
|
+
console.log('');
|
|
293
|
+
console.log('注意: Node.js 模式功能有限,建议使用原生二进制版本。');
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (args[0] === 'java') {
|
|
298
|
+
const homeDir = os.homedir();
|
|
299
|
+
const fnvaDir = path.join(homeDir, '.fnva', 'java-packages');
|
|
300
|
+
|
|
301
|
+
if (args[1] === 'list') {
|
|
302
|
+
if (!fs.existsSync(fnvaDir)) {
|
|
303
|
+
console.log('No Java environments found');
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const versions = fs.readdirSync(fnvaDir, { withFileTypes: true })
|
|
308
|
+
.filter(dirent => dirent.isDirectory())
|
|
309
|
+
.map(dirent => dirent.name)
|
|
310
|
+
.sort();
|
|
311
|
+
|
|
312
|
+
if (versions.length === 0) {
|
|
313
|
+
console.log('No Java environments found');
|
|
314
|
+
} else {
|
|
315
|
+
console.log('Available java environments:');
|
|
316
|
+
versions.forEach(version => {
|
|
317
|
+
const versionDir = path.join(fnvaDir, version);
|
|
318
|
+
const jdkSubdirs = fs.readdirSync(versionDir, { withFileTypes: true })
|
|
319
|
+
.filter(dirent => dirent.isDirectory())
|
|
320
|
+
.map(dirent => dirent.name);
|
|
321
|
+
|
|
322
|
+
if (jdkSubdirs.length > 0) {
|
|
323
|
+
const jdkSubdir = jdkSubdirs[0];
|
|
324
|
+
const fullJdkPath = path.join(versionDir, jdkSubdir);
|
|
325
|
+
|
|
326
|
+
if (fs.existsSync(path.join(fullJdkPath, 'release'))) {
|
|
327
|
+
try {
|
|
328
|
+
const releaseContent = fs.readFileSync(path.join(fullJdkPath, 'release'), 'utf8');
|
|
329
|
+
const versionMatch = releaseContent.match(/JAVA_VERSION="(.+)"/);
|
|
330
|
+
const javaVersion = versionMatch ? versionMatch[1].replace(/"/g, '') : 'Unknown';
|
|
331
|
+
console.log(` ${version} (current): Java ${javaVersion} (${fullJdkPath})`);
|
|
332
|
+
} catch (e) {
|
|
333
|
+
console.log(` ${version} (${fullJdkPath})`);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
} else if (args[1] === 'use' && args[2]) {
|
|
340
|
+
const version = args[2];
|
|
341
|
+
const versionDir = path.join(fnvaDir, version);
|
|
342
|
+
|
|
343
|
+
if (!fs.existsSync(versionDir)) {
|
|
344
|
+
console.error(`Java environment '${version}' not found`);
|
|
345
|
+
process.exit(1);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// 查找实际的 JDK 目录
|
|
349
|
+
const jdkSubdirs = fs.readdirSync(versionDir, { withFileTypes: true })
|
|
350
|
+
.filter(dirent => dirent.isDirectory())
|
|
351
|
+
.map(dirent => dirent.name);
|
|
352
|
+
|
|
353
|
+
if (jdkSubdirs.length === 0) {
|
|
354
|
+
console.error(`No JDK installation found in ${versionDir}`);
|
|
355
|
+
process.exit(1);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const jdkPath = path.join(versionDir, jdkSubdirs[0]);
|
|
359
|
+
const jdkBinPath = path.join(jdkPath, 'bin');
|
|
360
|
+
|
|
361
|
+
// 生成环境切换脚本
|
|
362
|
+
const envVars = {
|
|
363
|
+
JAVA_HOME: jdkPath
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const script = generateSimpleScript(envVars, 'java', version);
|
|
367
|
+
console.log(script);
|
|
368
|
+
} else {
|
|
369
|
+
console.error('Usage: fnva java <list|use <version>>');
|
|
370
|
+
process.exit(1);
|
|
371
|
+
}
|
|
372
|
+
} else {
|
|
373
|
+
console.error(`Command '${args[0]}' not supported in Node.js mode`);
|
|
374
|
+
process.exit(1);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
275
378
|
function run() {
|
|
276
379
|
const binaryPath = buildBinaryPath();
|
|
277
380
|
|
|
278
381
|
if (!binaryPath) {
|
|
382
|
+
if (process.env.FNVA_SKIP_NATIVE === '1') {
|
|
383
|
+
// 纯 Node.js 模式 - 实现基本的环境切换功能
|
|
384
|
+
const args = process.argv.slice(2);
|
|
385
|
+
handleNodeOnlyMode(args);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
|
|
279
389
|
console.error('Error: fnva native binary not found.');
|
|
280
390
|
console.error('');
|
|
281
391
|
console.error("Please either:");
|
|
282
392
|
console.error(" 1) Run 'npm run build' (or 'npm run build:all') to produce platform binaries,");
|
|
283
393
|
console.error(" 2) Install a release package that includes the platforms directory, or");
|
|
284
394
|
console.error(" 3) Set FNVA_NATIVE_PATH to the full path of an existing fnva executable.");
|
|
395
|
+
console.error(" 4) Set FNVA_SKIP_NATIVE=1 to use Node.js mode (limited functionality).");
|
|
285
396
|
process.exit(1);
|
|
286
397
|
}
|
|
287
398
|
|
package/package.json
CHANGED
package/platforms/fnva
CHANGED
|
Binary file
|
package/platforms/fnva.exe
CHANGED
|
Binary file
|