From eb21580efd302b37e007b2b2d28917d12e8c8c82 Mon Sep 17 00:00:00 2001 From: Thomas Beer <71586988+Tommypop2@users.noreply.github.com> Date: Thu, 23 Jan 2025 19:17:49 +0000 Subject: [PATCH] format feat: add `docs` command Allows for opening the Solid docs in the browser --- packages/full-solid/package.json | 1 + packages/full-solid/src/bin.ts | 13 ++++++- packages/full-solid/src/debug/index.ts | 38 ++++++++++--------- .../full-solid/src/debug/runtime-detector.ts | 34 ++++++++--------- packages/full-solid/src/start/index.ts | 3 ++ packages/full-solid/tests/debuginfo.test.ts | 4 +- pnpm-lock.yaml | 3 ++ 7 files changed, 58 insertions(+), 38 deletions(-) diff --git a/packages/full-solid/package.json b/packages/full-solid/package.json index b5314dc..feb18ac 100644 --- a/packages/full-solid/package.json +++ b/packages/full-solid/package.json @@ -35,6 +35,7 @@ "@types/node": "^22.10.7", "citty": "^0.1.6", "@solid-cli/create": "workspace:*", + "@solid-cli/utils": "workspace:*", "tsup": "^8.3.5", "typescript": "^5.7.3" }, diff --git a/packages/full-solid/src/bin.ts b/packages/full-solid/src/bin.ts index c06965d..d44602e 100644 --- a/packages/full-solid/src/bin.ts +++ b/packages/full-solid/src/bin.ts @@ -5,11 +5,20 @@ import { createSolid } from "@solid-cli/create"; import packageJson from "../package.json" with { type: "json" }; import { intro } from "@clack/prompts"; import * as color from "picocolors"; -import { debuginfo } from "./debug" +import { debuginfo } from "./debug"; +import { startCommands } from "./start"; +import { openInBrowser } from "@solid-cli/utils"; intro(`\n${color.bgCyan(color.black(` Solid CLI v${packageJson.version}`))}`); const main = defineCommand({ - subCommands: { create: createSolid(packageJson.version), debug: debuginfo }, + subCommands: { + create: createSolid(packageJson.version), debug: debuginfo, start: startCommands, docs: defineCommand({ + meta: { description: "Open the Solid Docs in your browser" }, + async run() { + openInBrowser("https://docs.solidjs.com") + } + }) + }, }); runMain(main); diff --git a/packages/full-solid/src/debug/index.ts b/packages/full-solid/src/debug/index.ts index 9d6fb65..e3fda26 100644 --- a/packages/full-solid/src/debug/index.ts +++ b/packages/full-solid/src/debug/index.ts @@ -2,35 +2,38 @@ import { readFile } from "fs/promises"; import os from "os"; import { defineCommand } from "citty"; -import { detectRuntime } from "./runtime-detector" +import { detectRuntime } from "./runtime-detector"; import * as p from "@clack/prompts"; type DebugInfo = { - runtime: { name: string, version: string } - os: { platform: string, release: string } - packages: Record -} + runtime: { name: string; version: string }; + os: { platform: string; release: string }; + packages: Record; +}; const getPackageJSON = async () => { const f = await readFile("package.json"); const parsed = JSON.parse(f.toString()); return parsed; -} +}; const prettyPrintRecord = (record: Record) => { let str = ""; for (const key in record) { const value = record[key]; - str += ` ${key}: ${value}\n` + str += ` ${key}: ${value}\n`; } return str; -} +}; export const prettyPrint = (info: DebugInfo) => { return `System: OS: ${info.os.platform} ${info.os.release} Runtime: ${info.runtime.name}: ${info.runtime.version} -${Object.keys(info.packages).length !== 0 ? `Dependencies: -${prettyPrintRecord(info.packages)}` : ""}` -} +${Object.keys(info.packages).length !== 0 + ? `Dependencies: +${prettyPrintRecord(info.packages)}` + : "" + }`; +}; export const fetchDebugInfo = async (): Promise => { const parsed = await getPackageJSON(); const packages: Record = parsed.dependencies ?? {}; @@ -39,15 +42,16 @@ export const fetchDebugInfo = async (): Promise => { runtime, os: { platform: os.platform(), - release: os.release() + release: os.release(), }, - packages - } -} + packages, + }; +}; export const debuginfo = defineCommand({ - async run(ctx) { + meta: { description: "Print important debug info" }, + async run(_ctx) { const info = await fetchDebugInfo(); p.log.info(prettyPrint(info)); }, -}) \ No newline at end of file +}); diff --git a/packages/full-solid/src/debug/runtime-detector.ts b/packages/full-solid/src/debug/runtime-detector.ts index 2a1da3a..014cc4b 100644 --- a/packages/full-solid/src/debug/runtime-detector.ts +++ b/packages/full-solid/src/debug/runtime-detector.ts @@ -1,20 +1,20 @@ -type RuntimeName = "Bun" | "Node" | "Deno" -type Runtime = { name: RuntimeName, version: string } +type RuntimeName = "Bun" | "Node" | "Deno"; +type Runtime = { name: RuntimeName; version: string }; declare global { - var Bun: { version: string } | undefined - var Deno: { version: { deno: string } } | undefined + var Bun: { version: string } | undefined; + var Deno: { version: { deno: string } } | undefined; } export const detectRuntime = (): Runtime => { - if (globalThis.Bun) { - return { name: "Bun", version: globalThis.Bun?.version } - } - if (globalThis.Deno) { - return { name: "Deno", version: globalThis.Deno?.version?.deno } - } - // @ts-ignore - if (typeof process !== undefined && !!process.versions?.node) { - // @ts-ignore - return { name: "Node", version: process?.version } - } - throw new Error("Unable to detect") -} + if (globalThis.Bun) { + return { name: "Bun", version: globalThis.Bun?.version }; + } + if (globalThis.Deno) { + return { name: "Deno", version: globalThis.Deno?.version?.deno }; + } + // @ts-ignore + if (typeof process !== undefined && !!process.versions?.node) { + // @ts-ignore + return { name: "Node", version: process?.version }; + } + throw new Error("Unable to detect"); +}; diff --git a/packages/full-solid/src/start/index.ts b/packages/full-solid/src/start/index.ts index e69de29..e69a1bd 100644 --- a/packages/full-solid/src/start/index.ts +++ b/packages/full-solid/src/start/index.ts @@ -0,0 +1,3 @@ +import { defineCommand } from "citty"; + +export const startCommands = defineCommand({}); diff --git a/packages/full-solid/tests/debuginfo.test.ts b/packages/full-solid/tests/debuginfo.test.ts index d492e8e..1a52062 100644 --- a/packages/full-solid/tests/debuginfo.test.ts +++ b/packages/full-solid/tests/debuginfo.test.ts @@ -2,5 +2,5 @@ import { it } from "vitest"; import { fetchDebugInfo, prettyPrint } from "../src/debug"; it("Runs", async () => { - console.log(prettyPrint(await fetchDebugInfo())) -}) \ No newline at end of file + console.log(prettyPrint(await fetchDebugInfo())); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fe1f309..ac2e8ca 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -88,6 +88,9 @@ importers: '@solid-cli/create': specifier: workspace:* version: link:../create + '@solid-cli/utils': + specifier: workspace:* + version: link:../utils '@types/node': specifier: ^22.10.7 version: 22.10.7