kangentic 0.7.1 → 0.8.0
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/kangentic.js +34 -34
- package/package.json +1 -1
package/bin/kangentic.js
CHANGED
|
@@ -61,35 +61,13 @@ function isInstalled(platformInfo) {
|
|
|
61
61
|
const installPath = getInstallPath(platformInfo);
|
|
62
62
|
if (!fs.existsSync(installPath)) return false;
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (platformInfo.platform === 'darwin') {
|
|
71
|
-
try {
|
|
72
|
-
const plistPath = path.join(installPath, 'Contents', 'Info.plist');
|
|
73
|
-
const plistContent = fs.readFileSync(plistPath, 'utf-8');
|
|
74
|
-
const versionMatch = plistContent.match(/<key>CFBundleShortVersionString<\/key>\s*<string>([^<]+)<\/string>/);
|
|
75
|
-
if (versionMatch && versionMatch[1] !== VERSION) return false;
|
|
76
|
-
} catch {
|
|
77
|
-
// Can't read plist, treat as not installed
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// On Linux, check `kangentic --version` output
|
|
83
|
-
if (platformInfo.platform === 'linux') {
|
|
84
|
-
try {
|
|
85
|
-
const output = execFileSync(installPath, ['--version'], { encoding: 'utf-8', timeout: 5000 }).trim();
|
|
86
|
-
if (!output.includes(VERSION)) return false;
|
|
87
|
-
} catch {
|
|
88
|
-
// Can't check version, treat as installed (binary exists)
|
|
89
|
-
}
|
|
64
|
+
try {
|
|
65
|
+
const installedVersion = fs.readFileSync(getVersionMarkerPath(), 'utf-8').trim();
|
|
66
|
+
return installedVersion === VERSION;
|
|
67
|
+
} catch {
|
|
68
|
+
// Marker missing or unreadable. Force reinstall (idempotent).
|
|
69
|
+
return false;
|
|
90
70
|
}
|
|
91
|
-
|
|
92
|
-
return true;
|
|
93
71
|
}
|
|
94
72
|
|
|
95
73
|
// --- Download URL construction ---
|
|
@@ -317,6 +295,20 @@ function getTempDir() {
|
|
|
317
295
|
return tempDir;
|
|
318
296
|
}
|
|
319
297
|
|
|
298
|
+
// --- Version marker ---
|
|
299
|
+
|
|
300
|
+
function getVersionMarkerPath() {
|
|
301
|
+
return path.join(getTempDir(), 'installed-version');
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function writeVersionMarker() {
|
|
305
|
+
try {
|
|
306
|
+
fs.writeFileSync(getVersionMarkerPath(), VERSION + '\n', 'utf-8');
|
|
307
|
+
} catch {
|
|
308
|
+
console.warn('Warning: Could not write version marker file.');
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
320
312
|
// --- Main ---
|
|
321
313
|
|
|
322
314
|
function parseDataDir(arguments_) {
|
|
@@ -356,8 +348,9 @@ async function main() {
|
|
|
356
348
|
// Determine target directory (first positional argument, skipping flags and their values)
|
|
357
349
|
const targetDir = findTargetDir(arguments_);
|
|
358
350
|
|
|
359
|
-
// Check for --demo
|
|
351
|
+
// Check for --demo and --force flags
|
|
360
352
|
const isDemo = arguments_.includes('--demo');
|
|
353
|
+
const forceInstall = arguments_.includes('--force');
|
|
361
354
|
|
|
362
355
|
// Resolve data directory: env var takes priority, then --data-dir flag
|
|
363
356
|
const dataDirFlag = parseDataDir(arguments_);
|
|
@@ -386,7 +379,7 @@ async function main() {
|
|
|
386
379
|
}
|
|
387
380
|
|
|
388
381
|
// Check if already installed
|
|
389
|
-
if (isInstalled(platformInfo)) {
|
|
382
|
+
if (!forceInstall && isInstalled(platformInfo)) {
|
|
390
383
|
console.log(`Kangentic v${VERSION} is already installed.`);
|
|
391
384
|
launch(platformInfo, targetDir, dataDir, extraArgs);
|
|
392
385
|
return;
|
|
@@ -412,6 +405,7 @@ async function main() {
|
|
|
412
405
|
// Install
|
|
413
406
|
try {
|
|
414
407
|
install(platformInfo, artifactPath);
|
|
408
|
+
writeVersionMarker();
|
|
415
409
|
} catch (error) {
|
|
416
410
|
console.error(`\nInstallation failed: ${error.message}`);
|
|
417
411
|
console.error(`\nTry installing manually. The downloaded file is at: ${artifactPath}`);
|
|
@@ -429,7 +423,13 @@ async function main() {
|
|
|
429
423
|
launch(platformInfo, targetDir, dataDir, extraArgs);
|
|
430
424
|
}
|
|
431
425
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
});
|
|
426
|
+
// Only auto-run when executed directly (not when required for testing)
|
|
427
|
+
if (require.main === module) {
|
|
428
|
+
main().catch((error) => {
|
|
429
|
+
console.error(`Unexpected error: ${error.message}`);
|
|
430
|
+
process.exit(1);
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// Exported for testing
|
|
435
|
+
module.exports = { isInstalled, getVersionMarkerPath, writeVersionMarker, getInstallPath, getTempDir };
|