@magnet-ai/cli 0.1.0 → 0.1.1
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 +35 -0
- package/bin/download.js +23 -6
- package/bin/magnet.js +8 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @magnet-ai/cli
|
|
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) at install time. You do not need Node.js to run the CLI after installation.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @magnet-ai/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Then run:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
magnet --help
|
|
15
|
+
magnet issues list
|
|
16
|
+
magnet search "query"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
Set your Magnet API key before using the CLI:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
export MAGNET_API_KEY="your-uuid-api-key"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Get an API key from your [Magnet](https://www.magnet.run) organization settings.
|
|
28
|
+
|
|
29
|
+
## Full documentation
|
|
30
|
+
|
|
31
|
+
See the [main repository](https://github.com/toolkit-ai/magnet-cli) for commands, pagination, and other install options (direct download, build from source).
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
MIT
|
package/bin/download.js
CHANGED
|
@@ -8,7 +8,18 @@ const path = require('path');
|
|
|
8
8
|
const https = require('https');
|
|
9
9
|
const { execSync } = require('child_process');
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
// Use repo from package.json so it works when published from any org (e.g. toolkit-ai/magnet-cli)
|
|
12
|
+
function getRepo() {
|
|
13
|
+
try {
|
|
14
|
+
const pkg = require(path.join(__dirname, '..', 'package.json'));
|
|
15
|
+
const url = (pkg.repository && pkg.repository.url) || pkg.repository || '';
|
|
16
|
+
const m = url.match(/github\.com[:/]([^/]+\/[^/]+?)(?:\.git)?$/);
|
|
17
|
+
return m ? m[1] : 'toolkit-ai/magnet-cli';
|
|
18
|
+
} catch (_) {
|
|
19
|
+
return 'toolkit-ai/magnet-cli';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const REPO = process.env.MAGNET_CLI_REPO || getRepo();
|
|
12
23
|
const VERSION = process.env.MAGNET_CLI_VERSION || 'latest';
|
|
13
24
|
const BIN_DIR = path.join(__dirname, '..', 'bin');
|
|
14
25
|
const BINARY = process.platform === 'win32' ? 'magnet.exe' : 'magnet';
|
|
@@ -24,23 +35,29 @@ function getPlatform() {
|
|
|
24
35
|
return null;
|
|
25
36
|
}
|
|
26
37
|
|
|
27
|
-
function fetch(url) {
|
|
38
|
+
function fetch(url, redirects = 0) {
|
|
39
|
+
if (redirects > 5) return Promise.reject(new Error('Too many redirects'));
|
|
28
40
|
return new Promise((resolve, reject) => {
|
|
29
|
-
https.get(url, { headers: { 'User-Agent': 'magnet-cli-npm' } }, (res) => {
|
|
41
|
+
const req = https.get(url, { headers: { 'User-Agent': 'magnet-cli-npm' } }, (res) => {
|
|
30
42
|
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
31
|
-
|
|
43
|
+
const loc = res.headers.location;
|
|
44
|
+
if (loc) return fetch(loc, redirects + 1).then(resolve).catch(reject);
|
|
32
45
|
}
|
|
33
46
|
const chunks = [];
|
|
34
47
|
res.on('data', (c) => chunks.push(c));
|
|
35
48
|
res.on('end', () => resolve(Buffer.concat(chunks)));
|
|
36
49
|
res.on('error', reject);
|
|
37
|
-
})
|
|
50
|
+
});
|
|
51
|
+
req.on('error', reject);
|
|
38
52
|
});
|
|
39
53
|
}
|
|
40
54
|
|
|
41
55
|
async function getLatestTag() {
|
|
42
56
|
const data = await fetch(`https://api.github.com/repos/${REPO}/releases/latest`);
|
|
43
|
-
const
|
|
57
|
+
const text = data.toString();
|
|
58
|
+
if (text.length < 10) throw new Error('Empty response from GitHub');
|
|
59
|
+
const j = JSON.parse(text);
|
|
60
|
+
if (!j.tag_name) throw new Error('No releases found. Push a tag (e.g. v0.1.0) to trigger a release.');
|
|
44
61
|
return j.tag_name;
|
|
45
62
|
}
|
|
46
63
|
|
package/bin/magnet.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
3
4
|
const { spawnSync } = require('child_process');
|
|
4
5
|
|
|
5
6
|
const binDir = path.join(__dirname, '..', 'bin');
|
|
6
7
|
const binary = path.join(binDir, process.platform === 'win32' ? 'magnet.exe' : 'magnet');
|
|
7
8
|
|
|
9
|
+
if (!fs.existsSync(binary)) {
|
|
10
|
+
console.error('magnet: binary not found at', binary);
|
|
11
|
+
console.error('Run "npm install -g @magnet-ai/cli" again. If that fails, the postinstall could not download the binary.');
|
|
12
|
+
console.error('Ensure a GitHub Release exists (push a tag like v0.1.0) and the repo has prebuilt binaries.');
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
const result = spawnSync(binary, process.argv.slice(2), {
|
|
9
17
|
stdio: 'inherit',
|
|
10
18
|
windowsHide: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magnet-ai/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Magnet CLI - download the native binary for your platform",
|
|
5
5
|
"bin": {
|
|
6
6
|
"magnet": "bin/magnet.js"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/toolkit-ai/magnet-cli.git"
|
|
14
14
|
},
|
|
15
15
|
"keywords": ["magnet", "cli"],
|
|
16
16
|
"license": "MIT"
|