@silvery/examples 0.5.1 → 0.5.2

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.ts +29 -28
  2. package/package.json +5 -1
package/bin/cli.ts CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env bun
1
+ #!/usr/bin/env node
2
2
  /**
3
3
  * silvery CLI
4
4
  *
@@ -66,20 +66,20 @@ const CATEGORY_COLOR: Record<string, string> = {
66
66
  }
67
67
 
68
68
  async function discoverExamples(): Promise<Example[]> {
69
- const { resolve } = await import("node:path")
70
- const examplesDir = resolve(new URL(".", import.meta.url).pathname, "../examples")
69
+ const { resolve, dirname } = await import("node:path")
70
+ const { fileURLToPath } = await import("node:url")
71
+ const { readdirSync } = await import("node:fs")
72
+ const __dirname = dirname(fileURLToPath(import.meta.url))
73
+ const examplesDir = resolve(__dirname, "../examples")
71
74
  const results: Example[] = []
72
75
 
73
76
  for (const dir of CATEGORY_DIRS) {
74
77
  const category = CATEGORY_DISPLAY[dir] ?? dir.charAt(0).toUpperCase() + dir.slice(1)
75
- const glob = new Bun.Glob("*.tsx")
76
78
  const dirPath = resolve(examplesDir, dir)
77
79
 
78
80
  try {
79
- for (const file of glob.scanSync({ cwd: dirPath })) {
80
- if (file.startsWith("_")) continue
81
-
82
- // Try to get meta from export, fall back to filename
81
+ const files = readdirSync(dirPath).filter((f: string) => f.endsWith(".tsx") && !f.startsWith("_"))
82
+ for (const file of files) {
83
83
  const name = file.replace(/\.tsx$/, "").replace(/-/g, " ")
84
84
  results.push({
85
85
  name,
@@ -213,40 +213,38 @@ async function exampleCommand(args: string[]): Promise<void> {
213
213
 
214
214
  console.log(`${DIM}Running ${BOLD}${match.name}${RESET}${DIM}...${RESET}\n`)
215
215
 
216
- const proc = Bun.spawn(["bun", "run", match.file], {
217
- stdio: ["inherit", "inherit", "inherit"],
218
- })
219
- const exitCode = await proc.exited
220
- process.exit(exitCode)
216
+ const { spawn } = await import("node:child_process")
217
+ const runtime = typeof globalThis.Bun !== "undefined" ? "bun" : "node"
218
+ const proc = spawn(runtime, ["run", match.file], { stdio: "inherit" })
219
+ proc.on("exit", (code) => process.exit(code ?? 1))
221
220
  }
222
221
 
223
222
  async function doctorCommand(): Promise<void> {
224
- // Try to resolve termtest from @silvery/ag-term (installed as dependency of silvery)
225
- const { resolve } = await import("node:path")
223
+ const { resolve, dirname } = await import("node:path")
224
+ const { fileURLToPath } = await import("node:url")
225
+ const __dirname = dirname(fileURLToPath(import.meta.url))
226
226
 
227
- // In monorepo: ../../ag-term/src/termtest.ts
228
- // In npm install: node_modules/@silvery/ag-term/src/termtest.ts
229
227
  const candidates = [
230
- resolve(new URL(".", import.meta.url).pathname, "../../ag-term/src/termtest.ts"),
231
- resolve(new URL(".", import.meta.url).pathname, "../node_modules/@silvery/ag-term/src/termtest.ts"),
228
+ resolve(__dirname, "../../ag-term/src/termtest.ts"),
229
+ resolve(__dirname, "../node_modules/@silvery/ag-term/src/termtest.ts"),
232
230
  ]
233
231
 
234
232
  for (const termtestPath of candidates) {
235
233
  try {
236
234
  const { stat } = await import("node:fs/promises")
237
235
  await stat(termtestPath)
238
- const proc = Bun.spawn(["bun", "run", termtestPath], {
239
- stdio: ["inherit", "inherit", "inherit"],
240
- })
241
- const exitCode = await proc.exited
242
- process.exit(exitCode)
236
+ const { spawn } = await import("node:child_process")
237
+ const runtime = typeof globalThis.Bun !== "undefined" ? "bun" : "node"
238
+ const proc = spawn(runtime, ["run", termtestPath], { stdio: "inherit" })
239
+ proc.on("exit", (code) => process.exit(code ?? 1))
240
+ return
243
241
  } catch {
244
242
  continue
245
243
  }
246
244
  }
247
245
 
248
246
  console.error(`${RED}Error:${RESET} Could not find terminal diagnostics.`)
249
- console.error(`${DIM}Make sure silvery is installed: bun add silvery${RESET}`)
247
+ console.error(`${DIM}Make sure silvery is installed: npm install silvery${RESET}`)
250
248
  process.exit(1)
251
249
  }
252
250
 
@@ -272,9 +270,12 @@ async function main(): Promise<void> {
272
270
 
273
271
  if (args.includes("--version") || args.includes("-v")) {
274
272
  try {
275
- const { resolve } = await import("node:path")
276
- const pkgPath = resolve(new URL(".", import.meta.url).pathname, "../package.json")
277
- const pkg = await Bun.file(pkgPath).json()
273
+ const { resolve, dirname } = await import("node:path")
274
+ const { fileURLToPath } = await import("node:url")
275
+ const { readFileSync } = await import("node:fs")
276
+ const __dirname = dirname(fileURLToPath(import.meta.url))
277
+ const pkgPath = resolve(__dirname, "../package.json")
278
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf8"))
278
279
  console.log(`@silvery/examples ${pkg.version}`)
279
280
  } catch {
280
281
  console.log("@silvery/examples (version unknown)")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@silvery/examples",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Example apps and component demos for silvery — bunx @silvery/examples <name>",
5
5
  "license": "MIT",
6
6
  "author": "Bjørn Stabell <bjorn@stabell.org>",
@@ -24,5 +24,9 @@
24
24
  "@silvery/ag-term": "0.5.0",
25
25
  "@silvery/create": "0.5.0",
26
26
  "silvery": "0.11.1"
27
+ },
28
+ "engines": {
29
+ "bun": ">=1.0",
30
+ "node": ">=23.6.0"
27
31
  }
28
32
  }