@vikat/vikat-gateway-cli 1.0.1 → 1.0.2
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.js +63 -3
- package/package.json +1 -1
package/bin.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { spawnSync } from "child_process";
|
|
3
4
|
import { createHash } from "crypto";
|
|
4
|
-
import { chmodSync, createWriteStream, existsSync, fsyncSync, mkdirSync, readFileSync, appendFileSync, renameSync, unlinkSync } from "fs";
|
|
5
|
+
import { chmodSync, createWriteStream, existsSync, fsyncSync, mkdirSync, readFileSync, appendFileSync, realpathSync, renameSync, unlinkSync } from "fs";
|
|
5
6
|
import { homedir } from "os";
|
|
6
7
|
import { dirname, join } from "path";
|
|
7
8
|
import { Readable } from "stream";
|
|
8
9
|
import { createInterface } from "readline";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
9
11
|
|
|
10
12
|
const BASE_URL = "https://downloads.vikat.ai";
|
|
11
13
|
// Matches the migration CLI. Without a bound, a hung host hangs the install.
|
|
@@ -337,7 +339,50 @@ function printStartMessage(message) {
|
|
|
337
339
|
console.log(`Enter 'vikat' when you're ready to start the CLI.`);
|
|
338
340
|
}
|
|
339
341
|
|
|
342
|
+
// ─── ONCE INSTALLED, GET OUT OF THE WAY ─────────────────────────────────────
|
|
343
|
+
//
|
|
344
|
+
// This package declares bin "vikat", and bin.js is an INSTALLER. So
|
|
345
|
+
// `npm i -g @vikat/vikat-gateway-cli` puts the installer at /usr/local/bin/vikat
|
|
346
|
+
// — ahead of ~/.vikat/bin on PATH — where it permanently shadows the CLI it
|
|
347
|
+
// just downloaded. Typing `vikat` re-ran the installer. Every time. Forever.
|
|
348
|
+
// Its own closing line, "Enter 'vikat' when you're ready to start the CLI",
|
|
349
|
+
// sent the user straight back round the loop, and every argument was swallowed:
|
|
350
|
+
// `vikat version` printed installer text and never a version.
|
|
351
|
+
//
|
|
352
|
+
// So: if the CLI is already there, exec it and pass the arguments through. The
|
|
353
|
+
// shim becomes transparent and `vikat` means the CLI, from whichever directory
|
|
354
|
+
// PATH happens to resolve first.
|
|
355
|
+
//
|
|
356
|
+
// FIRST run still installs and still does NOT auto-start. That is deliberate
|
|
357
|
+
// upstream behaviour ("The installer won't start Vikat automatically"), it is
|
|
358
|
+
// what the quickstart documents, and `npx @vikat/vikat-gateway-cli` on a clean
|
|
359
|
+
// machine must keep behaving that way.
|
|
360
|
+
//
|
|
361
|
+
// Installer flags are the exception: --cli-version means "install this version",
|
|
362
|
+
// not "run the tool", so it always takes the install path.
|
|
363
|
+
function execInstalledCli(args) {
|
|
364
|
+
const target = join(homedir(), ".vikat", "bin", process.platform === "win32" ? "vikat.exe" : "vikat");
|
|
365
|
+
if (!existsSync(target)) return false;
|
|
366
|
+
|
|
367
|
+
// Never exec ourselves. If some future packaging put this script at that
|
|
368
|
+
// path, the transparent shim would become an infinite fork bomb rather than
|
|
369
|
+
// the loop it replaced.
|
|
370
|
+
try {
|
|
371
|
+
if (realpathSync(target) === realpathSync(fileURLToPath(import.meta.url))) return false;
|
|
372
|
+
} catch {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const res = spawnSync(target, args, { stdio: "inherit" });
|
|
377
|
+
if (res.error) return false; // fall through to the installer
|
|
378
|
+
process.exit(res.status === null ? 1 : res.status);
|
|
379
|
+
}
|
|
380
|
+
|
|
340
381
|
async function main() {
|
|
382
|
+
const passthrough = process.argv.slice(2);
|
|
383
|
+
const installerFlag = passthrough.some((a) => a.startsWith("--cli-version"));
|
|
384
|
+
if (!installerFlag) execInstalledCli(passthrough);
|
|
385
|
+
|
|
341
386
|
const { platformDir, archDir, binaryName } = getPlatformArchAndBinary();
|
|
342
387
|
|
|
343
388
|
let namedVersion;
|
|
@@ -394,10 +439,25 @@ async function main() {
|
|
|
394
439
|
const shellConfig = getShellConfig();
|
|
395
440
|
|
|
396
441
|
if (!shellConfig) {
|
|
397
|
-
//
|
|
442
|
+
// getShellConfig() returns null for TWO different situations, and this
|
|
443
|
+
// branch used to assume the first: actual Windows, and a POSIX machine
|
|
444
|
+
// whose $SHELL is unset or unrecognised. The second is ordinary — SHELL
|
|
445
|
+
// is not set in most Docker images, in cron, or in a CI step — and those
|
|
446
|
+
// users were told to open "System Settings > Environment Variables",
|
|
447
|
+
// which does not exist on Linux. Advice that cannot be followed reads as
|
|
448
|
+
// a broken installer.
|
|
398
449
|
console.log(`\nTo complete installation, add the following directory to your PATH:`);
|
|
399
450
|
console.log(` ${installDir}`);
|
|
400
|
-
|
|
451
|
+
if (process.platform === "win32") {
|
|
452
|
+
console.log(`\nYou can do this in System Settings > Environment Variables.`);
|
|
453
|
+
} else {
|
|
454
|
+
// Named rather than guessed: $SHELL told us nothing, so pointing at
|
|
455
|
+
// one specific rc file would be a guess presented as an instruction.
|
|
456
|
+
console.log(`\nAdd this line to whichever startup file your shell reads`);
|
|
457
|
+
console.log(`(~/.bashrc, ~/.zshrc, ~/.profile):`);
|
|
458
|
+
console.log(` export PATH="$HOME/.vikat/bin:$PATH"`);
|
|
459
|
+
console.log(`\n($SHELL is unset or unrecognised here, so this step could not be done for you.)`);
|
|
460
|
+
}
|
|
401
461
|
printStartMessage("The installer won't start Vikat automatically.");
|
|
402
462
|
return;
|
|
403
463
|
}
|