mafit 1.0.2 → 1.0.4
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 +24 -0
- package/bin/darwin-arm64/mafit +0 -0
- package/bin/darwin-x64/mafit +0 -0
- package/bin/linux-arm64/mafit +0 -0
- package/bin/linux-x64/mafit +0 -0
- package/bin/mafit.js +65 -0
- package/bin/win32-arm64/mafit.exe +0 -0
- package/bin/win32-x64/mafit.exe +0 -0
- package/package.json +13 -23
- package/dist/bin/mafit.cjs +0 -204
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# mafit
|
|
2
|
+
|
|
3
|
+
Mafit local agent CLI.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g mafit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Update
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install -g mafit@latest
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
mafit --help
|
|
21
|
+
mafit login
|
|
22
|
+
mafit status
|
|
23
|
+
mafit web
|
|
24
|
+
```
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/bin/mafit.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
|
|
11
|
+
const SUPPORTED_PLATFORM_KEYS = new Set([
|
|
12
|
+
"darwin-x64",
|
|
13
|
+
"darwin-arm64",
|
|
14
|
+
"linux-x64",
|
|
15
|
+
"linux-arm64",
|
|
16
|
+
"win32-x64",
|
|
17
|
+
"win32-arm64",
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
const platformKey = `${process.platform}-${process.arch}`;
|
|
21
|
+
|
|
22
|
+
if (!SUPPORTED_PLATFORM_KEYS.has(platformKey)) {
|
|
23
|
+
console.error(`Unsupported platform: ${process.platform} (${process.arch})`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const binaryName = process.platform === "win32" ? "mafit.exe" : "mafit";
|
|
28
|
+
const binaryPath = path.join(__dirname, platformKey, binaryName);
|
|
29
|
+
|
|
30
|
+
if (!existsSync(binaryPath)) {
|
|
31
|
+
console.error(`Missing mafit binary for ${platformKey}: ${binaryPath}`);
|
|
32
|
+
console.error("Reinstall mafit or rebuild the npm package with npm run build:binaries.");
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
37
|
+
stdio: "inherit",
|
|
38
|
+
env: {
|
|
39
|
+
...process.env,
|
|
40
|
+
MAFIT_MANAGED_BY_NPM: "1",
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
child.on("error", (error) => {
|
|
45
|
+
console.error(error);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const forwardSignal = (signal) => {
|
|
50
|
+
if (!child.killed) {
|
|
51
|
+
child.kill(signal);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
|
|
56
|
+
process.on(signal, () => forwardSignal(signal));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
child.on("exit", (code, signal) => {
|
|
60
|
+
if (signal) {
|
|
61
|
+
process.kill(process.pid, signal);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
process.exit(code ?? 1);
|
|
65
|
+
});
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mafit",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "Mafit local agent CLI",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"mafit": "
|
|
8
|
+
"mafit": "bin/mafit.js"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=16"
|
|
9
12
|
},
|
|
10
13
|
"files": [
|
|
11
|
-
"
|
|
14
|
+
"bin",
|
|
15
|
+
"README.md"
|
|
12
16
|
],
|
|
13
17
|
"scripts": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
"build:launcher": "node scripts/build-launcher.cjs",
|
|
18
|
-
"prepare:binaries:pkg": "node scripts/prepare-binaries-package.cjs",
|
|
19
|
-
"pack:binaries:pkg": "npm run prepare:binaries:pkg && npm pack --dry-run .release/mafit-binaries",
|
|
20
|
-
"publish:binaries:pkg": "npm run prepare:binaries:pkg && npm publish .release/mafit-binaries --access public --tag binaries",
|
|
21
|
-
"stage:binary": "node scripts/stage-binary.cjs",
|
|
22
|
-
"verify:binaries": "node scripts/verify-release-binaries.cjs",
|
|
23
|
-
"verify:binaries:core": "node scripts/verify-release-binaries.cjs --required linux-x64,win32-x64",
|
|
24
|
-
"build": "npm run sync:rust-version && npm run clean && npm run build:rust && npm run build:launcher",
|
|
25
|
-
"build:target": "npm run sync:rust-version && npm run build:rust && npm run build:launcher",
|
|
26
|
-
"start": "node scripts/run-bin.cjs",
|
|
27
|
-
"dev": "npm run build && npm run start",
|
|
28
|
-
"prepack": "npm run build:launcher"
|
|
29
|
-
},
|
|
30
|
-
"license": "MIT"
|
|
18
|
+
"build:binaries": "../scripts/build-npm-binaries.sh",
|
|
19
|
+
"pack:check": "npm pack --dry-run"
|
|
20
|
+
}
|
|
31
21
|
}
|
package/dist/bin/mafit.cjs
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const fs = require("node:fs");
|
|
3
|
-
const os = require("node:os");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const http = require("node:http");
|
|
6
|
-
const https = require("node:https");
|
|
7
|
-
const { spawnSync } = require("node:child_process");
|
|
8
|
-
|
|
9
|
-
const binaryByPlatform = {
|
|
10
|
-
"linux-x64": {
|
|
11
|
-
"id": "linux-x64",
|
|
12
|
-
"platform": "linux",
|
|
13
|
-
"arch": "x64",
|
|
14
|
-
"filename": "mafit-linux-x64",
|
|
15
|
-
"downloadFilename": "mafit-linux-x64"
|
|
16
|
-
},
|
|
17
|
-
"darwin-x64": {
|
|
18
|
-
"id": "darwin-x64",
|
|
19
|
-
"platform": "darwin",
|
|
20
|
-
"arch": "x64",
|
|
21
|
-
"filename": "mafit-darwin-x64",
|
|
22
|
-
"downloadFilename": "mafit-darwin-x64"
|
|
23
|
-
},
|
|
24
|
-
"darwin-arm64": {
|
|
25
|
-
"id": "darwin-arm64",
|
|
26
|
-
"platform": "darwin",
|
|
27
|
-
"arch": "arm64",
|
|
28
|
-
"filename": "mafit-darwin-arm64",
|
|
29
|
-
"downloadFilename": "mafit-darwin-arm64"
|
|
30
|
-
},
|
|
31
|
-
"win32-x64": {
|
|
32
|
-
"id": "win32-x64",
|
|
33
|
-
"platform": "win32",
|
|
34
|
-
"arch": "x64",
|
|
35
|
-
"filename": "mafit-win32-x64.exe",
|
|
36
|
-
"downloadFilename": "mafit-win32-x64.bin"
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const fallbackByPlatform = {
|
|
40
|
-
"win32-arm64": "win32-x64"
|
|
41
|
-
};
|
|
42
|
-
const version = "1.0.2";
|
|
43
|
-
const binaryVersion = "1.0.2-bin.0";
|
|
44
|
-
const defaultUrlTemplate = "https://cdn.jsdelivr.net/npm/mafit@{binaryVersion}/dist/bin/{downloadFilename}";
|
|
45
|
-
const key = `${process.platform}-${process.arch}`;
|
|
46
|
-
const resolvedKey = binaryByPlatform[key] ? key : (fallbackByPlatform[key] || "");
|
|
47
|
-
const target = binaryByPlatform[resolvedKey];
|
|
48
|
-
const binaryName = target && target.filename;
|
|
49
|
-
const ensureOnly = process.argv[2] === "--mafit-internal-ensure";
|
|
50
|
-
const cliArgs = ensureOnly ? [] : process.argv.slice(2);
|
|
51
|
-
|
|
52
|
-
if (!target || !binaryName) {
|
|
53
|
-
console.error(`mafit: unsupported platform ${key}`);
|
|
54
|
-
console.error("supported: linux-x64, darwin-x64, darwin-arm64, win32-x64");
|
|
55
|
-
process.exit(1);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (resolvedKey && resolvedKey !== key) {
|
|
59
|
-
console.error(`mafit: ${key} fallback to ${resolvedKey}`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const getCacheRoot = () => {
|
|
63
|
-
if (process.env.MAFIT_BINARY_CACHE_DIR) {
|
|
64
|
-
return process.env.MAFIT_BINARY_CACHE_DIR;
|
|
65
|
-
}
|
|
66
|
-
if (process.platform === "win32") {
|
|
67
|
-
const localAppData = process.env.LOCALAPPDATA || path.join(os.homedir(), "AppData", "Local");
|
|
68
|
-
return path.join(localAppData, "mafit", "bin");
|
|
69
|
-
}
|
|
70
|
-
const xdg = process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache");
|
|
71
|
-
return path.join(xdg, "mafit", "bin");
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const applyTemplate = (template) =>
|
|
75
|
-
template
|
|
76
|
-
.replaceAll("{version}", version)
|
|
77
|
-
.replaceAll("{binaryVersion}", binaryVersion)
|
|
78
|
-
.replaceAll("{id}", target.id)
|
|
79
|
-
.replaceAll("{platform}", target.platform)
|
|
80
|
-
.replaceAll("{arch}", target.arch)
|
|
81
|
-
.replaceAll("{filename}", target.filename)
|
|
82
|
-
.replaceAll("{downloadFilename}", target.downloadFilename || target.filename);
|
|
83
|
-
|
|
84
|
-
const urlTemplate = process.env.MAFIT_BINARY_URL_TEMPLATE || defaultUrlTemplate;
|
|
85
|
-
const downloadUrl = applyTemplate(urlTemplate);
|
|
86
|
-
const packagedBinaryPath = path.join(__dirname, binaryName);
|
|
87
|
-
const cacheBinaryPath = path.join(getCacheRoot(), version, binaryName);
|
|
88
|
-
|
|
89
|
-
const ensureExecutable = (filePath) => {
|
|
90
|
-
if (process.platform === "win32") {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
fs.chmodSync(filePath, 0o755);
|
|
95
|
-
} catch {}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const makeRequest = (urlString, redirectsLeft = 5) =>
|
|
99
|
-
new Promise((resolve, reject) => {
|
|
100
|
-
const lib = urlString.startsWith("https://") ? https : http;
|
|
101
|
-
const req = lib.get(
|
|
102
|
-
urlString,
|
|
103
|
-
{
|
|
104
|
-
headers: {
|
|
105
|
-
"User-Agent": `mafit/${version}`,
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
(res) => {
|
|
109
|
-
const status = res.statusCode || 0;
|
|
110
|
-
const location = res.headers.location;
|
|
111
|
-
|
|
112
|
-
if (status >= 300 && status < 400 && location) {
|
|
113
|
-
if (redirectsLeft <= 0) {
|
|
114
|
-
res.resume();
|
|
115
|
-
reject(new Error(`too many redirects: ${urlString}`));
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const nextUrl = new URL(location, urlString).toString();
|
|
119
|
-
res.resume();
|
|
120
|
-
resolve(makeRequest(nextUrl, redirectsLeft - 1));
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (status !== 200) {
|
|
125
|
-
res.resume();
|
|
126
|
-
reject(new Error(`download failed with status ${status}: ${urlString}`));
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
resolve(res);
|
|
131
|
-
}
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
req.on("error", reject);
|
|
135
|
-
req.setTimeout(30000, () => req.destroy(new Error("download timed out")));
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const downloadBinary = async (targetPath) => {
|
|
139
|
-
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
140
|
-
const tempPath = `${targetPath}.part-${process.pid}`;
|
|
141
|
-
const stream = fs.createWriteStream(tempPath, { mode: 0o755 });
|
|
142
|
-
const response = await makeRequest(downloadUrl);
|
|
143
|
-
|
|
144
|
-
await new Promise((resolve, reject) => {
|
|
145
|
-
response.pipe(stream);
|
|
146
|
-
response.on("error", reject);
|
|
147
|
-
stream.on("error", reject);
|
|
148
|
-
stream.on("finish", resolve);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
fs.renameSync(tempPath, targetPath);
|
|
152
|
-
ensureExecutable(targetPath);
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
const resolveBinaryPath = async () => {
|
|
156
|
-
if (fs.existsSync(packagedBinaryPath)) {
|
|
157
|
-
ensureExecutable(packagedBinaryPath);
|
|
158
|
-
return packagedBinaryPath;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (fs.existsSync(cacheBinaryPath)) {
|
|
162
|
-
ensureExecutable(cacheBinaryPath);
|
|
163
|
-
return cacheBinaryPath;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
console.error(`mafit: downloading ${target.id} binary...`);
|
|
167
|
-
try {
|
|
168
|
-
await downloadBinary(cacheBinaryPath);
|
|
169
|
-
} catch (error) {
|
|
170
|
-
console.error(`mafit: failed to download binary for ${target.id}`);
|
|
171
|
-
console.error(`url: ${downloadUrl}`);
|
|
172
|
-
console.error(`set MAFIT_BINARY_URL_TEMPLATE to your mirror if needed`);
|
|
173
|
-
console.error(error && error.message ? error.message : String(error));
|
|
174
|
-
process.exit(1);
|
|
175
|
-
}
|
|
176
|
-
return cacheBinaryPath;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
const run = async () => {
|
|
180
|
-
const binaryPath = await resolveBinaryPath();
|
|
181
|
-
if (ensureOnly) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const result = spawnSync(binaryPath, cliArgs, { stdio: "inherit" });
|
|
186
|
-
|
|
187
|
-
if (result.error) {
|
|
188
|
-
console.error(`mafit: failed to start binary: ${binaryPath}`);
|
|
189
|
-
console.error(result.error.message);
|
|
190
|
-
process.exit(1);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (typeof result.status === "number") {
|
|
194
|
-
process.exit(result.status);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
process.exit(1);
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
run().catch((error) => {
|
|
201
|
-
console.error("mafit: unexpected launcher error");
|
|
202
|
-
console.error(error && error.message ? error.message : String(error));
|
|
203
|
-
process.exit(1);
|
|
204
|
-
});
|