@vantaloom/cli 0.3.5 → 0.3.7
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 +1 -1
- package/src/cli.mjs +59 -0
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync, spawnSync } from "node:child_process"
|
|
2
2
|
import {
|
|
3
|
+
appendFileSync,
|
|
3
4
|
chmodSync,
|
|
4
5
|
existsSync,
|
|
5
6
|
mkdirSync,
|
|
@@ -125,6 +126,7 @@ async function installFromSource(options) {
|
|
|
125
126
|
|
|
126
127
|
console.log(`${options.update ? "updated" : "installed"} Vantaloom: ${prefix}`)
|
|
127
128
|
console.log(`version: ${version}`)
|
|
129
|
+
ensureInPath(prefix)
|
|
128
130
|
console.log(`run: ${displayCommand(prefix)} status`)
|
|
129
131
|
}
|
|
130
132
|
|
|
@@ -138,6 +140,7 @@ async function installFromPackage(options) {
|
|
|
138
140
|
|
|
139
141
|
console.log(`${options.update ? "updated" : "installed"} Vantaloom: ${prefix}`)
|
|
140
142
|
console.log(`version: ${version}`)
|
|
143
|
+
ensureInPath(prefix)
|
|
141
144
|
console.log(`run: ${displayCommand(prefix)} status`)
|
|
142
145
|
}
|
|
143
146
|
|
|
@@ -332,6 +335,7 @@ async function syncFromNpmRegistry(options, action) {
|
|
|
332
335
|
console.log(`version: ${version}`)
|
|
333
336
|
console.log(`source: ${runtimePackage}@${resolved.version}`)
|
|
334
337
|
console.log(`registry: ${resolved.registry}`)
|
|
338
|
+
ensureInPath(prefix)
|
|
335
339
|
console.log(`run: ${displayCommand(prefix)} status`)
|
|
336
340
|
} finally {
|
|
337
341
|
removeKnownPath(tempRoot, os.tmpdir())
|
|
@@ -373,6 +377,7 @@ async function syncFromRelease(options, action) {
|
|
|
373
377
|
console.log(`${action === "update" ? "updated" : "installed"} Vantaloom: ${prefix}`)
|
|
374
378
|
console.log(`version: ${version}`)
|
|
375
379
|
console.log(`source: ${repo}@${releaseTag}`)
|
|
380
|
+
ensureInPath(prefix)
|
|
376
381
|
console.log(`run: ${displayCommand(prefix)} status`)
|
|
377
382
|
} finally {
|
|
378
383
|
removeKnownPath(tempRoot, os.tmpdir())
|
|
@@ -1089,6 +1094,60 @@ async function writeText(filePath, content) {
|
|
|
1089
1094
|
await writeFile(filePath, content)
|
|
1090
1095
|
}
|
|
1091
1096
|
|
|
1097
|
+
// ensureInPath adds the Vantaloom install directory to the user's shell PATH
|
|
1098
|
+
// on macOS and Linux, so `vantaloom` can be run directly after install.
|
|
1099
|
+
// On Windows this is not needed (vantaloom.cmd is run by full path or added via installer).
|
|
1100
|
+
function ensureInPath(prefix) {
|
|
1101
|
+
if (process.platform === "win32") return
|
|
1102
|
+
|
|
1103
|
+
// Check if already in PATH
|
|
1104
|
+
const pathDirs = (process.env.PATH || "").split(":")
|
|
1105
|
+
if (pathDirs.includes(prefix)) return
|
|
1106
|
+
|
|
1107
|
+
// Determine shell profile file
|
|
1108
|
+
const home = os.homedir()
|
|
1109
|
+
const shell = process.env.SHELL || ""
|
|
1110
|
+
let profilePath
|
|
1111
|
+
if (shell.endsWith("/zsh") || existsSync(path.join(home, ".zshrc"))) {
|
|
1112
|
+
profilePath = path.join(home, ".zshrc")
|
|
1113
|
+
} else if (shell.endsWith("/bash")) {
|
|
1114
|
+
// On macOS, bash uses .bash_profile; on Linux, .bashrc
|
|
1115
|
+
profilePath = process.platform === "darwin"
|
|
1116
|
+
? path.join(home, ".bash_profile")
|
|
1117
|
+
: path.join(home, ".bashrc")
|
|
1118
|
+
} else if (existsSync(path.join(home, ".profile"))) {
|
|
1119
|
+
profilePath = path.join(home, ".profile")
|
|
1120
|
+
} else {
|
|
1121
|
+
profilePath = path.join(home, ".profile")
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// Use $HOME-relative path for portability
|
|
1125
|
+
const homeRelative = prefix.startsWith(home)
|
|
1126
|
+
? `$HOME${prefix.slice(home.length)}`
|
|
1127
|
+
: prefix
|
|
1128
|
+
const exportLine = `export PATH="${homeRelative}:$PATH"`
|
|
1129
|
+
const marker = "# vantaloom"
|
|
1130
|
+
|
|
1131
|
+
// Check if already added to profile
|
|
1132
|
+
try {
|
|
1133
|
+
if (existsSync(profilePath)) {
|
|
1134
|
+
const content = readFileSync(profilePath, "utf8")
|
|
1135
|
+
if (content.includes("vantaloom") && content.includes("PATH")) return
|
|
1136
|
+
}
|
|
1137
|
+
} catch {}
|
|
1138
|
+
|
|
1139
|
+
// Append to profile
|
|
1140
|
+
try {
|
|
1141
|
+
const entry = `\n${marker}\n${exportLine}\n`
|
|
1142
|
+
appendFileSync(profilePath, entry)
|
|
1143
|
+
console.log(`PATH: added ${prefix} to ${profilePath}`)
|
|
1144
|
+
console.log(` run: source ${profilePath} (or open a new terminal)`)
|
|
1145
|
+
} catch (error) {
|
|
1146
|
+
console.log(`PATH: could not update ${profilePath}: ${error.message}`)
|
|
1147
|
+
console.log(` add manually: ${exportLine}`)
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1092
1151
|
function killTrayProcess(prefix) {
|
|
1093
1152
|
if (process.platform === "win32") {
|
|
1094
1153
|
// Try PID file first (new tray versions write runtime/tray.pid).
|