@uniac/cli 0.0.0 → 0.0.1

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/README.md CHANGED
@@ -20,12 +20,18 @@ uniac --version
20
20
 
21
21
  ## How it works
22
22
 
23
- This package is a thin JS shim. It resolves the platform-specific binary
24
- (shipped via `@uniac/cli-<platform>-<arch>` packages, declared as
25
- `optionalDependencies`) and execs into it. No postinstall script, no
26
- runtime download.
23
+ This package ships a JS shim plus a postinstall script. After `npm install`,
24
+ the postinstall downloads the matching Go binary from this repo's
25
+ [GitHub Releases](https://github.com/uniac-ai/Uniac/releases) and drops it
26
+ next to the shim. The shim then `execFileSync`s the binary with your argv.
27
27
 
28
- Supported: `darwin-arm64`, `darwin-x64`, `linux-arm64`, `linux-x64`.
28
+ Supported platforms: `darwin-arm64`, `darwin-x64`, `linux-arm64`, `linux-x64`.
29
+
30
+ Requirements: Node 18+ (for built-in `fetch`) and `tar` on `$PATH`
31
+ (present by default on macOS, Linux, and Windows 10 1803+).
32
+
33
+ Set `UNIAC_SKIP_POSTINSTALL=1` to skip the binary download — useful for
34
+ sandboxes that vendor the binary by other means.
29
35
 
30
36
  ## License
31
37
 
package/bin/uniac.js CHANGED
@@ -1,26 +1,17 @@
1
1
  #!/usr/bin/env node
2
- const { execFileSync } = require('node:child_process');
3
- const path = require('node:path');
2
+ // Thin shim. The postinstall script downloads the matching `uniac` Go
3
+ // binary into this same directory; we just exec it with our argv.
4
+ import { execFileSync } from "node:child_process";
5
+ import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
4
7
 
5
- const pkg = `@uniac/cli-${process.platform}-${process.arch}`;
6
- const exe = process.platform === 'win32' ? 'uniac.exe' : 'uniac';
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+ const exe = process.platform === "win32" ? "uniac.exe" : "uniac";
7
10
 
8
- let binary;
9
11
  try {
10
- const pkgJson = require.resolve(`${pkg}/package.json`);
11
- binary = path.join(path.dirname(pkgJson), 'bin', exe);
12
- } catch {
13
- console.error(
14
- `[uniac] no prebuilt binary for ${process.platform}-${process.arch}.\n` +
15
- `Supported: darwin-arm64, darwin-x64, linux-arm64, linux-x64.\n` +
16
- `Grab the matching tar.gz from\n` +
17
- `https://github.com/uniac-ai/Uniac/releases and put \`uniac\` on $PATH.`
18
- );
19
- process.exit(1);
20
- }
21
-
22
- try {
23
- execFileSync(binary, process.argv.slice(2), { stdio: 'inherit' });
12
+ execFileSync(path.join(__dirname, exe), process.argv.slice(2), {
13
+ stdio: "inherit",
14
+ });
24
15
  } catch (err) {
25
- process.exit(typeof err.status === 'number' ? err.status : 1);
16
+ process.exit(typeof err.status === "number" ? err.status : 1);
26
17
  }
@@ -0,0 +1,25 @@
1
+ // Postinstall configuration. Pure data, no runtime logic — keep it
2
+ // trivial so platform/URL changes don't touch postinstall.js.
3
+ //
4
+ // The URL template must match the archive name_template in
5
+ // uniac_ctl/.goreleaser.yml — they're two sides of the same contract.
6
+ // GoReleaser produces archives named:
7
+ // uniac_<version>_<title-case OS>_<arch>.tar.gz
8
+ // where arch is x86_64 for amd64 and bare arch otherwise. The GitHub
9
+ // Release tag GoReleaser creates strips the `cli-` prefix from the
10
+ // user-pushed tag, so the URL path uses v<version>.
11
+
12
+ export const PLATFORMS = {
13
+ // process.platform-process.arch -> { os, arch } parts of the archive name
14
+ "darwin-arm64": { os: "Darwin", arch: "arm64" },
15
+ "darwin-x64": { os: "Darwin", arch: "x86_64" },
16
+ "linux-arm64": { os: "Linux", arch: "arm64" },
17
+ "linux-x64": { os: "Linux", arch: "x86_64" },
18
+ };
19
+
20
+ export const URL_TEMPLATE =
21
+ "https://github.com/uniac-ai/Uniac/releases/download/v{{version}}/uniac_{{version}}_{{os}}_{{arch}}.tar.gz";
22
+
23
+ // Name of the binary inside the tar.gz (top-level entry — GoReleaser
24
+ // doesn't nest under a directory).
25
+ export const BINARY_NAME = "uniac";
@@ -0,0 +1,77 @@
1
+ // Runs after `npm install @uniac/cli`. Downloads the matching Go binary
2
+ // from this repo's GitHub Release and drops it next to bin/uniac.js so
3
+ // the shim can exec it. Zero npm deps — uses Node 18+ built-in fetch +
4
+ // the system `tar` binary (Win10 1803+ ships one).
5
+ //
6
+ // Skip with UNIAC_SKIP_POSTINSTALL=1. Useful for sandbox / CI builds
7
+ // that vendor the binary by other means.
8
+
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+ import { execFileSync } from "node:child_process";
12
+ import { fileURLToPath } from "node:url";
13
+ import { PLATFORMS, URL_TEMPLATE, BINARY_NAME } from "./config.js";
14
+
15
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
16
+ const pkgRoot = path.resolve(__dirname, "..");
17
+ const binDir = path.join(pkgRoot, "bin");
18
+
19
+ async function main() {
20
+ if (process.env.UNIAC_SKIP_POSTINSTALL === "1") {
21
+ console.log("[uniac] UNIAC_SKIP_POSTINSTALL=1 — skipping binary download.");
22
+ return;
23
+ }
24
+
25
+ const key = `${process.platform}-${process.arch}`;
26
+ const target = PLATFORMS[key];
27
+ if (!target) {
28
+ console.error(
29
+ `[uniac] no prebuilt binary for ${key}.\n` +
30
+ `Supported: ${Object.keys(PLATFORMS).join(", ")}.\n` +
31
+ `Grab the matching tar.gz from\n` +
32
+ `https://github.com/uniac-ai/Uniac/releases and put \`${BINARY_NAME}\` on $PATH.`
33
+ );
34
+ process.exit(1);
35
+ }
36
+
37
+ const pkg = JSON.parse(
38
+ fs.readFileSync(path.join(pkgRoot, "package.json"), "utf8")
39
+ );
40
+ const version = pkg.version;
41
+ const url = URL_TEMPLATE
42
+ .replaceAll("{{version}}", version)
43
+ .replaceAll("{{os}}", target.os)
44
+ .replaceAll("{{arch}}", target.arch);
45
+
46
+ fs.mkdirSync(binDir, { recursive: true });
47
+ const tarPath = path.join(binDir, "uniac.tar.gz");
48
+
49
+ console.log(`[uniac] downloading ${url}`);
50
+ await downloadTo(url, tarPath);
51
+
52
+ // Extract just the binary — GoReleaser archives also include LICENSE
53
+ // and README*, which would clutter bin/. Positional arg restricts the
54
+ // extraction to a single entry.
55
+ execFileSync("tar", ["-xzf", tarPath, "-C", binDir, BINARY_NAME], {
56
+ stdio: "inherit",
57
+ });
58
+ fs.unlinkSync(tarPath);
59
+ fs.chmodSync(path.join(binDir, BINARY_NAME), 0o755);
60
+ console.log(`[uniac] installed ${BINARY_NAME} ${version} for ${key}`);
61
+ }
62
+
63
+ async function downloadTo(url, destPath) {
64
+ // Built-in fetch follows redirects automatically. GitHub Releases
65
+ // 302s to a CDN — Node 18+ handles that without extra code.
66
+ const res = await fetch(url);
67
+ if (!res.ok) {
68
+ throw new Error(`HTTP ${res.status} ${res.statusText} fetching ${url}`);
69
+ }
70
+ const buf = Buffer.from(await res.arrayBuffer());
71
+ fs.writeFileSync(destPath, buf);
72
+ }
73
+
74
+ main().catch((err) => {
75
+ console.error("[uniac] postinstall failed:", err.message);
76
+ process.exit(1);
77
+ });
package/package.json CHANGED
@@ -1,29 +1,28 @@
1
1
  {
2
2
  "name": "@uniac/cli",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
+ "type": "module",
4
5
  "description": "Control-plane CLI for Uniac services",
5
6
  "bin": {
6
7
  "uniac": "bin/uniac.js"
7
8
  },
9
+ "scripts": {
10
+ "postinstall": "node ./npm-install/postinstall.js"
11
+ },
8
12
  "files": [
9
13
  "bin/uniac.js",
14
+ "npm-install/",
10
15
  "README.md",
11
16
  "LICENSE"
12
17
  ],
13
18
  "engines": {
14
- "node": ">=16"
19
+ "node": ">=18"
15
20
  },
16
21
  "license": "MIT",
17
22
  "repository": {
18
23
  "type": "git",
19
24
  "url": "https://github.com/uniac-ai/Uniac.git",
20
- "directory": "uniac_ctl"
25
+ "directory": "uniac_cli/npm"
21
26
  },
22
- "homepage": "https://uniac.ai",
23
- "optionalDependencies": {
24
- "@uniac/cli-darwin-arm64": "0.0.0",
25
- "@uniac/cli-darwin-x64": "0.0.0",
26
- "@uniac/cli-linux-arm64": "0.0.0",
27
- "@uniac/cli-linux-x64": "0.0.0"
28
- }
27
+ "homepage": "https://uniac.ai"
29
28
  }