swapbook 0.1.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/README.md +15 -0
- package/bin/swapbook.js +71 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# swapbook
|
|
2
|
+
|
|
3
|
+
Run [Swapbook](https://github.com/Aejkatappaja/swapbook), the component workbench for htmx and hypermedia, without installing anything:
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npx swapbook --target :8080
|
|
7
|
+
# then open http://localhost:7007/__sb/
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
This package is a thin launcher: on first run it downloads the prebuilt Swapbook
|
|
11
|
+
binary for your platform from the matching GitHub Release, caches it, and runs
|
|
12
|
+
it. There is no build step and no postinstall.
|
|
13
|
+
|
|
14
|
+
See the [documentation](https://aejkatappaja.github.io/swapbook/) for the full
|
|
15
|
+
guide.
|
package/bin/swapbook.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Thin launcher for `npx swapbook`. On first run it downloads the prebuilt
|
|
3
|
+
// binary matching this package version + the host platform from GitHub
|
|
4
|
+
// Releases, caches it, and execs it. No build, no postinstall.
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const { spawnSync } = require("child_process");
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const os = require("os");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
const { version } = require("../package.json");
|
|
12
|
+
|
|
13
|
+
const REPO = "Aejkatappaja/swapbook";
|
|
14
|
+
|
|
15
|
+
function target() {
|
|
16
|
+
const p = process.platform;
|
|
17
|
+
const a = process.arch;
|
|
18
|
+
const goos = p === "darwin" ? "darwin" : p === "linux" ? "linux" : p === "win32" ? "windows" : null;
|
|
19
|
+
const goarch = a === "x64" ? "amd64" : a === "arm64" ? "arm64" : null;
|
|
20
|
+
if (!goos || !goarch) {
|
|
21
|
+
console.error(`swapbook: unsupported platform ${p}/${a}`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
goos,
|
|
26
|
+
goarch,
|
|
27
|
+
ext: goos === "windows" ? "zip" : "tar.gz",
|
|
28
|
+
bin: goos === "windows" ? "swapbook.exe" : "swapbook",
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function ensureBinary() {
|
|
33
|
+
const { goos, goarch, ext, bin } = target();
|
|
34
|
+
const cacheDir = path.join(os.homedir(), ".cache", "swapbook", version);
|
|
35
|
+
const binPath = path.join(cacheDir, bin);
|
|
36
|
+
if (fs.existsSync(binPath)) return binPath;
|
|
37
|
+
|
|
38
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
39
|
+
const asset = `swapbook_${version}_${goos}_${goarch}.${ext}`;
|
|
40
|
+
const url = `https://github.com/${REPO}/releases/download/v${version}/${asset}`;
|
|
41
|
+
process.stderr.write(`swapbook: downloading v${version} (${goos}/${goarch})\n`);
|
|
42
|
+
|
|
43
|
+
const res = await fetch(url); // Node 18+ follows the release redirect for us
|
|
44
|
+
if (!res.ok) {
|
|
45
|
+
console.error(`swapbook: download failed (${res.status}): ${url}`);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
const archive = path.join(cacheDir, asset);
|
|
49
|
+
fs.writeFileSync(archive, Buffer.from(await res.arrayBuffer()));
|
|
50
|
+
|
|
51
|
+
// bsdtar (the system `tar` on macOS, Linux and Windows 10+) extracts both
|
|
52
|
+
// .tar.gz and .zip, so we avoid an npm dependency.
|
|
53
|
+
const r = spawnSync("tar", ["-xf", archive, "-C", cacheDir], { stdio: "inherit" });
|
|
54
|
+
if (r.status !== 0) {
|
|
55
|
+
console.error("swapbook: extraction failed (a `tar` on PATH is required)");
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
fs.unlinkSync(archive);
|
|
59
|
+
fs.chmodSync(binPath, 0o755);
|
|
60
|
+
return binPath;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
ensureBinary()
|
|
64
|
+
.then((binPath) => {
|
|
65
|
+
const r = spawnSync(binPath, process.argv.slice(2), { stdio: "inherit" });
|
|
66
|
+
process.exit(r.status === null ? 1 : r.status);
|
|
67
|
+
})
|
|
68
|
+
.catch((err) => {
|
|
69
|
+
console.error("swapbook:", err && err.message ? err.message : err);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "swapbook",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Storybook for htmx and hypermedia. One binary, zero JS toolchain.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"swapbook": "bin/swapbook.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin/"
|
|
10
|
+
],
|
|
11
|
+
"keywords": [
|
|
12
|
+
"htmx",
|
|
13
|
+
"hypermedia",
|
|
14
|
+
"storybook",
|
|
15
|
+
"component-workbench",
|
|
16
|
+
"design-system"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/Aejkatappaja/swapbook.git"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://aejkatappaja.github.io/swapbook/",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": "Aejkatappaja",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"os": [
|
|
29
|
+
"darwin",
|
|
30
|
+
"linux",
|
|
31
|
+
"win32"
|
|
32
|
+
],
|
|
33
|
+
"cpu": [
|
|
34
|
+
"x64",
|
|
35
|
+
"arm64"
|
|
36
|
+
]
|
|
37
|
+
}
|