maleme 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/maleme.js +127 -0
- package/package.json +27 -0
package/bin/maleme.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
|
|
13
|
+
const TARGETS = {
|
|
14
|
+
"darwin-arm64": {
|
|
15
|
+
triple: "aarch64-apple-darwin",
|
|
16
|
+
packageName: "maleme-darwin-arm64",
|
|
17
|
+
},
|
|
18
|
+
"darwin-x64": {
|
|
19
|
+
triple: "x86_64-apple-darwin",
|
|
20
|
+
packageName: "maleme-darwin-x64",
|
|
21
|
+
},
|
|
22
|
+
"linux-arm64": {
|
|
23
|
+
triple: "aarch64-unknown-linux-musl",
|
|
24
|
+
packageName: "maleme-linux-arm64",
|
|
25
|
+
},
|
|
26
|
+
"linux-x64": {
|
|
27
|
+
triple: "x86_64-unknown-linux-musl",
|
|
28
|
+
packageName: "maleme-linux-x64",
|
|
29
|
+
},
|
|
30
|
+
"win32-x64": {
|
|
31
|
+
triple: "x86_64-pc-windows-msvc",
|
|
32
|
+
packageName: "maleme-win32-x64",
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function detectTarget() {
|
|
37
|
+
return TARGETS[`${process.platform}-${process.arch}`] ?? null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function localVendorPath(target) {
|
|
41
|
+
return path.resolve(
|
|
42
|
+
__dirname,
|
|
43
|
+
"..",
|
|
44
|
+
"..",
|
|
45
|
+
"platforms",
|
|
46
|
+
target.packageName,
|
|
47
|
+
"vendor",
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function installedVendorPath(target) {
|
|
52
|
+
const packageJsonPath = require.resolve(`${target.packageName}/package.json`);
|
|
53
|
+
return path.join(path.dirname(packageJsonPath), "vendor");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function resolveBinaryPath(target) {
|
|
57
|
+
let vendorRoot;
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
vendorRoot = installedVendorPath(target);
|
|
61
|
+
} catch {
|
|
62
|
+
const repoVendorRoot = localVendorPath(target);
|
|
63
|
+
if (existsSync(repoVendorRoot)) {
|
|
64
|
+
vendorRoot = repoVendorRoot;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!vendorRoot) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Missing optional dependency ${target.packageName}. Reinstall with: npm install -g maleme@latest`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const binaryName = process.platform === "win32" ? "maleme.exe" : "maleme";
|
|
75
|
+
return path.join(vendorRoot, target.triple, "maleme", binaryName);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const target = detectTarget();
|
|
79
|
+
if (!target) {
|
|
80
|
+
throw new Error(`Unsupported platform: ${process.platform} (${process.arch})`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const binaryPath = resolveBinaryPath(target);
|
|
84
|
+
if (!existsSync(binaryPath)) {
|
|
85
|
+
throw new Error(`Binary not found at ${binaryPath}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
89
|
+
stdio: "inherit",
|
|
90
|
+
env: process.env,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
child.on("error", (error) => {
|
|
94
|
+
console.error(error);
|
|
95
|
+
process.exit(1);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const forwardSignal = (signal) => {
|
|
99
|
+
if (!child.killed) {
|
|
100
|
+
try {
|
|
101
|
+
child.kill(signal);
|
|
102
|
+
} catch {
|
|
103
|
+
// Ignore signal forwarding errors from already-exiting children.
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
["SIGINT", "SIGTERM", "SIGHUP"].forEach((signal) => {
|
|
109
|
+
process.on(signal, () => forwardSignal(signal));
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const result = await new Promise((resolve) => {
|
|
113
|
+
child.on("exit", (code, signal) => {
|
|
114
|
+
if (signal) {
|
|
115
|
+
resolve({ signal });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
resolve({ code: code ?? 1 });
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
if ("signal" in result) {
|
|
124
|
+
process.kill(process.pid, result.signal);
|
|
125
|
+
} else {
|
|
126
|
+
process.exit(result.code);
|
|
127
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "maleme",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Profanity analytics CLI for local coding-agent histories.",
|
|
5
|
+
"license": "WTFPL",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"maleme": "bin/maleme.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/Yeuoly/maleme.git"
|
|
19
|
+
},
|
|
20
|
+
"optionalDependencies": {
|
|
21
|
+
"maleme-darwin-arm64": "0.1.0",
|
|
22
|
+
"maleme-darwin-x64": "0.1.0",
|
|
23
|
+
"maleme-linux-arm64": "0.1.0",
|
|
24
|
+
"maleme-linux-x64": "0.1.0",
|
|
25
|
+
"maleme-win32-x64": "0.1.0"
|
|
26
|
+
}
|
|
27
|
+
}
|