@brianlovin/hn-cli 0.4.3 → 0.4.5
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/hn +70 -0
- package/dist/cli.js +69 -69
- package/package.json +13 -3
package/bin/hn
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const childProcess = require("child_process")
|
|
4
|
+
const fs = require("fs")
|
|
5
|
+
const path = require("path")
|
|
6
|
+
const os = require("os")
|
|
7
|
+
|
|
8
|
+
function run(target) {
|
|
9
|
+
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
})
|
|
12
|
+
if (result.error) {
|
|
13
|
+
console.error(result.error.message)
|
|
14
|
+
process.exit(1)
|
|
15
|
+
}
|
|
16
|
+
const code = typeof result.status === "number" ? result.status : 0
|
|
17
|
+
process.exit(code)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Resolve symlinks to get the real script location
|
|
21
|
+
const scriptPath = fs.realpathSync(__filename)
|
|
22
|
+
const scriptDir = path.dirname(scriptPath)
|
|
23
|
+
|
|
24
|
+
// Map platform/arch to package names
|
|
25
|
+
const platformMap = {
|
|
26
|
+
darwin: "darwin",
|
|
27
|
+
linux: "linux",
|
|
28
|
+
win32: "windows",
|
|
29
|
+
}
|
|
30
|
+
const archMap = {
|
|
31
|
+
x64: "x64",
|
|
32
|
+
arm64: "arm64",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const platform = platformMap[os.platform()] || os.platform()
|
|
36
|
+
const arch = archMap[os.arch()] || os.arch()
|
|
37
|
+
const pkgName = `@brianlovin/hn-cli-${platform}-${arch}`
|
|
38
|
+
const binary = platform === "windows" ? "hn.exe" : "hn"
|
|
39
|
+
|
|
40
|
+
// Search for the platform-specific binary in node_modules
|
|
41
|
+
function findBinary(startDir) {
|
|
42
|
+
let current = startDir
|
|
43
|
+
while (true) {
|
|
44
|
+
const modules = path.join(current, "node_modules")
|
|
45
|
+
if (fs.existsSync(modules)) {
|
|
46
|
+
// Check for the platform-specific package
|
|
47
|
+
const candidate = path.join(modules, "@brianlovin", `hn-cli-${platform}-${arch}`, "bin", binary)
|
|
48
|
+
if (fs.existsSync(candidate)) {
|
|
49
|
+
return candidate
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const parent = path.dirname(current)
|
|
53
|
+
if (parent === current) break
|
|
54
|
+
current = parent
|
|
55
|
+
}
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const resolved = findBinary(scriptDir)
|
|
60
|
+
if (!resolved) {
|
|
61
|
+
console.error("")
|
|
62
|
+
console.error(`Error: Could not find the HN CLI binary for your platform (${platform}-${arch}).`)
|
|
63
|
+
console.error("")
|
|
64
|
+
console.error("You can try manually installing the platform package:")
|
|
65
|
+
console.error(` npm install ${pkgName}`)
|
|
66
|
+
console.error("")
|
|
67
|
+
process.exit(1)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
run(resolved)
|