orderk-cli 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/orderk.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { runOrderk } from "../dist/index.js";
3
+ runOrderk(process.argv.slice(2)).catch((error) => {
4
+ console.error(error?.stack || error?.message || String(error));
5
+ process.exit(1);
6
+ });
@@ -0,0 +1,2 @@
1
+ export { resolveOrderkBinary } from "./resolveBinary.js";
2
+ export { runOrderk, spawnOrderk } from "./spawn.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { resolveOrderkBinary } from "./resolveBinary.js";
2
+ export { runOrderk, spawnOrderk } from "./spawn.js";
@@ -0,0 +1 @@
1
+ export declare function resolveOrderkBinary(explicitPath?: string): string;
@@ -0,0 +1,25 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ export function resolveOrderkBinary(explicitPath) {
4
+ const candidates = [
5
+ explicitPath,
6
+ process.env.ORDERK_BIN,
7
+ resolvePackageLocalBinary(),
8
+ "orderk",
9
+ ].filter(Boolean);
10
+ for (const candidate of candidates) {
11
+ if (candidate === "orderk")
12
+ return candidate;
13
+ if (fs.existsSync(candidate))
14
+ return candidate;
15
+ }
16
+ throw new Error("orderk CLI not found. Install `cargo run -p orderk-cli --bin orderk` or set ORDERK_BIN.");
17
+ }
18
+ function resolvePackageLocalBinary() {
19
+ const cwd = process.cwd();
20
+ const packageVendor = path.join(cwd, "vendor", process.platform === "win32" ? "orderk.exe" : "orderk");
21
+ const repoRoot = path.resolve(cwd, "..", "..");
22
+ const releaseBinary = path.join(repoRoot, "target", "release", process.platform === "win32" ? "orderk.exe" : "orderk");
23
+ const debugBinary = path.join(repoRoot, "target", "debug", process.platform === "win32" ? "orderk.exe" : "orderk");
24
+ return [packageVendor, releaseBinary, debugBinary].find((p) => fs.existsSync(p));
25
+ }
@@ -0,0 +1,2 @@
1
+ export declare function spawnOrderk(args: string[], binaryPath?: string): import("child_process").ChildProcessWithoutNullStreams;
2
+ export declare function runOrderk(args: string[], binaryPath?: string): Promise<void>;
package/dist/spawn.js ADDED
@@ -0,0 +1,20 @@
1
+ import { spawn } from "node:child_process";
2
+ import { resolveOrderkBinary } from "./resolveBinary.js";
3
+ export function spawnOrderk(args, binaryPath) {
4
+ const bin = resolveOrderkBinary(binaryPath);
5
+ return spawn(bin, args, { stdio: "pipe" });
6
+ }
7
+ export function runOrderk(args, binaryPath) {
8
+ return new Promise((resolve, reject) => {
9
+ const child = spawnOrderk(args, binaryPath);
10
+ let stderr = "";
11
+ child.stderr.on("data", (chunk) => (stderr += chunk.toString()));
12
+ child.stdout.on("data", (chunk) => process.stdout.write(chunk));
13
+ child.on("error", reject);
14
+ child.on("close", (code) => {
15
+ if (code === 0)
16
+ return resolve();
17
+ reject(new Error(stderr.trim() || `orderk exited with code ${code}`));
18
+ });
19
+ });
20
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+
2
+ {
3
+ "name": "orderk-cli",
4
+ "version": "0.1.0",
5
+ "description": "Node wrapper for the orderk native CLI",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/bsbofmusic/orderk.git"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "bin": {
16
+ "orderk": "bin/orderk.js"
17
+ },
18
+ "exports": {
19
+ ".": "./dist/index.js",
20
+ "./resolve": "./dist/resolveBinary.js"
21
+ },
22
+ "files": [
23
+ "bin/",
24
+ "dist/",
25
+ "scripts/",
26
+ "README.md"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsc -p tsconfig.json",
30
+ "typecheck": "tsc -p tsconfig.json --noEmit",
31
+ "test": "node scripts/verify-binary.cjs",
32
+ "postinstall": "node scripts/postinstall.cjs"
33
+ },
34
+ "dependencies": {},
35
+ "devDependencies": {
36
+ "@types/node": "^20.0.0",
37
+ "typescript": "^5.0.0"
38
+ }
39
+ }
@@ -0,0 +1,88 @@
1
+
2
+ const fs = require("node:fs");
3
+ const path = require("node:path");
4
+
5
+ const pkg = require("../package.json");
6
+
7
+ main().catch((error) => {
8
+ console.warn(`[orderk] postinstall binary setup failed: ${error?.message || error}`);
9
+ });
10
+
11
+ async function main() {
12
+ const target = vendorBinaryPath();
13
+ if (fs.existsSync(target)) {
14
+ return;
15
+ }
16
+
17
+ if (process.env.ORDERK_SKIP_BINARY_DOWNLOAD === "1") {
18
+ console.warn("[orderk] skipped binary download because ORDERK_SKIP_BINARY_DOWNLOAD=1");
19
+ return;
20
+ }
21
+
22
+ const url = resolveBinaryUrl();
23
+ if (!url) {
24
+ console.warn("[orderk] no release binary is available for this platform; set ORDERK_BIN or build orderk locally");
25
+ return;
26
+ }
27
+
28
+ const response = await fetch(url);
29
+ if (!response.ok) {
30
+ throw new Error(`download failed with HTTP ${response.status}`);
31
+ }
32
+
33
+ const bytes = Buffer.from(await response.arrayBuffer());
34
+ fs.mkdirSync(path.dirname(target), { recursive: true });
35
+ fs.writeFileSync(target, bytes, { mode: 0o755 });
36
+ fs.chmodSync(target, 0o755);
37
+ console.log(`[orderk] downloaded native binary from ${url}`);
38
+ }
39
+
40
+ function vendorBinaryPath() {
41
+ return path.join(__dirname, "..", "vendor", binaryFilename());
42
+ }
43
+
44
+ function binaryFilename() {
45
+ return process.platform === "win32" ? "orderk.exe" : "orderk";
46
+ }
47
+
48
+ function resolveBinaryUrl() {
49
+ const explicit = process.env.ORDERK_BINARY_URL;
50
+ if (explicit) return explicit;
51
+
52
+ const platform = platformName();
53
+ const arch = process.arch;
54
+ if (!platform || !arch) return "";
55
+
56
+ // Current release pipeline ships Linux x64 first; the mapping below is future-proof.
57
+ const supported = platform === "linux" && arch === "x64";
58
+ if (!supported) return "";
59
+
60
+ const version = String(pkg.version || "0.1.0");
61
+ const repoUrl = repositoryUrl();
62
+ const { owner, repo } = parseRepo(repoUrl);
63
+ const asset = `orderk-v${version}-${platform}-${arch}`;
64
+ return `https://github.com/${owner}/${repo}/releases/download/v${version}/${asset}`;
65
+ }
66
+
67
+ function platformName() {
68
+ if (process.platform === "linux") return "linux";
69
+ if (process.platform === "darwin") return "darwin";
70
+ if (process.platform === "win32") return "windows";
71
+ return "";
72
+ }
73
+
74
+ function repositoryUrl() {
75
+ const repo = pkg.repository;
76
+ if (repo && typeof repo === "object" && typeof repo.url === "string") return repo.url;
77
+ if (typeof repo === "string") return repo;
78
+ return process.env.ORDERK_RELEASE_REPOSITORY || "https://github.com/bsbofmusic/orderk.git";
79
+ }
80
+
81
+ function parseRepo(url) {
82
+ const normalized = String(url).replace(/\.git$/, "");
83
+ const match = normalized.match(/github\.com[:/](.+?)\/(.+)$/);
84
+ if (!match) {
85
+ return { owner: "bsbofmusic", repo: "orderk" };
86
+ }
87
+ return { owner: match[1], repo: match[2] };
88
+ }
@@ -0,0 +1,8 @@
1
+
2
+ const { resolveOrderkBinary } = require("../dist/resolveBinary.js");
3
+ try {
4
+ const bin = resolveOrderkBinary(process.env.ORDERK_BIN);
5
+ console.log(bin);
6
+ } catch (error) {
7
+ console.log("skip: " + error.message);
8
+ }