nvicode 0.1.12 → 0.1.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.
@@ -1,4 +1,5 @@
1
1
  import { spawnSync } from "node:child_process";
2
+ import { promises as fs } from "node:fs";
2
3
  import path from "node:path";
3
4
  import process from "node:process";
4
5
  import { fileURLToPath } from "node:url";
@@ -7,6 +8,48 @@ const isTruthy = (value) => value === "1" || value === "true" || value === "yes"
7
8
  const isGlobalInstall = () => process.env.npm_config_global === "true" ||
8
9
  process.env.npm_config_location === "global";
9
10
  const isInteractive = () => Boolean(process.stdin.isTTY && process.stdout.isTTY);
11
+ const getCliPath = () => path.join(path.dirname(fileURLToPath(import.meta.url)), "cli.js");
12
+ const getGlobalBinDir = () => {
13
+ const prefix = process.env.npm_config_prefix || process.env.PREFIX;
14
+ if (!prefix) {
15
+ return null;
16
+ }
17
+ return process.platform === "win32" ? prefix : path.join(prefix, "bin");
18
+ };
19
+ const createGlobalLauncher = async () => {
20
+ const binDir = getGlobalBinDir();
21
+ if (!binDir) {
22
+ return "skipped";
23
+ }
24
+ const cliPath = getCliPath();
25
+ const launcherPath = process.platform === "win32"
26
+ ? path.join(binDir, "nvicode.cmd")
27
+ : path.join(binDir, "nvicode");
28
+ const launcherContents = process.platform === "win32"
29
+ ? [
30
+ "@echo off",
31
+ `node "${cliPath}" %*`,
32
+ "",
33
+ ].join("\r\n")
34
+ : [
35
+ "#!/bin/sh",
36
+ `exec node "${cliPath}" "$@"`,
37
+ "",
38
+ ].join("\n");
39
+ try {
40
+ await fs.lstat(launcherPath);
41
+ return "skipped";
42
+ }
43
+ catch {
44
+ // create launcher only when npm did not create the command entry
45
+ }
46
+ await fs.mkdir(binDir, { recursive: true });
47
+ await fs.writeFile(launcherPath, launcherContents, "utf8");
48
+ if (process.platform !== "win32") {
49
+ await fs.chmod(launcherPath, 0o755);
50
+ }
51
+ return "created";
52
+ };
10
53
  const main = async () => {
11
54
  if (isTruthy(process.env.NVICODE_SKIP_POSTINSTALL) || isTruthy(process.env.CI)) {
12
55
  return;
@@ -14,6 +57,12 @@ const main = async () => {
14
57
  if (!isGlobalInstall()) {
15
58
  return;
16
59
  }
60
+ try {
61
+ await createGlobalLauncher();
62
+ }
63
+ catch {
64
+ // keep install resilient even if the launcher cannot be created manually
65
+ }
17
66
  if (!isInteractive()) {
18
67
  console.log("nvicode installed. Run `nvicode select model` to finish setup.");
19
68
  return;
@@ -27,7 +76,7 @@ const main = async () => {
27
76
  console.log("nvicode installed. Starting guided setup.");
28
77
  console.log("If you want to skip now, press Ctrl+C and run `nvicode select model` later.");
29
78
  console.log("");
30
- const cliPath = path.join(path.dirname(fileURLToPath(import.meta.url)), "cli.js");
79
+ const cliPath = getCliPath();
31
80
  const result = spawnSync(process.execPath, [cliPath, "select", "model"], {
32
81
  stdio: "inherit",
33
82
  env: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nvicode",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "NviCode - Introducing one click Nvidia/OpenRouter keys to Claude Code. Free Claude code.",
5
5
  "author": "Dinesh Potla",
6
6
  "keywords": [