@magnet-ai/cli 0.1.1 → 0.1.3
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 +13 -2
- package/bin/download.js +12 -3
- package/bin/magnet +0 -0
- package/bin/magnet.js +13 -4
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @magnet-ai/cli
|
|
2
2
|
|
|
3
|
-
Install the **Magnet CLI** via npm. This package downloads the native binary for your platform from [GitHub Releases](https://github.com/toolkit-ai/magnet-cli/releases)
|
|
3
|
+
Install the **Magnet CLI** via npm. This package downloads the native binary for your platform from [GitHub Releases](https://github.com/toolkit-ai/magnet-cli/releases) the **first time you run `magnet`** (so `npm install -g` finishes quickly). You do not need Node.js to run the CLI after the binary is downloaded.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ Install the **Magnet CLI** via npm. This package downloads the native binary for
|
|
|
8
8
|
npm install -g @magnet-ai/cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
The first time you run `magnet`, it will download the binary (~30s); after that it runs instantly. Example:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
magnet --help
|
|
@@ -26,6 +26,17 @@ 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
|
+
```
|
|
37
|
+
|
|
38
|
+
To test against a specific release tag: `MAGNET_CLI_VERSION=v0.1.0 npm run download`. Then run `./bin/magnet.js --help` to confirm the binary works.
|
|
39
|
+
|
|
29
40
|
## Full documentation
|
|
30
41
|
|
|
31
42
|
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/bin/magnet.js
CHANGED
|
@@ -7,10 +7,19 @@ const binDir = path.join(__dirname, '..', 'bin');
|
|
|
7
7
|
const binary = path.join(binDir, process.platform === 'win32' ? 'magnet.exe' : 'magnet');
|
|
8
8
|
|
|
9
9
|
if (!fs.existsSync(binary)) {
|
|
10
|
-
console.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
console.info('magnet: Downloading binary...');
|
|
11
|
+
const download = spawnSync(process.execPath, [path.join(__dirname, 'download.js')], {
|
|
12
|
+
stdio: 'inherit',
|
|
13
|
+
cwd: path.join(__dirname, '..'),
|
|
14
|
+
});
|
|
15
|
+
if (download.status !== 0) {
|
|
16
|
+
console.error('magnet: download failed. Ensure a GitHub Release exists (e.g. tag v0.1.0).');
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
if (!fs.existsSync(binary)) {
|
|
20
|
+
console.error('magnet: binary still missing after download.');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
14
23
|
}
|
|
15
24
|
|
|
16
25
|
const result = spawnSync(binary, process.argv.slice(2), {
|
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magnet-ai/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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
|
-
"
|
|
9
|
+
"download": "node bin/download.js"
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "https://github.com/toolkit-ai/magnet-cli.git"
|
|
14
14
|
},
|
|
15
|
-
"keywords": [
|
|
15
|
+
"keywords": [
|
|
16
|
+
"magnet",
|
|
17
|
+
"cli"
|
|
18
|
+
],
|
|
16
19
|
"license": "MIT"
|
|
17
|
-
}
|
|
20
|
+
}
|