@openduo/searchis 0.2.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/searchis ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('../run.js');
package/install.js ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const https = require("https");
5
+ const http = require("http");
6
+ const fs = require("fs");
7
+ const path = require("path");
8
+ const { URL } = require("url");
9
+
10
+ const pkg = require("./package.json");
11
+ const version = pkg.version;
12
+
13
+ const PLATFORM_MAP = {
14
+ darwin: "darwin",
15
+ linux: "linux",
16
+ win32: "windows",
17
+ };
18
+
19
+ const ARCH_MAP = {
20
+ x64: "amd64",
21
+ arm64: "arm64",
22
+ };
23
+
24
+ function getBinaryName() {
25
+ const platform = PLATFORM_MAP[process.platform];
26
+ const arch = ARCH_MAP[process.arch];
27
+
28
+ if (!platform || !arch) {
29
+ throw new Error(
30
+ `Unsupported platform/arch: ${process.platform}/${process.arch}`
31
+ );
32
+ }
33
+
34
+ const ext = process.platform === "win32" ? ".exe" : "";
35
+ return `searchis-${platform}-${arch}${ext}`;
36
+ }
37
+
38
+ function download(url, dest, maxRedirects = 5) {
39
+ return new Promise((resolve, reject) => {
40
+ if (maxRedirects <= 0) {
41
+ return reject(new Error("Too many redirects"));
42
+ }
43
+
44
+ const parsedUrl = new URL(url);
45
+ const client = parsedUrl.protocol === "https:" ? https : http;
46
+
47
+ client
48
+ .get(url, { headers: { "User-Agent": "searchis-npm-installer" } }, (res) => {
49
+ // Follow redirects (GitHub releases redirect to S3)
50
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
51
+ return download(res.headers.location, dest, maxRedirects - 1).then(
52
+ resolve,
53
+ reject
54
+ );
55
+ }
56
+
57
+ if (res.statusCode !== 200) {
58
+ return reject(
59
+ new Error(`Download failed: HTTP ${res.statusCode} for ${url}`)
60
+ );
61
+ }
62
+
63
+ const file = fs.createWriteStream(dest);
64
+ res.pipe(file);
65
+ file.on("finish", () => {
66
+ file.close(resolve);
67
+ });
68
+ file.on("error", (err) => {
69
+ fs.unlink(dest, () => {});
70
+ reject(err);
71
+ });
72
+ })
73
+ .on("error", reject);
74
+ });
75
+ }
76
+
77
+ async function main() {
78
+ const binaryName = getBinaryName();
79
+ const url = `https://github.com/rectified-flow/searchis/releases/download/v${version}/${binaryName}`;
80
+ const binDir = path.join(__dirname, "bin");
81
+ const ext = process.platform === "win32" ? ".exe" : "";
82
+ const dest = path.join(binDir, `searchis${ext}`);
83
+
84
+ // Ensure bin directory exists
85
+ if (!fs.existsSync(binDir)) {
86
+ fs.mkdirSync(binDir, { recursive: true });
87
+ }
88
+
89
+ console.log(`Downloading searchis v${version} for ${process.platform}/${process.arch}...`);
90
+ console.log(` ${url}`);
91
+
92
+ await download(url, dest);
93
+
94
+ // Make executable on unix
95
+ if (process.platform !== "win32") {
96
+ fs.chmodSync(dest, 0o755);
97
+ }
98
+
99
+ console.log(`searchis v${version} installed successfully.`);
100
+ }
101
+
102
+ main().catch((err) => {
103
+ console.error(`Warning: Failed to download searchis binary: ${err.message}`);
104
+ console.error("The 'searchis' command will not work until the binary is available.");
105
+ console.error("You can manually download it from:");
106
+ console.error(` https://github.com/rectified-flow/searchis/releases/tag/v${version}`);
107
+ // Exit 0 so npm install doesn't fail
108
+ process.exit(0);
109
+ });
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@openduo/searchis",
3
+ "version": "0.2.0",
4
+ "description": "Searchis evidence retrieval CLI",
5
+ "bin": {
6
+ "searchis": "bin/searchis"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js"
10
+ },
11
+ "files": [
12
+ "bin/",
13
+ "install.js",
14
+ "run.js"
15
+ ],
16
+ "os": [
17
+ "darwin",
18
+ "linux",
19
+ "win32"
20
+ ],
21
+ "cpu": [
22
+ "x64",
23
+ "arm64"
24
+ ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/rectified-flow/searchis.git",
28
+ "directory": "packages/cli-npm"
29
+ },
30
+ "license": "MIT"
31
+ }
package/run.js ADDED
@@ -0,0 +1,21 @@
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", `searchis${ext}`);
9
+
10
+ try {
11
+ execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
12
+ } catch (e) {
13
+ if (e.code === "ENOENT") {
14
+ console.error(
15
+ "searchis binary not found. Run `npm rebuild searchis` or reinstall the package."
16
+ );
17
+ console.error(`Expected binary at: ${bin}`);
18
+ process.exit(1);
19
+ }
20
+ process.exit(e.status ?? 1);
21
+ }