docdex 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/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+ - Initial npm scaffold for the Docdex CLI (`docdex`/`docdexd` bin).
5
+ - Postinstall downloader to fetch platform-specific `docdexd` binaries.
6
+ - Supports macOS (arm64/x64) and Linux (arm64/x64, gnu/musl auto-detect).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 bekir dağ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Docdex (npm)
2
+
3
+ Install the Docdex CLI via npm:
4
+
5
+ ```bash
6
+ npm i -g docdex
7
+ # or
8
+ npx docdex --version
9
+ ```
10
+
11
+ Requirements:
12
+ - Node.js >= 18
13
+ - Supported platforms: macOS (arm64, x64), Linux glibc (arm64, x64). Musl (Alpine) is detected automatically when artifacts are available.
14
+
15
+ How it works:
16
+ - The package ships a small launcher (`docdex`/`docdexd`); `postinstall` downloads the correct `docdexd` binary for your platform from the GitHub release matching the npm package version.
17
+
18
+ Environment overrides (optional):
19
+ - `DOCDEX_DOWNLOAD_REPO` — `owner/repo` slug hosting release assets (required if `package.json` repository is still a placeholder).
20
+ - `DOCDEX_DOWNLOAD_BASE` — full base URL for release downloads (defaults to `https://github.com/<repo>/releases/download`).
21
+ - `DOCDEX_VERSION` — force a specific version/tag when testing.
22
+ - `DOCDEX_LIBC` — force `gnu` or `musl` on Linux if auto-detection is wrong.
23
+ - `DOCDEX_GITHUB_TOKEN` — token for authenticated GitHub downloads (avoids rate limits/private release issues).
24
+
25
+ Notes:
26
+ - Release assets are expected to be named `docdexd-<platform>.tar.gz` with a matching `.sha256`.
27
+ - License: MIT (see `LICENSE`).
28
+ - Changelog: see `CHANGELOG.md`.
package/bin/docdex.js ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const fs = require("node:fs");
5
+ const path = require("node:path");
6
+ const { spawn } = require("node:child_process");
7
+
8
+ const { detectPlatformKey } = require("../lib/platform");
9
+
10
+ function run() {
11
+ const platformKey = detectPlatformKey();
12
+ const binaryPath = path.join(__dirname, "..", "dist", platformKey, "docdexd");
13
+
14
+ if (!fs.existsSync(binaryPath)) {
15
+ console.error(
16
+ `[docdex] Missing binary for ${platformKey}. Try reinstalling or set DOCDEX_DOWNLOAD_REPO to a repo with release assets.`
17
+ );
18
+ process.exit(1);
19
+ }
20
+
21
+ const child = spawn(binaryPath, process.argv.slice(2), { stdio: "inherit" });
22
+ child.on("exit", (code) => process.exit(code ?? 1));
23
+ child.on("error", (err) => {
24
+ console.error(`[docdex] failed to launch binary: ${err.message}`);
25
+ process.exit(1);
26
+ });
27
+ }
28
+
29
+ run();
package/lib/install.js ADDED
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const fs = require("node:fs");
5
+ const https = require("node:https");
6
+ const os = require("node:os");
7
+ const path = require("node:path");
8
+ const { pipeline } = require("node:stream/promises");
9
+ const tar = require("tar");
10
+
11
+ const pkg = require("../package.json");
12
+ const { artifactName, detectPlatformKey } = require("./platform");
13
+
14
+ const MAX_REDIRECTS = 5;
15
+ const USER_AGENT = "docdex-installer";
16
+ const PLACEHOLDER_REPO_TOKEN = /OWNER|REPO/i;
17
+
18
+ function parseRepoSlug() {
19
+ const envRepo = process.env.DOCDEX_DOWNLOAD_REPO;
20
+ if (envRepo) return envRepo;
21
+
22
+ const repoUrl = pkg.repository?.url || "";
23
+ const match = repoUrl.match(/github\.com[:/](.+?)(\.git)?$/);
24
+
25
+ if (match && match[1] && !PLACEHOLDER_REPO_TOKEN.test(match[1])) {
26
+ return match[1];
27
+ }
28
+
29
+ throw new Error("Set DOCDEX_DOWNLOAD_REPO env var or update package.json repository.url to owner/repo");
30
+ }
31
+
32
+ function getDownloadBase(repoSlug) {
33
+ return process.env.DOCDEX_DOWNLOAD_BASE || `https://github.com/${repoSlug}/releases/download`;
34
+ }
35
+
36
+ function getVersion() {
37
+ const envVersion = process.env.DOCDEX_VERSION;
38
+ const version = (envVersion || pkg.version || "").replace(/^v/, "");
39
+
40
+ if (!version) {
41
+ throw new Error("Missing package version; set DOCDEX_VERSION or package.json version");
42
+ }
43
+
44
+ return version;
45
+ }
46
+
47
+ function requestOptions() {
48
+ const headers = { "User-Agent": USER_AGENT };
49
+ const token = process.env.DOCDEX_GITHUB_TOKEN || process.env.GITHUB_TOKEN;
50
+ if (token) headers.Authorization = `Bearer ${token}`;
51
+ return { headers };
52
+ }
53
+
54
+ function download(url, dest, redirects = 0) {
55
+ if (redirects > MAX_REDIRECTS) {
56
+ throw new Error(`Too many redirects while fetching ${url}`);
57
+ }
58
+
59
+ return new Promise((resolve, reject) => {
60
+ https
61
+ .get(url, requestOptions(), (res) => {
62
+ if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
63
+ res.resume();
64
+ return download(res.headers.location, dest, redirects + 1).then(resolve, reject);
65
+ }
66
+
67
+ if (res.statusCode !== 200) {
68
+ res.resume();
69
+ return reject(new Error(`Download failed (${res.statusCode}) from ${url}`));
70
+ }
71
+
72
+ const file = fs.createWriteStream(dest);
73
+ pipeline(res, file).then(resolve).catch(reject);
74
+ })
75
+ .on("error", reject);
76
+ });
77
+ }
78
+
79
+ async function extractTarball(archivePath, targetDir) {
80
+ await fs.promises.mkdir(targetDir, { recursive: true });
81
+ await tar.x({ file: archivePath, cwd: targetDir, gzip: true });
82
+ }
83
+
84
+ async function main() {
85
+ const platformKey = detectPlatformKey();
86
+ const version = getVersion();
87
+ const repoSlug = parseRepoSlug();
88
+ const archive = artifactName(platformKey);
89
+ const downloadUrl = `${getDownloadBase(repoSlug)}/v${version}/${archive}`;
90
+ const distDir = path.join(__dirname, "..", "dist", platformKey);
91
+ const tmpFile = path.join(os.tmpdir(), `${archive}.${process.pid}.tgz`);
92
+
93
+ console.log(`[docdex] Fetching ${archive} for ${platformKey}...`);
94
+ await fs.promises.rm(distDir, { recursive: true, force: true });
95
+ await download(downloadUrl, tmpFile);
96
+ await extractTarball(tmpFile, distDir);
97
+
98
+ const binaryPath = path.join(distDir, "docdexd");
99
+ if (!fs.existsSync(binaryPath)) {
100
+ throw new Error(`Downloaded archive missing binary at ${binaryPath}`);
101
+ }
102
+
103
+ await fs.promises.chmod(binaryPath, 0o755).catch(() => {});
104
+ await fs.promises.rm(tmpFile, { force: true });
105
+ console.log(`[docdex] Installed binary to ${binaryPath}`);
106
+ }
107
+
108
+ main().catch((err) => {
109
+ console.error(`[docdex] install failed: ${err.message}`);
110
+ process.exit(1);
111
+ });
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ function detectLibc() {
4
+ const override = process.env.DOCDEX_LIBC;
5
+ if (override) {
6
+ const libc = override.toLowerCase();
7
+ if (libc === "musl" || libc === "gnu") {
8
+ return libc;
9
+ }
10
+ }
11
+
12
+ const report = typeof process.report?.getReport === "function" ? process.report.getReport() : null;
13
+ const glibcVersion = report?.header?.glibcVersionRuntime;
14
+ return glibcVersion ? "gnu" : "musl";
15
+ }
16
+
17
+ function detectPlatformKey() {
18
+ const platform = process.platform;
19
+ const arch = process.arch;
20
+
21
+ if (platform === "darwin") {
22
+ if (arch === "arm64") return "darwin-arm64";
23
+ if (arch === "x64") return "darwin-x64";
24
+ }
25
+
26
+ if (platform === "linux") {
27
+ const libc = detectLibc();
28
+ if (arch === "arm64") return `linux-arm64-${libc}`;
29
+ if (arch === "x64") return `linux-x64-${libc}`;
30
+ }
31
+
32
+ throw new Error(`Unsupported platform: ${platform}/${arch}`);
33
+ }
34
+
35
+ function artifactName(platformKey) {
36
+ return `docdexd-${platformKey}.tar.gz`;
37
+ }
38
+
39
+ module.exports = {
40
+ detectLibc,
41
+ detectPlatformKey,
42
+ artifactName
43
+ };
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "docdex",
3
+ "version": "0.1.0",
4
+ "description": "Docdex CLI as an npm-installable binary wrapper.",
5
+ "bin": {
6
+ "docdex": "bin/docdex.js",
7
+ "docdexd": "bin/docdex.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "lib",
12
+ "README.md",
13
+ "CHANGELOG.md",
14
+ "LICENSE"
15
+ ],
16
+ "scripts": {
17
+ "postinstall": "node ./lib/install.js"
18
+ },
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "os": [
23
+ "darwin",
24
+ "linux"
25
+ ],
26
+ "cpu": [
27
+ "arm64",
28
+ "x64"
29
+ ],
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/bekirdag/docdex.git"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/bekirdag/docdex/issues"
36
+ },
37
+ "homepage": "https://github.com/bekirdag/docdex#readme",
38
+ "license": "MIT",
39
+ "author": "bekir dağ",
40
+ "keywords": [
41
+ "docdex",
42
+ "search",
43
+ "cli"
44
+ ],
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "dependencies": {
49
+ "tar": "^6.2.1"
50
+ }
51
+ }