-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: begin adding command for pretty printing useful debug info
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
}) |