Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
feat: add `docs` command

Allows for opening the Solid docs in the browser
  • Loading branch information
Tommypop2 committed Jan 23, 2025
1 parent cd20d01 commit eb21580
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 38 deletions.
1 change: 1 addition & 0 deletions packages/full-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
13 changes: 11 additions & 2 deletions packages/full-solid/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
38 changes: 21 additions & 17 deletions packages/full-solid/src/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
}
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`
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<DebugInfo> => {
const parsed = await getPackageJSON();
const packages: Record<string, string> = parsed.dependencies ?? {};
Expand All @@ -39,15 +42,16 @@ export const fetchDebugInfo = async (): Promise<DebugInfo> => {
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));
},
})
});
34 changes: 17 additions & 17 deletions packages/full-solid/src/debug/runtime-detector.ts
Original file line number Diff line number Diff line change
@@ -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");
};
3 changes: 3 additions & 0 deletions packages/full-solid/src/start/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineCommand } from "citty";

export const startCommands = defineCommand({});
4 changes: 2 additions & 2 deletions packages/full-solid/tests/debuginfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { it } from "vitest";
import { fetchDebugInfo, prettyPrint } from "../src/debug";

it("Runs", async () => {
console.log(prettyPrint(await fetchDebugInfo()))
})
console.log(prettyPrint(await fetchDebugInfo()));
});
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eb21580

Please sign in to comment.