@gridland/demo 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.
Files changed (2) hide show
  1. package/bin/cli.mjs +88 -0
  2. package/package.json +11 -0
package/bin/cli.mjs ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ import { execSync, spawnSync } from "node:child_process";
3
+ import { mkdtempSync, rmSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+
7
+ const AVAILABLE_DEMOS = [
8
+ "gradient", "ascii", "table", "spinner", "select-input",
9
+ "multi-select", "text-input", "link", "tab-bar", "status-bar",
10
+ "modal", "primitives", "chat", "terminal",
11
+ ];
12
+
13
+ const name = process.argv[2];
14
+
15
+ if (!name || name === "--help" || name === "-h") {
16
+ console.log("Usage: gridland-demo <demo-name>\n");
17
+ console.log("Available demos:");
18
+ for (const d of AVAILABLE_DEMOS) {
19
+ console.log(` ${d}`);
20
+ }
21
+ console.log("\nExamples:");
22
+ console.log(" npx @gridland/demo ascii");
23
+ console.log(" bunx @gridland/demo gradient");
24
+ process.exit(name ? 0 : 1);
25
+ }
26
+
27
+ if (!AVAILABLE_DEMOS.includes(name)) {
28
+ console.error(`Unknown demo: "${name}"`);
29
+ console.error(`Available: ${AVAILABLE_DEMOS.join(", ")}`);
30
+ process.exit(1);
31
+ }
32
+
33
+ function hasBun() {
34
+ try {
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
+
57
+ try {
58
+ execSync(`git clone --depth 1 -q https://github.com/cjroth/gridland.git "${workDir}/gridland"`, {
59
+ stdio: "inherit",
60
+ });
61
+
62
+ const repoDir = join(workDir, "gridland");
63
+
64
+ if (useBun) {
65
+ execSync("bun install", { cwd: repoDir, stdio: ["ignore", "ignore", "inherit"] });
66
+ } else {
67
+ execSync("npm install", { cwd: repoDir, stdio: ["ignore", "ignore", "inherit"] });
68
+ }
69
+
70
+ console.log(`Running ${name} demo...`);
71
+
72
+ const demoScript = join("packages", "ui", "scripts", "demo.tsx");
73
+
74
+ if (useBun) {
75
+ spawnSync("bun", ["run", "--tsconfig-override", "packages/ui/tsconfig.json", demoScript, name], {
76
+ cwd: repoDir,
77
+ stdio: "inherit",
78
+ });
79
+ } else {
80
+ spawnSync("npx", ["tsx", "--tsconfig", "packages/ui/tsconfig.json", demoScript, name], {
81
+ cwd: repoDir,
82
+ stdio: "inherit",
83
+ });
84
+ }
85
+ } catch (err) {
86
+ console.error("Failed to run demo:", err.message);
87
+ process.exit(1);
88
+ }
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@gridland/demo",
3
+ "version": "0.1.0",
4
+ "description": "Run gridland component demos from anywhere",
5
+ "bin": {
6
+ "gridland-demo": "./bin/cli.mjs"
7
+ },
8
+ "files": ["bin"],
9
+ "keywords": ["gridland", "tui", "terminal", "demo"],
10
+ "license": "MIT"
11
+ }