complior 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/bin/run.js ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ // Launcher for Complior TUI binary installed via npm
3
+ import { execFileSync } from "node:child_process";
4
+ import { join, dirname } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { existsSync } from "node:fs";
7
+
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+ const binaryName = process.platform === "win32" ? "complior.exe" : "complior";
10
+ const binaryPath = join(__dirname, binaryName);
11
+
12
+ if (!existsSync(binaryPath)) {
13
+ console.error("Complior binary not found. Run: npm rebuild ai-comply");
14
+ process.exit(1);
15
+ }
16
+
17
+ try {
18
+ execFileSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
19
+ } catch (err) {
20
+ process.exit(err.status ?? 1);
21
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "complior",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "description": "AI Act Compliance Scanner & Fixer — EU AI Act compliance in your terminal",
6
+ "license": "Apache-2.0",
7
+ "homepage": "https://complior.ai",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/a3ka/complior"
11
+ },
12
+ "keywords": [
13
+ "ai",
14
+ "compliance",
15
+ "eu-ai-act",
16
+ "scanner",
17
+ "fixer",
18
+ "tui",
19
+ "terminal"
20
+ ],
21
+ "bin": {
22
+ "ai-comply": "./bin/run.js",
23
+ "complior": "./bin/run.js"
24
+ },
25
+ "scripts": {
26
+ "postinstall": "node scripts/postinstall.js"
27
+ },
28
+ "files": [
29
+ "bin/",
30
+ "scripts/"
31
+ ],
32
+ "engines": {
33
+ "node": ">=18"
34
+ }
35
+ }
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+ // Downloads the platform-specific Complior binary after npm install
3
+ import { createWriteStream, chmodSync, existsSync, mkdirSync } from "node:fs";
4
+ import { join, dirname } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { get } from "node:https";
7
+ import { execSync } from "node:child_process";
8
+
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+ const BIN_DIR = join(__dirname, "..", "bin");
11
+ const REPO = "a3ka/complior";
12
+
13
+ function getPlatformArtifact() {
14
+ const platform = process.platform;
15
+ const arch = process.arch;
16
+
17
+ const map = {
18
+ "linux-x64": "complior-linux-x86_64",
19
+ "linux-arm64": "complior-linux-aarch64",
20
+ "darwin-x64": "complior-macos-x86_64",
21
+ "darwin-arm64": "complior-macos-arm64",
22
+ "win32-x64": "complior-windows-x86_64.exe",
23
+ };
24
+
25
+ const key = `${platform}-${arch}`;
26
+ const artifact = map[key];
27
+ if (!artifact) {
28
+ console.error(`Unsupported platform: ${key}`);
29
+ console.error("Supported: linux-x64, linux-arm64, darwin-x64, darwin-arm64, win32-x64");
30
+ process.exit(1);
31
+ }
32
+ return artifact;
33
+ }
34
+
35
+ function getLatestVersion() {
36
+ return new Promise((resolve, reject) => {
37
+ get(
38
+ `https://api.github.com/repos/${REPO}/releases/latest`,
39
+ { headers: { "User-Agent": "ai-comply-npm" } },
40
+ (res) => {
41
+ let data = "";
42
+ res.on("data", (chunk) => (data += chunk));
43
+ res.on("end", () => {
44
+ try {
45
+ resolve(JSON.parse(data).tag_name);
46
+ } catch {
47
+ reject(new Error("Failed to parse GitHub release info"));
48
+ }
49
+ });
50
+ }
51
+ ).on("error", reject);
52
+ });
53
+ }
54
+
55
+ function download(url, dest) {
56
+ return new Promise((resolve, reject) => {
57
+ get(url, { headers: { "User-Agent": "ai-comply-npm" } }, (res) => {
58
+ // Follow redirect
59
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
60
+ return download(res.headers.location, dest).then(resolve, reject);
61
+ }
62
+ if (res.statusCode !== 200) {
63
+ return reject(new Error(`Download failed: HTTP ${res.statusCode}`));
64
+ }
65
+ const file = createWriteStream(dest);
66
+ res.pipe(file);
67
+ file.on("finish", () => {
68
+ file.close();
69
+ resolve();
70
+ });
71
+ }).on("error", reject);
72
+ });
73
+ }
74
+
75
+ async function main() {
76
+ const artifact = getPlatformArtifact();
77
+ const binaryName = process.platform === "win32" ? "complior.exe" : "complior";
78
+ const binaryPath = join(BIN_DIR, binaryName);
79
+
80
+ // Skip if already downloaded
81
+ if (existsSync(binaryPath)) {
82
+ return;
83
+ }
84
+
85
+ console.log(`Downloading Complior binary for ${process.platform}-${process.arch}...`);
86
+
87
+ try {
88
+ const version = await getLatestVersion();
89
+ const url = `https://github.com/${REPO}/releases/download/${version}/${artifact}`;
90
+
91
+ if (!existsSync(BIN_DIR)) {
92
+ mkdirSync(BIN_DIR, { recursive: true });
93
+ }
94
+
95
+ await download(url, binaryPath);
96
+
97
+ if (process.platform !== "win32") {
98
+ chmodSync(binaryPath, 0o755);
99
+ }
100
+
101
+ console.log(`Complior ${version} installed successfully!`);
102
+ } catch (err) {
103
+ console.error("Failed to download Complior binary:", err.message);
104
+ console.error("You can install manually: https://complior.ai/docs/install");
105
+ // Don't fail npm install — binary can be downloaded later
106
+ }
107
+ }
108
+
109
+ main();
@@ -0,0 +1,58 @@
1
+ // US-S0205: Binary download — platform detection tests
2
+ // Run: node --test packages/npm/scripts/postinstall.test.js
3
+
4
+ import { describe, it } from "node:test";
5
+ import assert from "node:assert/strict";
6
+
7
+ // Platform → expected artifact name mapping (mirrors postinstall.js)
8
+ const ARTIFACT_MAP = {
9
+ "linux-x64": "complior-linux-x86_64",
10
+ "linux-arm64": "complior-linux-aarch64",
11
+ "darwin-x64": "complior-macos-x86_64",
12
+ "darwin-arm64": "complior-macos-arm64",
13
+ "win32-x64": "complior-windows-x86_64.exe",
14
+ };
15
+
16
+ function getPlatformArtifact(platform, arch) {
17
+ const key = `${platform}-${arch}`;
18
+ return ARTIFACT_MAP[key] ?? null;
19
+ }
20
+
21
+ describe("binary_download: platform detection", () => {
22
+ it("linux x64 → linux-x86_64 artifact", () => {
23
+ assert.equal(getPlatformArtifact("linux", "x64"), "complior-linux-x86_64");
24
+ });
25
+
26
+ it("linux arm64 → linux-aarch64 artifact", () => {
27
+ assert.equal(getPlatformArtifact("linux", "arm64"), "complior-linux-aarch64");
28
+ });
29
+
30
+ it("darwin x64 → macos-x86_64 artifact", () => {
31
+ assert.equal(getPlatformArtifact("darwin", "x64"), "complior-macos-x86_64");
32
+ });
33
+
34
+ it("darwin arm64 → macos-arm64 artifact", () => {
35
+ assert.equal(getPlatformArtifact("darwin", "arm64"), "complior-macos-arm64");
36
+ });
37
+
38
+ it("win32 x64 → windows-x86_64.exe artifact", () => {
39
+ assert.equal(getPlatformArtifact("win32", "x64"), "complior-windows-x86_64.exe");
40
+ });
41
+
42
+ it("unsupported platform → null", () => {
43
+ assert.equal(getPlatformArtifact("freebsd", "x64"), null);
44
+ });
45
+
46
+ it("all 5 supported platforms resolve to non-null", () => {
47
+ const supported = [
48
+ ["linux", "x64"], ["linux", "arm64"],
49
+ ["darwin", "x64"], ["darwin", "arm64"],
50
+ ["win32", "x64"],
51
+ ];
52
+ for (const [platform, arch] of supported) {
53
+ const artifact = getPlatformArtifact(platform, arch);
54
+ assert.ok(artifact, `${platform}-${arch} must have an artifact`);
55
+ assert.ok(artifact.startsWith("complior-"), "artifact must start with 'complior-'");
56
+ }
57
+ });
58
+ });