benmore 0.1.35
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 +18 -0
- package/bin/benmore.js +82 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# benmore
|
|
2
|
+
|
|
3
|
+
The Benmore CLI, for building, deploying and verifying apps on [benmore.ai](https://benmore.ai).
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npx benmore login # or: npm i -g benmore
|
|
7
|
+
benmore new my-app && cd my-app && benmore deploy
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
This package is a small launcher. On first run it downloads the CLI release
|
|
11
|
+
matching its version from
|
|
12
|
+
[Benmore-Studio/benmore-cli](https://github.com/Benmore-Studio/benmore-cli/releases),
|
|
13
|
+
checks the archive's SHA-256 against the release's `checksums.txt`, caches the
|
|
14
|
+
binary under `~/.cache/benmore/npm/<version>` (`%LOCALAPPDATA%\benmore\npm` on
|
|
15
|
+
Windows, or `$BENMORE_NPM_CACHE`) and runs it. It has no install scripts.
|
|
16
|
+
|
|
17
|
+
On macOS, Homebrew is the preferred install:
|
|
18
|
+
`brew install benmore-studio/benmore/benmore`.
|
package/bin/benmore.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Thin launcher for the Benmore CLI. On first run it downloads the release
|
|
3
|
+
// archive for this platform from the public Benmore-Studio/benmore-cli GitHub
|
|
4
|
+
// release matching this package's version, checks its SHA-256 against the
|
|
5
|
+
// release's checksums.txt, caches the binary and runs it. Later runs use the
|
|
6
|
+
// cache. No install scripts, so it works with `npx benmore` and with
|
|
7
|
+
// --ignore-scripts. The Homebrew cask (brew install benmore-studio/benmore/benmore)
|
|
8
|
+
// remains the preferred install on macOS.
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
const { spawnSync } = require('node:child_process');
|
|
12
|
+
const crypto = require('node:crypto');
|
|
13
|
+
const fs = require('node:fs');
|
|
14
|
+
const os = require('node:os');
|
|
15
|
+
const path = require('node:path');
|
|
16
|
+
|
|
17
|
+
const VERSION = require('../package.json').version;
|
|
18
|
+
const REPO = 'https://github.com/Benmore-Studio/benmore-cli/releases/download/v' + VERSION + '/';
|
|
19
|
+
const OS = { darwin: 'darwin', linux: 'linux', win32: 'windows' }[process.platform];
|
|
20
|
+
const ARCH = { x64: 'amd64', arm64: 'arm64' }[process.arch];
|
|
21
|
+
|
|
22
|
+
function fail(msg) {
|
|
23
|
+
process.stderr.write('benmore (npm launcher): ' + msg + '\n');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function cacheDir() {
|
|
28
|
+
const base = process.env.BENMORE_NPM_CACHE ||
|
|
29
|
+
(process.platform === 'win32'
|
|
30
|
+
? path.join(process.env.LOCALAPPDATA || os.homedir(), 'benmore', 'npm')
|
|
31
|
+
: path.join(process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache'), 'benmore', 'npm'));
|
|
32
|
+
return path.join(base, VERSION);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function download(url) {
|
|
36
|
+
const res = await fetch(url, { redirect: 'follow' });
|
|
37
|
+
if (!res.ok) fail('download failed: HTTP ' + res.status + ' ' + url);
|
|
38
|
+
return Buffer.from(await res.arrayBuffer());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function install(binPath) {
|
|
42
|
+
if (!OS || !ARCH || (OS === 'windows' && ARCH === 'arm64')) {
|
|
43
|
+
fail('no prebuilt CLI for ' + process.platform + '/' + process.arch + '. See https://benmore.ai/cli');
|
|
44
|
+
}
|
|
45
|
+
const archive = 'benmore_' + VERSION + '_' + OS + '_' + ARCH + (OS === 'windows' ? '.zip' : '.tar.gz');
|
|
46
|
+
process.stderr.write('Downloading Benmore CLI ' + VERSION + ' (' + OS + '/' + ARCH + ')...\n');
|
|
47
|
+
const sums = (await download(REPO + 'checksums.txt')).toString('utf8');
|
|
48
|
+
const line = sums.split('\n').find((l) => l.trim().endsWith(' ' + archive) || l.trim().endsWith(' ' + archive));
|
|
49
|
+
if (!line) fail('checksums.txt does not list ' + archive);
|
|
50
|
+
const want = line.trim().split(/\s+/)[0].toLowerCase();
|
|
51
|
+
const data = await download(REPO + archive);
|
|
52
|
+
const got = crypto.createHash('sha256').update(data).digest('hex');
|
|
53
|
+
if (got !== want) fail('checksum mismatch for ' + archive + ' (expected ' + want + ', got ' + got + '); nothing was installed');
|
|
54
|
+
|
|
55
|
+
const dir = path.dirname(binPath);
|
|
56
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
57
|
+
const work = fs.mkdtempSync(path.join(dir, '.tmp-'));
|
|
58
|
+
try {
|
|
59
|
+
const file = path.join(work, archive);
|
|
60
|
+
fs.writeFileSync(file, data);
|
|
61
|
+
// tar ships with macOS, Linux and Windows 10+ (bsdtar, which also reads zip).
|
|
62
|
+
const res = spawnSync('tar', ['-xf', file, '-C', work], { stdio: 'inherit' });
|
|
63
|
+
if (res.status !== 0) fail('could not extract ' + archive + ' (is tar installed?)');
|
|
64
|
+
const exe = OS === 'windows' ? 'benmore.exe' : 'benmore';
|
|
65
|
+
const extracted = path.join(work, exe);
|
|
66
|
+
if (!fs.existsSync(extracted)) fail(archive + ' did not contain ' + exe);
|
|
67
|
+
fs.chmodSync(extracted, 0o755);
|
|
68
|
+
fs.renameSync(extracted, binPath);
|
|
69
|
+
} finally {
|
|
70
|
+
fs.rmSync(work, { recursive: true, force: true });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function main() {
|
|
75
|
+
const binPath = path.join(cacheDir(), process.platform === 'win32' ? 'benmore.exe' : 'benmore');
|
|
76
|
+
if (!fs.existsSync(binPath)) await install(binPath);
|
|
77
|
+
const res = spawnSync(binPath, process.argv.slice(2), { stdio: 'inherit' });
|
|
78
|
+
if (res.error) fail(res.error.message);
|
|
79
|
+
process.exit(res.status === null ? 1 : res.status);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
main().catch((err) => fail(err && err.message ? err.message : String(err)));
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "benmore",
|
|
3
|
+
"version": "0.1.35",
|
|
4
|
+
"description": "The Benmore CLI: build, deploy and verify apps on benmore.ai",
|
|
5
|
+
"homepage": "https://benmore.ai/cli",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"bin": {
|
|
8
|
+
"benmore": "bin/benmore.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin/benmore.js",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=18"
|
|
16
|
+
},
|
|
17
|
+
"os": [
|
|
18
|
+
"darwin",
|
|
19
|
+
"linux",
|
|
20
|
+
"win32"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"benmore",
|
|
24
|
+
"cli",
|
|
25
|
+
"deploy"
|
|
26
|
+
]
|
|
27
|
+
}
|