codeix 0.1.4

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.
Files changed (3) hide show
  1. package/install.js +110 -0
  2. package/package.json +34 -0
  3. package/run.js +20 -0
package/install.js ADDED
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // Postinstall script: downloads the prebuilt codeix binary from GitHub Releases.
5
+ // Zero dependencies — uses Node.js built-in modules only.
6
+
7
+ const https = require("https");
8
+ const fs = require("fs");
9
+ const path = require("path");
10
+ const { execSync } = require("child_process");
11
+ const zlib = require("zlib");
12
+
13
+ const VERSION = require("./package.json").version;
14
+ const REPO = "montanetech/codeix";
15
+
16
+ const PLATFORM_MAP = {
17
+ "darwin-arm64": "aarch64-apple-darwin",
18
+ "linux-x64": "x86_64-unknown-linux-gnu",
19
+ "win32-x64": "x86_64-pc-windows-msvc",
20
+ };
21
+
22
+ function getTarget() {
23
+ const key = `${process.platform}-${process.arch}`;
24
+ const target = PLATFORM_MAP[key];
25
+ if (!target) {
26
+ console.error(`codeix: unsupported platform ${key}`);
27
+ console.error(`Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`);
28
+ process.exit(1);
29
+ }
30
+ return target;
31
+ }
32
+
33
+ function getArchiveUrl(target) {
34
+ const ext = process.platform === "win32" ? "zip" : "tar.gz";
35
+ return `https://github.com/${REPO}/releases/download/v${VERSION}/codeix-${target}.${ext}`;
36
+ }
37
+
38
+ function download(url) {
39
+ return new Promise((resolve, reject) => {
40
+ https.get(url, (res) => {
41
+ // Follow redirects (GitHub releases redirect to S3)
42
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
43
+ return download(res.headers.location).then(resolve, reject);
44
+ }
45
+ if (res.statusCode !== 200) {
46
+ return reject(new Error(`HTTP ${res.statusCode} for ${url}`));
47
+ }
48
+ const chunks = [];
49
+ res.on("data", (chunk) => chunks.push(chunk));
50
+ res.on("end", () => resolve(Buffer.concat(chunks)));
51
+ res.on("error", reject);
52
+ }).on("error", reject);
53
+ });
54
+ }
55
+
56
+ function extractTarGz(buffer, destDir) {
57
+ // Write to temp file then extract with tar (available on macOS/Linux)
58
+ const tmpFile = path.join(destDir, "_codeix.tar.gz");
59
+ fs.writeFileSync(tmpFile, buffer);
60
+ execSync(`tar xzf "${tmpFile}" -C "${destDir}"`, { stdio: "ignore" });
61
+ fs.unlinkSync(tmpFile);
62
+ }
63
+
64
+ function extractZip(buffer, destDir) {
65
+ // Write to temp file then extract with PowerShell (Windows)
66
+ const tmpFile = path.join(destDir, "_codeix.zip");
67
+ fs.writeFileSync(tmpFile, buffer);
68
+ execSync(
69
+ `powershell -Command "Expand-Archive -Path '${tmpFile}' -DestinationPath '${destDir}' -Force"`,
70
+ { stdio: "ignore" }
71
+ );
72
+ fs.unlinkSync(tmpFile);
73
+ }
74
+
75
+ async function main() {
76
+ const target = getTarget();
77
+ const url = getArchiveUrl(target);
78
+ const binDir = path.join(__dirname, "bin");
79
+
80
+ // Skip if binary already exists (e.g. CI caching)
81
+ const binName = process.platform === "win32" ? "codeix.exe" : "codeix";
82
+ const binPath = path.join(binDir, binName);
83
+ if (fs.existsSync(binPath)) {
84
+ return;
85
+ }
86
+
87
+ console.log(`Downloading codeix v${VERSION} for ${target}...`);
88
+
89
+ fs.mkdirSync(binDir, { recursive: true });
90
+
91
+ const buffer = await download(url);
92
+
93
+ if (process.platform === "win32") {
94
+ extractZip(buffer, binDir);
95
+ } else {
96
+ extractTarGz(buffer, binDir);
97
+ fs.chmodSync(binPath, 0o755);
98
+ }
99
+
100
+ console.log(`Installed codeix to ${binPath}`);
101
+ }
102
+
103
+ main().catch((err) => {
104
+ console.error(`codeix install failed: ${err.message}`);
105
+ console.error("You can install manually from:");
106
+ console.error(` https://github.com/${REPO}/releases/tag/v${VERSION}`);
107
+ // Don't fail the install — the binary just won't be available
108
+ // This avoids breaking `npm install` in CI environments that don't need the binary
109
+ process.exit(0);
110
+ });
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "codeix",
3
+ "version": "0.1.4",
4
+ "description": "Portable, composable code index — build with tree-sitter, query via MCP",
5
+ "license": "MIT OR Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/montanetech/codeix"
9
+ },
10
+ "homepage": "https://github.com/montanetech/codeix",
11
+ "bin": {
12
+ "codeix": "run.js"
13
+ },
14
+ "scripts": {
15
+ "postinstall": "node install.js"
16
+ },
17
+ "os": [
18
+ "darwin",
19
+ "linux",
20
+ "win32"
21
+ ],
22
+ "cpu": [
23
+ "x64",
24
+ "arm64"
25
+ ],
26
+ "engines": {
27
+ "node": ">=16"
28
+ },
29
+ "files": [
30
+ "install.js",
31
+ "run.js",
32
+ "bin/"
33
+ ]
34
+ }
package/run.js ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { execFileSync } = require("child_process");
5
+ const path = require("path");
6
+
7
+ const ext = process.platform === "win32" ? ".exe" : "";
8
+ const bin = path.join(__dirname, "bin", "codeix" + ext);
9
+
10
+ try {
11
+ execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
12
+ } catch (e) {
13
+ if (e.status != null) {
14
+ process.exitCode = e.status;
15
+ } else {
16
+ console.error(`codeix: binary not found at ${bin}`);
17
+ console.error("Try reinstalling: npm install -g codeix");
18
+ process.exitCode = 1;
19
+ }
20
+ }