fix: show help text and refresh help formatting (#3399)

- Show help text when `-h` or `--help` is passed to `@fresh/init`
- Print current version for `@fresh/init` during `--help`
<img width="367" height="95" alt="image"
src="https://github.com/user-attachments/assets/e3318fae-ce8a-4cbb-bb0a-78f338f1b3a2"
/>
- Refresh `--help` text with colors similar to `deno -h`; + "Fresh
branding" style for the `@fresh/init` text
- Print `@fresh/core` version when `@fresh/init` runs
<img width="471" height="88" alt="image"
src="https://github.com/user-attachments/assets/1a0bd619-315d-4abb-889c-ec6eb3a9b45f"
/>

I think showing versions is helpful for verifying/debugging what Fresh
version will be installed during init before all files are generated.

## Comparisons

### `@fresh/init` + empty project name

#### Before

<img width="1104" height="615" alt="image"
src="https://github.com/user-attachments/assets/b1534bb5-eecc-4692-9977-df3903868416"
/>

#### After

<img width="1169" height="695" alt="image"
src="https://github.com/user-attachments/assets/6a743d79-bb59-463a-aadd-fbf734149258"
/>

### `@fresh/init --help`

#### Before

<img width="1007" height="150" alt="image"
src="https://github.com/user-attachments/assets/0ad42078-420c-4dc6-9561-4a338cc09741"
/>

#### After

<img width="1272" height="579" alt="image"
src="https://github.com/user-attachments/assets/3dfe6712-8604-4429-a418-5e6538117303"
/>
This commit is contained in:
Christian Svensson
2025-09-12 10:04:54 +02:00
committed by GitHub
parent a473cc9d9f
commit 6466c975d5
2 changed files with 55 additions and 15 deletions
+21
View File
@@ -3,6 +3,7 @@ import {
CONFIRM_TAILWIND_MESSAGE,
CONFIRM_VITE_MESSAGE,
CONFIRM_VSCODE_MESSAGE,
HELP_TEXT,
initProject,
} from "./init.ts";
import * as path from "@std/path";
@@ -27,6 +28,14 @@ function stubConfirm(steps: Record<string, boolean> = {}) {
);
}
function stubLogs() {
return stub(
console,
"log",
() => undefined,
);
}
function withTmpDir(): Promise<{ dir: string } & AsyncDisposable> {
const dir = path.join(import.meta.dirname!, "..", "..", "..", "..");
return withTmpDirBase({ dir, prefix: "tmp_" });
@@ -75,6 +84,18 @@ async function readProjectFile(dir: string, pathname: string): Promise<string> {
return content;
}
Deno.test("init - show help", async () => {
using logs = stubLogs();
await initProject("", [], { help: true });
const args = logs.calls.flatMap((c) => c.args);
const out = args.join("\n");
await initProject("", [], { h: true });
expect(out).toBe(HELP_TEXT);
expect(args).toEqual(logs.calls.flatMap((c) => c.args).slice(args.length));
});
Deno.test("init - new project", async () => {
await using tmp = await withTmpDir();
using _promptStub = stubPrompt("fresh-init");