@circlesac/sandbox 0.0.0 → 26.2.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/bin/install.js +56 -0
- package/bin/install.sh +26 -0
- package/bin/sandbox +14 -0
- package/package.json +32 -3
package/bin/install.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import https from "node:https";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
const { version } = require("../package.json");
|
|
10
|
+
|
|
11
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
|
|
13
|
+
const REPO = "circlesac/sandbox";
|
|
14
|
+
|
|
15
|
+
const PLATFORMS = {
|
|
16
|
+
"darwin-x64": { artifact: "sandbox-darwin-amd64", ext: ".tar.gz" },
|
|
17
|
+
"darwin-arm64": { artifact: "sandbox-darwin-arm64", ext: ".tar.gz" },
|
|
18
|
+
"linux-x64": { artifact: "sandbox-linux-amd64", ext: ".tar.gz" },
|
|
19
|
+
"linux-arm64": { artifact: "sandbox-linux-arm64", ext: ".tar.gz" },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function download(url) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
https.get(url, (res) => {
|
|
25
|
+
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
26
|
+
return download(res.headers.location).then(resolve).catch(reject);
|
|
27
|
+
}
|
|
28
|
+
if (res.statusCode !== 200) return reject(new Error(`HTTP ${res.statusCode}`));
|
|
29
|
+
const chunks = [];
|
|
30
|
+
res.on("data", (c) => chunks.push(c));
|
|
31
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
32
|
+
res.on("error", reject);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (process.env.CI) process.exit(0);
|
|
38
|
+
|
|
39
|
+
const platform = `${process.platform}-${process.arch}`;
|
|
40
|
+
const info = PLATFORMS[platform];
|
|
41
|
+
if (!info) {
|
|
42
|
+
console.error(`Unsupported platform: ${platform}`);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { artifact, ext } = info;
|
|
47
|
+
const url = `https://github.com/${REPO}/releases/download/v${version}/${artifact}${ext}`;
|
|
48
|
+
const nativeDir = path.join(__dirname, "native");
|
|
49
|
+
fs.mkdirSync(nativeDir, { recursive: true });
|
|
50
|
+
|
|
51
|
+
const data = await download(url);
|
|
52
|
+
const tmp = path.join(nativeDir, `tmp${ext}`);
|
|
53
|
+
fs.writeFileSync(tmp, data);
|
|
54
|
+
execSync(`tar xzf "${tmp}"`, { cwd: nativeDir });
|
|
55
|
+
fs.unlinkSync(tmp);
|
|
56
|
+
fs.chmodSync(path.join(nativeDir, "sandbox"), 0o755);
|
package/bin/install.sh
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
REPO="circlesac/sandbox"
|
|
5
|
+
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
|
|
6
|
+
|
|
7
|
+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
|
8
|
+
ARCH=$(uname -m)
|
|
9
|
+
|
|
10
|
+
case "$ARCH" in
|
|
11
|
+
x86_64) ARCH="amd64" ;;
|
|
12
|
+
aarch64) ARCH="arm64" ;;
|
|
13
|
+
esac
|
|
14
|
+
|
|
15
|
+
case "$OS-$ARCH" in
|
|
16
|
+
darwin-arm64|darwin-amd64|linux-amd64|linux-arm64) ;;
|
|
17
|
+
*) echo "Unsupported platform: $OS-$ARCH"; exit 1 ;;
|
|
18
|
+
esac
|
|
19
|
+
|
|
20
|
+
VERSION=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name"' | cut -d'"' -f4)
|
|
21
|
+
URL="https://github.com/$REPO/releases/download/$VERSION/sandbox-$OS-$ARCH.tar.gz"
|
|
22
|
+
|
|
23
|
+
echo "Installing sandbox $VERSION..."
|
|
24
|
+
curl -fsSL "$URL" | tar xz -C "$INSTALL_DIR"
|
|
25
|
+
chmod +x "$INSTALL_DIR/sandbox"
|
|
26
|
+
echo "Installed to $INSTALL_DIR/sandbox"
|
package/bin/sandbox
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawnSync } = require("child_process");
|
|
3
|
+
const { existsSync } = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const bin = path.join(__dirname, "native", "sandbox");
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
if (!existsSync(bin)) {
|
|
10
|
+
await require("./install.js");
|
|
11
|
+
}
|
|
12
|
+
const result = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
13
|
+
process.exit(result.status ?? 1);
|
|
14
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
{
|
|
2
|
+
"bin": {
|
|
3
|
+
"sandbox": "bin/sandbox"
|
|
4
|
+
},
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@asteasolutions/zod-to-openapi": "^8.4.1",
|
|
7
|
+
"chanfana": "^3.0.0",
|
|
8
|
+
"dockerode": "^4.0.9",
|
|
9
|
+
"hono": "^4.11.9",
|
|
10
|
+
"nanoid": "^5.1.6",
|
|
11
|
+
"zod": "^4.3.6"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/bun": "latest",
|
|
15
|
+
"@types/dockerode": "^4.0.1",
|
|
16
|
+
"e2b": "^2.12.1",
|
|
17
|
+
"typescript": "^5",
|
|
18
|
+
"vitest": "^4.0.18"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"bin"
|
|
22
|
+
],
|
|
2
23
|
"name": "@circlesac/sandbox",
|
|
3
|
-
"version": "0.0.0",
|
|
4
|
-
"description": "E2B-compatible sandbox for local development with Docker",
|
|
5
24
|
"repository": {
|
|
25
|
+
"directory": "cli",
|
|
6
26
|
"type": "git",
|
|
7
27
|
"url": "https://github.com/circlesac/sandbox.git"
|
|
8
28
|
},
|
|
9
|
-
"
|
|
29
|
+
"scripts": {
|
|
30
|
+
"dev": "bun run src/index.ts",
|
|
31
|
+
"lint": "npx @circlesac/lint --all",
|
|
32
|
+
"postinstall": "node bin/install.js",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest",
|
|
35
|
+
"typecheck": "tsc --noEmit"
|
|
36
|
+
},
|
|
37
|
+
"type": "module",
|
|
38
|
+
"version": "26.2.1"
|
|
10
39
|
}
|