@clanker-code/c2c 0.8.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/c2c-js-wrapper.js +9 -0
- package/index.js +70 -0
- package/package.json +24 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawnSync } = require("child_process");
|
|
3
|
+
const { resolveC2cBinary } = require("../index.js");
|
|
4
|
+
|
|
5
|
+
const binary = resolveC2cBinary();
|
|
6
|
+
const result = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
|
|
7
|
+
if (result.error) throw result.error;
|
|
8
|
+
if (result.signal) process.kill(process.pid, result.signal);
|
|
9
|
+
process.exit(result.status === null ? 1 : result.status);
|
package/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { spawnSync } = require("child_process");
|
|
4
|
+
|
|
5
|
+
const PACKAGE_BY_PLATFORM = {
|
|
6
|
+
"linux-x64": "@clanker-code/c2c-linux-x64",
|
|
7
|
+
"linux-arm64": "@clanker-code/c2c-linux-arm64",
|
|
8
|
+
"darwin-x64": "@clanker-code/c2c-darwin-x64",
|
|
9
|
+
"darwin-arm64": "@clanker-code/c2c-darwin-arm64",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function isExecutable(file) {
|
|
13
|
+
try {
|
|
14
|
+
fs.accessSync(file, fs.constants.X_OK);
|
|
15
|
+
return true;
|
|
16
|
+
} catch (_) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function pathEntries() {
|
|
22
|
+
return (process.env.PATH || "").split(path.delimiter).filter(Boolean);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function resolveOnPath(name) {
|
|
26
|
+
let currentWrapper = null;
|
|
27
|
+
try {
|
|
28
|
+
currentWrapper = process.argv[1] ? fs.realpathSync(process.argv[1]) : null;
|
|
29
|
+
} catch (_) {}
|
|
30
|
+
for (const dir of pathEntries()) {
|
|
31
|
+
const candidate = path.join(dir, name);
|
|
32
|
+
if (!isExecutable(candidate)) continue;
|
|
33
|
+
try {
|
|
34
|
+
if (currentWrapper && fs.realpathSync(candidate) === currentWrapper) continue;
|
|
35
|
+
} catch (_) {}
|
|
36
|
+
return candidate;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function resolvePlatformPackage() {
|
|
42
|
+
const key = `${process.platform}-${process.arch}`;
|
|
43
|
+
const pkg = PACKAGE_BY_PLATFORM[key];
|
|
44
|
+
if (!pkg) return null;
|
|
45
|
+
try {
|
|
46
|
+
return require.resolve(`${pkg}/bin/c2c`);
|
|
47
|
+
} catch (_) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function resolveC2cBinary() {
|
|
53
|
+
if (process.env.C2C_BIN) {
|
|
54
|
+
if (!isExecutable(process.env.C2C_BIN)) {
|
|
55
|
+
throw new Error(`C2C_BIN is set but is not executable: ${process.env.C2C_BIN}`);
|
|
56
|
+
}
|
|
57
|
+
return process.env.C2C_BIN;
|
|
58
|
+
}
|
|
59
|
+
const system = resolveOnPath(process.platform === "win32" ? "c2c.exe" : "c2c");
|
|
60
|
+
if (system) return system;
|
|
61
|
+
const packaged = resolvePlatformPackage();
|
|
62
|
+
if (packaged && isExecutable(packaged)) return packaged;
|
|
63
|
+
throw new Error(
|
|
64
|
+
`No c2c binary is available for ${process.platform}-${process.arch}. ` +
|
|
65
|
+
"Install c2c system-wide, install a supported @clanker-code/c2c platform package, " +
|
|
66
|
+
"or set C2C_BIN=/path/to/c2c."
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = { resolveC2cBinary };
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@clanker-code/c2c",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "Resolver and CLI wrapper for the c2c agent messaging binary",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/clankercode/c2c.git"
|
|
9
|
+
},
|
|
10
|
+
"main": "index.js",
|
|
11
|
+
"bin": {
|
|
12
|
+
"c2c": "bin/c2c-js-wrapper.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin/",
|
|
16
|
+
"index.js"
|
|
17
|
+
],
|
|
18
|
+
"optionalDependencies": {
|
|
19
|
+
"@clanker-code/c2c-linux-x64": "0.8.0",
|
|
20
|
+
"@clanker-code/c2c-linux-arm64": "0.8.0",
|
|
21
|
+
"@clanker-code/c2c-darwin-x64": "0.8.0",
|
|
22
|
+
"@clanker-code/c2c-darwin-arm64": "0.8.0"
|
|
23
|
+
}
|
|
24
|
+
}
|