Skip to content

Commit

Permalink
feat: add debug command to full CLI
Browse files Browse the repository at this point in the history
This command allows for printing system information useful for debugging purposes
  • Loading branch information
Tommypop2 committed Jan 23, 2025
1 parent 9294c1b commit cd20d01
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/full-solid/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ 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"
intro(`\n${color.bgCyan(color.black(` Solid CLI v${packageJson.version}`))}`);

const main = defineCommand({
subCommands: { create: createSolid(packageJson.version) },
subCommands: { create: createSolid(packageJson.version), debug: debuginfo },
});

runMain(main);
20 changes: 14 additions & 6 deletions packages/full-solid/src/debug/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/// This subcommand prints useful debug info to stdout
import { readFile } from "fs/promises";
import os from "os";
import { defineCommand } from "citty";
import { detectRuntime } from "./runtime-detector"
import * as p from "@clack/prompts";
type DebugInfo = {
runtime: { name: string, version: string }
os: { platform: string, release: string }
Expand All @@ -24,22 +27,27 @@ export const prettyPrint = (info: DebugInfo) => {
return `System:
OS: ${info.os.platform} ${info.os.release}
Runtime:
${info.runtime.name}: v${info.runtime.version}
${info.runtime.name}: ${info.runtime.version}
${Object.keys(info.packages).length !== 0 ? `Dependencies:
${prettyPrintRecord(info.packages)}` : ""}`
}
export const fetchDebugInfo = async (): Promise<DebugInfo> => {
const parsed = await getPackageJSON();
const packages: Record<string, string> = parsed.dependencies ?? {};
const runtime = detectRuntime();
return {
runtime: {
name: "Node",
version: "22.10.4"
},
runtime,
os: {
platform: os.platform(),
release: os.release()
},
packages
}
}
}

export const debuginfo = defineCommand({
async run(ctx) {
const info = await fetchDebugInfo();
p.log.info(prettyPrint(info));
},
})
20 changes: 20 additions & 0 deletions packages/full-solid/src/debug/runtime-detector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type RuntimeName = "Bun" | "Node" | "Deno"
type Runtime = { name: RuntimeName, version: string }
declare global {
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")
}

0 comments on commit cd20d01

Please sign in to comment.