Skip to content

Commit

Permalink
feat: begin adding command for pretty printing useful debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommypop2 committed Jan 22, 2025
1 parent 4ce5f30 commit 9294c1b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/full-solid/src/debug/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/// This subcommand prints useful debug info to stdout
import { readFile } from "fs/promises";
import os from "os";
type DebugInfo = {
runtime: { name: string, version: string }
os: { platform: string, release: string }
packages: Record<string, string>
}
const getPackageJSON = async () => {
const f = await readFile("package.json");
const parsed = JSON.parse(f.toString());
return parsed;
}
const prettyPrintRecord = (record: Record<string, string>) => {
let str = "";
for (const key in record) {
const value = record[key];
str += ` ${key}: ${value}\n`
}
return str;
}

export const prettyPrint = (info: DebugInfo) => {
return `System:
OS: ${info.os.platform} ${info.os.release}
Runtime:
${info.runtime.name}: v${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 ?? {};
return {
runtime: {
name: "Node",
version: "22.10.4"
},
os: {
platform: os.platform(),
release: os.release()
},
packages
}
}
Empty file.
6 changes: 6 additions & 0 deletions packages/full-solid/tests/debuginfo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { it } from "vitest";
import { fetchDebugInfo, prettyPrint } from "../src/debug";

it("Runs", async () => {
console.log(prettyPrint(await fetchDebugInfo()))
})

0 comments on commit 9294c1b

Please sign in to comment.