@gridland/demo 0.2.11 → 0.2.13
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/cli.mjs +24 -92
- package/dist/demo-names.json +1 -0
- package/dist/run.js +1920 -0
- package/package.json +26 -3
package/bin/cli.mjs
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
2
3
|
import { execSync, spawnSync } from "node:child_process";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
];
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const AVAILABLE_DEMOS = JSON.parse(
|
|
9
|
+
readFileSync(join(__dirname, "../dist/demo-names.json"), "utf-8")
|
|
10
|
+
);
|
|
12
11
|
|
|
13
12
|
const name = process.argv[2];
|
|
14
13
|
|
|
@@ -19,7 +18,7 @@ if (!name || name === "--help" || name === "-h") {
|
|
|
19
18
|
console.log(` ${d}`);
|
|
20
19
|
}
|
|
21
20
|
console.log("\nExamples:");
|
|
22
|
-
console.log("
|
|
21
|
+
console.log(" bunx @gridland/demo ascii");
|
|
23
22
|
console.log(" bunx @gridland/demo gradient");
|
|
24
23
|
process.exit(name ? 0 : 1);
|
|
25
24
|
}
|
|
@@ -30,89 +29,22 @@ if (!AVAILABLE_DEMOS.includes(name)) {
|
|
|
30
29
|
process.exit(1);
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
execSync("bun --version", { stdio: "ignore" });
|
|
36
|
-
return true;
|
|
37
|
-
} catch {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const useBun = hasBun();
|
|
43
|
-
|
|
44
|
-
const workDir = mkdtempSync(join(tmpdir(), "gridland-demo-"));
|
|
45
|
-
|
|
46
|
-
function cleanup() {
|
|
47
|
-
try {
|
|
48
|
-
rmSync(workDir, { recursive: true, force: true });
|
|
49
|
-
} catch {}
|
|
50
|
-
}
|
|
51
|
-
process.on("exit", cleanup);
|
|
52
|
-
process.on("SIGINT", () => { cleanup(); process.exit(130); });
|
|
53
|
-
process.on("SIGTERM", () => { cleanup(); process.exit(143); });
|
|
54
|
-
|
|
55
|
-
console.log("Setting up demo...");
|
|
56
|
-
|
|
32
|
+
// @opentui/core uses bun:ffi for the native terminal renderer, so we must run under bun
|
|
33
|
+
let hasBun = false;
|
|
57
34
|
try {
|
|
58
|
-
execSync(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const pkgPath = join(repoDir, "package.json");
|
|
67
|
-
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
68
|
-
pkg.workspaces = ["packages/web", "packages/ui", "packages/testing", "packages/docs"];
|
|
69
|
-
delete pkg.devDependencies;
|
|
70
|
-
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
71
|
-
|
|
72
|
-
// Deps only needed for building, not for running demos
|
|
73
|
-
const STRIP = new Set([
|
|
74
|
-
"tsup", "typescript", "vite", "esbuild", "postcss", "tailwindcss",
|
|
75
|
-
"@vitejs/plugin-react", "@happy-dom/global-registrator",
|
|
76
|
-
"@tailwindcss/postcss",
|
|
77
|
-
"@types/bun", "@types/node", "@types/react", "@types/react-dom",
|
|
78
|
-
"next", "fumadocs-core", "fumadocs-mdx", "fumadocs-ui",
|
|
79
|
-
"lucide-react", "react-dom",
|
|
80
|
-
]);
|
|
81
|
-
for (const ws of pkg.workspaces) {
|
|
82
|
-
const wsPkgPath = join(repoDir, ws, "package.json");
|
|
83
|
-
if (!existsSync(wsPkgPath)) continue;
|
|
84
|
-
const wsPkg = JSON.parse(readFileSync(wsPkgPath, "utf8"));
|
|
85
|
-
for (const field of ["dependencies", "devDependencies"]) {
|
|
86
|
-
if (!wsPkg[field]) continue;
|
|
87
|
-
for (const dep of Object.keys(wsPkg[field])) {
|
|
88
|
-
if (STRIP.has(dep)) delete wsPkg[field][dep];
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
writeFileSync(wsPkgPath, JSON.stringify(wsPkg, null, 2) + "\n");
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (useBun) {
|
|
95
|
-
execSync("bun install", { cwd: repoDir, stdio: ["ignore", "ignore", "inherit"] });
|
|
96
|
-
} else {
|
|
97
|
-
execSync("npm install", { cwd: repoDir, stdio: ["ignore", "ignore", "inherit"] });
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
console.log(`Running ${name} demo...`);
|
|
101
|
-
|
|
102
|
-
const demoScript = join("packages", "ui", "scripts", "demo.tsx");
|
|
103
|
-
|
|
104
|
-
if (useBun) {
|
|
105
|
-
spawnSync("bun", ["run", "--tsconfig-override", "packages/ui/tsconfig.json", demoScript, name], {
|
|
106
|
-
cwd: repoDir,
|
|
107
|
-
stdio: "inherit",
|
|
108
|
-
});
|
|
109
|
-
} else {
|
|
110
|
-
spawnSync("npx", ["tsx", "--tsconfig", "packages/ui/tsconfig.json", demoScript, name], {
|
|
111
|
-
cwd: repoDir,
|
|
112
|
-
stdio: "inherit",
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
} catch (err) {
|
|
116
|
-
console.error("Failed to run demo:", err.message);
|
|
35
|
+
execSync("bun --version", { stdio: "ignore" });
|
|
36
|
+
hasBun = true;
|
|
37
|
+
} catch {}
|
|
38
|
+
|
|
39
|
+
if (!hasBun) {
|
|
40
|
+
console.error("Error: bun is required to run gridland demos.");
|
|
41
|
+
console.error("Install it with: curl -fsSL https://bun.sh/install | bash");
|
|
42
|
+
console.error("\nThen run: bunx @gridland/demo " + name);
|
|
117
43
|
process.exit(1);
|
|
118
44
|
}
|
|
45
|
+
|
|
46
|
+
const runPath = join(__dirname, "../dist/run.js");
|
|
47
|
+
const { status } = spawnSync("bun", ["-e", `import("${runPath}").then(m => m.runDemo("${name}"))`], {
|
|
48
|
+
stdio: "inherit",
|
|
49
|
+
});
|
|
50
|
+
process.exit(status ?? 1);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
["gradient","ascii","table","spinner","select-input","multi-select","text-input","link","tab-bar","status-bar","modal","primitives","chat","terminal","landing"]
|