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