@aryanbhosale/pick 0.1.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/pick.js +89 -0
- package/package.json +36 -0
package/bin/pick.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawnSync } = require("child_process");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
|
|
7
|
+
const PLATFORMS = {
|
|
8
|
+
"darwin-arm64": "@aryanbhosale/pick-darwin-arm64",
|
|
9
|
+
"darwin-x64": "@aryanbhosale/pick-darwin-x64",
|
|
10
|
+
"linux-x64": "@aryanbhosale/pick-linux-x64",
|
|
11
|
+
"linux-arm64": "@aryanbhosale/pick-linux-arm64",
|
|
12
|
+
"win32-x64": "@aryanbhosale/pick-win32-x64",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const platformKey = `${process.platform}-${process.arch}`;
|
|
16
|
+
const pkgName = PLATFORMS[platformKey];
|
|
17
|
+
|
|
18
|
+
if (!pkgName) {
|
|
19
|
+
console.error(
|
|
20
|
+
`pick: unsupported platform ${process.platform}-${process.arch}`
|
|
21
|
+
);
|
|
22
|
+
console.error(`Supported: ${Object.keys(PLATFORMS).join(", ")}`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const binName = `pick${process.platform === "win32" ? ".exe" : ""}`;
|
|
27
|
+
|
|
28
|
+
function findBinary() {
|
|
29
|
+
// 1. Try require.resolve (works when properly installed as dependency)
|
|
30
|
+
try {
|
|
31
|
+
return require.resolve(`${pkgName}/bin/${binName}`);
|
|
32
|
+
} catch {}
|
|
33
|
+
|
|
34
|
+
// 2. Walk up from the *executed* script path (process.argv[1]) to find
|
|
35
|
+
// node_modules. This handles symlinks from node_modules/.bin/ correctly
|
|
36
|
+
// since process.argv[1] gives the symlink target inside node_modules.
|
|
37
|
+
const scriptPaths = [
|
|
38
|
+
process.argv[1], // The actual executed path (follows .bin symlink)
|
|
39
|
+
__filename, // May be resolved differently
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
for (const scriptPath of scriptPaths) {
|
|
43
|
+
if (!scriptPath) continue;
|
|
44
|
+
let dir = path.dirname(scriptPath);
|
|
45
|
+
while (dir !== path.dirname(dir)) {
|
|
46
|
+
const candidate = path.join(
|
|
47
|
+
dir, "node_modules", pkgName, "bin", binName
|
|
48
|
+
);
|
|
49
|
+
if (fs.existsSync(candidate)) {
|
|
50
|
+
return candidate;
|
|
51
|
+
}
|
|
52
|
+
// Also check if we're inside node_modules/@aryanbhosale/pick/bin already
|
|
53
|
+
// and the sibling package is at the same scope level
|
|
54
|
+
if (dir.endsWith(path.join("node_modules", "@aryanbhosale", "pick"))) {
|
|
55
|
+
const sibling = path.join(
|
|
56
|
+
path.dirname(dir), path.basename(pkgName), "bin", binName
|
|
57
|
+
);
|
|
58
|
+
if (fs.existsSync(sibling)) {
|
|
59
|
+
return sibling;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
dir = path.dirname(dir);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const binPath = findBinary();
|
|
70
|
+
|
|
71
|
+
if (!binPath) {
|
|
72
|
+
console.error(`pick: could not find binary package "${pkgName}".`);
|
|
73
|
+
console.error(
|
|
74
|
+
`This usually means the optional dependency was not installed.`
|
|
75
|
+
);
|
|
76
|
+
console.error(`Try: npm install ${pkgName}`);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const result = spawnSync(binPath, process.argv.slice(2), {
|
|
81
|
+
stdio: "inherit",
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (result.error) {
|
|
85
|
+
console.error(`pick: ${result.error.message}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
process.exit(result.status ?? 1);
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aryanbhosale/pick",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Extract values from anything — JSON, YAML, TOML, .env, HTTP headers, logfmt, CSV, and more",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/aryanbhosale/pick"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"cli",
|
|
12
|
+
"extract",
|
|
13
|
+
"json",
|
|
14
|
+
"yaml",
|
|
15
|
+
"toml",
|
|
16
|
+
"env",
|
|
17
|
+
"logfmt",
|
|
18
|
+
"csv",
|
|
19
|
+
"jq",
|
|
20
|
+
"yq",
|
|
21
|
+
"parser"
|
|
22
|
+
],
|
|
23
|
+
"bin": {
|
|
24
|
+
"pick": "bin/pick.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"bin"
|
|
28
|
+
],
|
|
29
|
+
"optionalDependencies": {
|
|
30
|
+
"@aryanbhosale/pick-darwin-arm64": "0.1.0",
|
|
31
|
+
"@aryanbhosale/pick-darwin-x64": "0.1.0",
|
|
32
|
+
"@aryanbhosale/pick-linux-x64": "0.1.0",
|
|
33
|
+
"@aryanbhosale/pick-linux-arm64": "0.1.0",
|
|
34
|
+
"@aryanbhosale/pick-win32-x64": "0.1.0"
|
|
35
|
+
}
|
|
36
|
+
}
|