@magnet-ai/cli 0.1.1 → 0.1.2
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 +12 -0
- package/bin/download.js +12 -3
- package/bin/magnet +0 -0
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -26,6 +26,18 @@ export MAGNET_API_KEY="your-uuid-api-key"
|
|
|
26
26
|
|
|
27
27
|
Get an API key from your [Magnet](https://www.magnet.run) organization settings.
|
|
28
28
|
|
|
29
|
+
## Test the download (before releasing)
|
|
30
|
+
|
|
31
|
+
From the `npm` folder, run the download script to fetch the binary from the latest GitHub Release:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
cd npm
|
|
35
|
+
npm run download
|
|
36
|
+
# or: node bin/download.js
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
To test against a specific release tag: `MAGNET_CLI_VERSION=v0.1.0 node bin/download.js`. Then run `./bin/magnet.js --help` to confirm the binary works.
|
|
40
|
+
|
|
29
41
|
## Full documentation
|
|
30
42
|
|
|
31
43
|
See the [main repository](https://github.com/toolkit-ai/magnet-cli) for commands, pagination, and other install options (direct download, build from source).
|
package/bin/download.js
CHANGED
|
@@ -35,13 +35,16 @@ function getPlatform() {
|
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
const FETCH_TIMEOUT_MS = 60000; // 60s for API / metadata
|
|
39
|
+
const DOWNLOAD_TIMEOUT_MS = 120000; // 120s for the binary tarball
|
|
40
|
+
|
|
41
|
+
function fetch(url, redirects = 0, timeoutMs = FETCH_TIMEOUT_MS) {
|
|
39
42
|
if (redirects > 5) return Promise.reject(new Error('Too many redirects'));
|
|
40
43
|
return new Promise((resolve, reject) => {
|
|
41
44
|
const req = https.get(url, { headers: { 'User-Agent': 'magnet-cli-npm' } }, (res) => {
|
|
42
45
|
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
43
46
|
const loc = res.headers.location;
|
|
44
|
-
if (loc) return fetch(loc, redirects + 1).then(resolve).catch(reject);
|
|
47
|
+
if (loc) return fetch(loc, redirects + 1, timeoutMs).then(resolve).catch(reject);
|
|
45
48
|
}
|
|
46
49
|
const chunks = [];
|
|
47
50
|
res.on('data', (c) => chunks.push(c));
|
|
@@ -49,6 +52,10 @@ function fetch(url, redirects = 0) {
|
|
|
49
52
|
res.on('error', reject);
|
|
50
53
|
});
|
|
51
54
|
req.on('error', reject);
|
|
55
|
+
req.setTimeout(timeoutMs, () => {
|
|
56
|
+
req.destroy();
|
|
57
|
+
reject(new Error('Request timed out after ' + (timeoutMs / 1000) + 's'));
|
|
58
|
+
});
|
|
52
59
|
});
|
|
53
60
|
}
|
|
54
61
|
|
|
@@ -67,13 +74,14 @@ async function main() {
|
|
|
67
74
|
console.warn('@magnet-ai/cli: No prebuilt binary for ' + process.platform + '/' + process.arch + '. Install from GitHub Releases.');
|
|
68
75
|
return;
|
|
69
76
|
}
|
|
77
|
+
console.log('@magnet-ai/cli: Downloading binary for ' + platform + '...');
|
|
70
78
|
const tag = VERSION === 'latest' ? await getLatestTag() : VERSION;
|
|
71
79
|
const archiveName = `magnet-cli-${platform}.tar.gz`;
|
|
72
80
|
const url = `https://github.com/${REPO}/releases/download/${tag}/${archiveName}`;
|
|
73
81
|
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
74
82
|
const destPath = path.join(BIN_DIR, BINARY);
|
|
75
83
|
try {
|
|
76
|
-
const buf = await fetch(url);
|
|
84
|
+
const buf = await fetch(url, 0, DOWNLOAD_TIMEOUT_MS);
|
|
77
85
|
if (buf.length < 1000) {
|
|
78
86
|
const text = buf.toString();
|
|
79
87
|
if (text.includes('Not Found')) throw new Error('Release not found: ' + tag);
|
|
@@ -92,6 +100,7 @@ async function main() {
|
|
|
92
100
|
fs.renameSync(extracted, destPath);
|
|
93
101
|
}
|
|
94
102
|
fs.chmodSync(destPath, 0o755);
|
|
103
|
+
console.log('@magnet-ai/cli: Done.');
|
|
95
104
|
} catch (e) {
|
|
96
105
|
console.warn('@magnet-ai/cli: Could not download binary:', e.message);
|
|
97
106
|
}
|
package/bin/magnet
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magnet-ai/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Magnet CLI - download the native binary for your platform",
|
|
5
5
|
"bin": {
|
|
6
6
|
"magnet": "bin/magnet.js"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
-
"postinstall": "node bin/download.js"
|
|
9
|
+
"postinstall": "node bin/download.js",
|
|
10
|
+
"download": "node bin/download.js"
|
|
10
11
|
},
|
|
11
12
|
"repository": {
|
|
12
13
|
"type": "git",
|
|
13
14
|
"url": "https://github.com/toolkit-ai/magnet-cli.git"
|
|
14
15
|
},
|
|
15
|
-
"keywords": [
|
|
16
|
+
"keywords": [
|
|
17
|
+
"magnet",
|
|
18
|
+
"cli"
|
|
19
|
+
],
|
|
16
20
|
"license": "MIT"
|
|
17
|
-
}
|
|
21
|
+
}
|