restorm-cli 1.0.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/bin/restorm.js +106 -0
- package/package.json +28 -0
package/bin/restorm.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Restorm installer bootstrap.
|
|
4
|
+
*
|
|
5
|
+
* If Restorm is already installed, exec it (all arguments pass through, so
|
|
6
|
+
* `restorm --run scenario.restorm` works). Otherwise, detect the platform,
|
|
7
|
+
* download the right build from the official release bucket, and guide the
|
|
8
|
+
* install. Zero dependencies.
|
|
9
|
+
*/
|
|
10
|
+
'use strict'
|
|
11
|
+
|
|
12
|
+
const { spawnSync, execFileSync } = require('node:child_process')
|
|
13
|
+
const { createWriteStream, existsSync, mkdirSync, chmodSync } = require('node:fs')
|
|
14
|
+
const { join } = require('node:path')
|
|
15
|
+
const { homedir, tmpdir } = require('node:os')
|
|
16
|
+
|
|
17
|
+
const BASE = 'https://dl.restorm.app/latest'
|
|
18
|
+
|
|
19
|
+
const CANDIDATES = {
|
|
20
|
+
linux: ['/opt/Restorm/restorm-bin', '/snap/bin/restorm', '/usr/bin/restorm'],
|
|
21
|
+
darwin: ['/Applications/Restorm.app/Contents/MacOS/Restorm'],
|
|
22
|
+
win32: [
|
|
23
|
+
join(process.env.LOCALAPPDATA || '', 'Programs', 'Restorm', 'Restorm.exe'),
|
|
24
|
+
join(process.env.ProgramFiles || 'C:\\Program Files', 'Restorm', 'Restorm.exe')
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function findInstalled() {
|
|
29
|
+
for (const p of CANDIDATES[process.platform] || []) {
|
|
30
|
+
if (p && existsSync(p)) return p
|
|
31
|
+
}
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function artifact() {
|
|
36
|
+
const { platform, arch } = process
|
|
37
|
+
if (platform === 'linux') return { url: `${BASE}/Restorm.AppImage`, file: 'Restorm.AppImage', run: true }
|
|
38
|
+
if (platform === 'darwin') {
|
|
39
|
+
return arch === 'arm64'
|
|
40
|
+
? { url: `${BASE}/Restorm-arm64.dmg`, file: 'Restorm-arm64.dmg' }
|
|
41
|
+
: { url: `${BASE}/Restorm.dmg`, file: 'Restorm.dmg' }
|
|
42
|
+
}
|
|
43
|
+
if (platform === 'win32') return { url: `${BASE}/Restorm-Setup.exe`, file: 'Restorm-Setup.exe' }
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function download(url, dest) {
|
|
48
|
+
const res = await fetch(url, { redirect: 'follow' })
|
|
49
|
+
if (!res.ok) throw new Error(`download failed: HTTP ${res.status} for ${url}`)
|
|
50
|
+
const total = Number(res.headers.get('content-length') || 0)
|
|
51
|
+
let done = 0
|
|
52
|
+
const out = createWriteStream(dest)
|
|
53
|
+
const reader = res.body.getReader()
|
|
54
|
+
for (;;) {
|
|
55
|
+
const { value, done: end } = await reader.read()
|
|
56
|
+
if (end) break
|
|
57
|
+
out.write(Buffer.from(value))
|
|
58
|
+
done += value.length
|
|
59
|
+
if (total && process.stdout.isTTY) {
|
|
60
|
+
process.stdout.write(`\r ${(done / 1048576).toFixed(1)} / ${(total / 1048576).toFixed(1)} MiB`)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
await new Promise((resolve, reject) => out.end((e) => (e ? reject(e) : resolve())))
|
|
64
|
+
if (process.stdout.isTTY) process.stdout.write('\n')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function main() {
|
|
68
|
+
const installed = findInstalled()
|
|
69
|
+
if (installed) {
|
|
70
|
+
const r = spawnSync(installed, process.argv.slice(2), { stdio: 'inherit' })
|
|
71
|
+
process.exit(r.status ?? 0)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const a = artifact()
|
|
75
|
+
if (!a) {
|
|
76
|
+
console.error(`Unsupported platform: ${process.platform}/${process.arch}`)
|
|
77
|
+
console.error('Downloads for every platform: https://restorm.app/download')
|
|
78
|
+
process.exit(1)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
console.log('Restorm is not installed yet — fetching the latest build…')
|
|
82
|
+
const dir = join(homedir(), 'Downloads')
|
|
83
|
+
const dest = join(existsSync(dir) ? dir : tmpdir(), a.file)
|
|
84
|
+
await download(a.url, dest)
|
|
85
|
+
console.log(`Saved to ${dest}`)
|
|
86
|
+
|
|
87
|
+
if (a.run && process.platform === 'linux') {
|
|
88
|
+
chmodSync(dest, 0o755)
|
|
89
|
+
console.log('Launching the AppImage… (prefer a package? https://restorm.app/download)')
|
|
90
|
+
const r = spawnSync(dest, process.argv.slice(2), { stdio: 'inherit' })
|
|
91
|
+
process.exit(r.status ?? 0)
|
|
92
|
+
}
|
|
93
|
+
if (process.platform === 'darwin') {
|
|
94
|
+
console.log('Opening the disk image — drag Restorm to Applications, then run `restorm` again.')
|
|
95
|
+
try { execFileSync('open', [dest]) } catch {}
|
|
96
|
+
} else if (process.platform === 'win32') {
|
|
97
|
+
console.log('Launching the installer — run `restorm` again once it finishes.')
|
|
98
|
+
try { execFileSync('cmd', ['/c', 'start', '', dest]) } catch {}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
main().catch((e) => {
|
|
103
|
+
console.error(e.message || e)
|
|
104
|
+
console.error('Manual downloads: https://restorm.app/download')
|
|
105
|
+
process.exit(1)
|
|
106
|
+
})
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "restorm-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Restorm — local-first API testing environment (REST, GraphQL, gRPC, WebSocket, MQTT, Redis, AMQP…). This package launches your installed Restorm or bootstraps the right build for your platform.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"restorm": "bin/restorm.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin"
|
|
10
|
+
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=18"
|
|
13
|
+
},
|
|
14
|
+
"license": "SEE LICENSE IN https://restorm.app",
|
|
15
|
+
"homepage": "https://restorm.app",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"api",
|
|
18
|
+
"rest",
|
|
19
|
+
"graphql",
|
|
20
|
+
"grpc",
|
|
21
|
+
"websocket",
|
|
22
|
+
"testing",
|
|
23
|
+
"client",
|
|
24
|
+
"mock",
|
|
25
|
+
"local-first"
|
|
26
|
+
],
|
|
27
|
+
"author": "MonsieurDev <contact@restorm.app>"
|
|
28
|
+
}
|