Skip to content

Commit 9294c1b

Browse files
committed
feat: begin adding command for pretty printing useful debug info
1 parent 4ce5f30 commit 9294c1b

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/// This subcommand prints useful debug info to stdout
2+
import { readFile } from "fs/promises";
3+
import os from "os";
4+
type DebugInfo = {
5+
runtime: { name: string, version: string }
6+
os: { platform: string, release: string }
7+
packages: Record<string, string>
8+
}
9+
const getPackageJSON = async () => {
10+
const f = await readFile("package.json");
11+
const parsed = JSON.parse(f.toString());
12+
return parsed;
13+
}
14+
const prettyPrintRecord = (record: Record<string, string>) => {
15+
let str = "";
16+
for (const key in record) {
17+
const value = record[key];
18+
str += ` ${key}: ${value}\n`
19+
}
20+
return str;
21+
}
22+
23+
export const prettyPrint = (info: DebugInfo) => {
24+
return `System:
25+
OS: ${info.os.platform} ${info.os.release}
26+
Runtime:
27+
${info.runtime.name}: v${info.runtime.version}
28+
${Object.keys(info.packages).length !== 0 ? `Dependencies:
29+
${prettyPrintRecord(info.packages)}` : ""}`
30+
}
31+
export const fetchDebugInfo = async (): Promise<DebugInfo> => {
32+
const parsed = await getPackageJSON();
33+
const packages: Record<string, string> = parsed.dependencies ?? {};
34+
return {
35+
runtime: {
36+
name: "Node",
37+
version: "22.10.4"
38+
},
39+
os: {
40+
platform: os.platform(),
41+
release: os.release()
42+
},
43+
packages
44+
}
45+
}

packages/full-solid/src/start/index.ts

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { it } from "vitest";
2+
import { fetchDebugInfo, prettyPrint } from "../src/debug";
3+
4+
it("Runs", async () => {
5+
console.log(prettyPrint(await fetchDebugInfo()))
6+
})

0 commit comments

Comments
 (0)