Skip to content

Commit 0cad0a7

Browse files
committed
feat(cli): allow overriding meta
1 parent 07d7caf commit 0cad0a7

File tree

8 files changed

+47
-21
lines changed

8 files changed

+47
-21
lines changed

automd.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { glob } from "node:fs/promises";
22
import * as md from "mdbox";
33
import { fileURLToPath } from "node:url";
4+
import pkg from "./package.json" with { type: "json" };
45

56
export default {
67
input: ["README.md", "docs/**/*.md"],
@@ -10,7 +11,12 @@ export default {
1011
process.env.NO_COLOR = "1";
1112
const { usage } = await import("./src/cli/usage.ts");
1213
delete process.env.NO_COLOR;
13-
const _usage = usage({ usage: { command: "srvx", docs: "", issues: "" } });
14+
const _usage = usage({
15+
meta: {
16+
name: "srvx",
17+
description: pkg.description,
18+
},
19+
});
1420
return {
1521
contents: md.codeBlock(_usage, "sh"),
1622
};

bin/srvx.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env node
22
import { main } from "../dist/cli.mjs";
3+
import pkg from "../package.json" with { type: "json" };
34

45
await main({
6+
meta: pkg,
57
usage: {
68
command: "srvx",
79
docs: "https://srvx.h3.dev",

docs/1.guide/1.index.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,20 @@ bun run server.mjs
8787

8888
<!-- automd:examples -->
8989

90-
| Example | Source | Try |
91-
| ---------------- | ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------- |
92-
| `aws-lambda` | [examples/aws-lambda](https://github.com/h3js/srvx/tree/main/examples/aws-lambda/) | `npx giget gh:h3js/srvx/examples/aws-lambda srvx-aws-lambda` |
93-
| `elysia` | [examples/elysia](https://github.com/h3js/srvx/tree/main/examples/elysia/) | `npx giget gh:h3js/srvx/examples/elysia srvx-elysia` |
94-
| `express` | [examples/express](https://github.com/h3js/srvx/tree/main/examples/express/) | `npx giget gh:h3js/srvx/examples/express srvx-express` |
95-
| `fastify` | [examples/fastify](https://github.com/h3js/srvx/tree/main/examples/fastify/) | `npx giget gh:h3js/srvx/examples/fastify srvx-fastify` |
96-
| `h3` | [examples/h3](https://github.com/h3js/srvx/tree/main/examples/h3/) | `npx giget gh:h3js/srvx/examples/h3 srvx-h3` |
97-
| `hello-world` | [examples/hello-world](https://github.com/h3js/srvx/tree/main/examples/hello-world/) | `npx giget gh:h3js/srvx/examples/hello-world srvx-hello-world` |
98-
| `hono` | [examples/hono](https://github.com/h3js/srvx/tree/main/examples/hono/) | `npx giget gh:h3js/srvx/examples/hono srvx-hono` |
99-
| `jsx` | [examples/jsx](https://github.com/h3js/srvx/tree/main/examples/jsx/) | `npx giget gh:h3js/srvx/examples/jsx srvx-jsx` |
100-
| `node-handler` | [examples/node-handler](https://github.com/h3js/srvx/tree/main/examples/node-handler/) | `npx giget gh:h3js/srvx/examples/node-handler srvx-node-handler` |
90+
| Example | Source | Try |
91+
| --- | --- | --- |
92+
| `aws-lambda` | [examples/aws-lambda](https://github.com/h3js/srvx/tree/main/examples/aws-lambda/) | `npx giget gh:h3js/srvx/examples/aws-lambda srvx-aws-lambda` |
93+
| `elysia` | [examples/elysia](https://github.com/h3js/srvx/tree/main/examples/elysia/) | `npx giget gh:h3js/srvx/examples/elysia srvx-elysia` |
94+
| `express` | [examples/express](https://github.com/h3js/srvx/tree/main/examples/express/) | `npx giget gh:h3js/srvx/examples/express srvx-express` |
95+
| `fastify` | [examples/fastify](https://github.com/h3js/srvx/tree/main/examples/fastify/) | `npx giget gh:h3js/srvx/examples/fastify srvx-fastify` |
96+
| `h3` | [examples/h3](https://github.com/h3js/srvx/tree/main/examples/h3/) | `npx giget gh:h3js/srvx/examples/h3 srvx-h3` |
97+
| `hello-world` | [examples/hello-world](https://github.com/h3js/srvx/tree/main/examples/hello-world/) | `npx giget gh:h3js/srvx/examples/hello-world srvx-hello-world` |
98+
| `hono` | [examples/hono](https://github.com/h3js/srvx/tree/main/examples/hono/) | `npx giget gh:h3js/srvx/examples/hono srvx-hono` |
99+
| `jsx` | [examples/jsx](https://github.com/h3js/srvx/tree/main/examples/jsx/) | `npx giget gh:h3js/srvx/examples/jsx srvx-jsx` |
100+
| `node-handler` | [examples/node-handler](https://github.com/h3js/srvx/tree/main/examples/node-handler/) | `npx giget gh:h3js/srvx/examples/node-handler srvx-node-handler` |
101101
| `service-worker` | [examples/service-worker](https://github.com/h3js/srvx/tree/main/examples/service-worker/) | `npx giget gh:h3js/srvx/examples/service-worker srvx-service-worker` |
102-
| `streaming` | [examples/streaming](https://github.com/h3js/srvx/tree/main/examples/streaming/) | `npx giget gh:h3js/srvx/examples/streaming srvx-streaming` |
103-
| `tracing` | [examples/tracing](https://github.com/h3js/srvx/tree/main/examples/tracing/) | `npx giget gh:h3js/srvx/examples/tracing srvx-tracing` |
104-
| `websocket` | [examples/websocket](https://github.com/h3js/srvx/tree/main/examples/websocket/) | `npx giget gh:h3js/srvx/examples/websocket srvx-websocket` |
102+
| `streaming` | [examples/streaming](https://github.com/h3js/srvx/tree/main/examples/streaming/) | `npx giget gh:h3js/srvx/examples/streaming srvx-streaming` |
103+
| `tracing` | [examples/tracing](https://github.com/h3js/srvx/tree/main/examples/tracing/) | `npx giget gh:h3js/srvx/examples/tracing srvx-tracing` |
104+
| `websocket` | [examples/websocket](https://github.com/h3js/srvx/tree/main/examples/websocket/) | `npx giget gh:h3js/srvx/examples/websocket srvx-websocket` |
105105

106106
<!-- /automd -->

docs/1.guide/9.cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bunx --bun srvx
3333
<!-- automd:cliUsage -->
3434

3535
```sh
36-
srvx - Universal Server CLI
36+
srvx - Universal Server.
3737

3838
SERVE MODE
3939

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "srvx",
33
"version": "0.11.0",
4-
"description": "Universal Server API based on web platform standards. Works seamlessly with Deno, Bun and Node.js.",
4+
"description": "Universal Server.",
55
"homepage": "https://srvx.h3.dev",
66
"license": "MIT",
77
"repository": "h3js/srvx",

src/cli/main.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { parseArgs as parseNodeArgs } from "node:util";
22
import { fileURLToPath } from "node:url";
33
import { fork } from "node:child_process";
44
import { existsSync, statSync } from "node:fs";
5-
import pkg from "../../package.json" with { type: "json" };
65
import * as c from "./_utils.ts";
76
import type { CLIOptions, MainOptions } from "./types.ts";
87
import { cliServe, NO_ENTRY_ERROR } from "./serve.ts";
@@ -15,7 +14,7 @@ export async function main(mainOpts: MainOptions): Promise<void> {
1514

1615
// Handle version flag
1716
if (cliOpts.version) {
18-
console.log(`srvx ${pkg.version}\n${runtime()}`);
17+
process.stdout.write(versions(mainOpts).join("\n") + "\n");
1918
process.exit(0);
2019
}
2120
// Handle help flag
@@ -26,7 +25,7 @@ export async function main(mainOpts: MainOptions): Promise<void> {
2625

2726
// Running in a child process
2827
if (process.send) {
29-
console.log(c.gray(`srvx ${pkg.version} - ${runtime()}`));
28+
console.log(c.gray(versions(mainOpts).join(" · ")));
3029
setupProcessErrorHandlers();
3130
await cliServe(cliOpts);
3231
return;
@@ -193,6 +192,15 @@ function setupProcessErrorHandlers() {
193192
});
194193
}
195194

195+
function versions(mainOpts: MainOptions): string[] {
196+
const versions: string[] = [];
197+
if (mainOpts.meta?.name) {
198+
versions.push(`${mainOpts.meta.name} ${mainOpts.meta.version || ""}`.trim());
199+
}
200+
versions.push(runtime());
201+
return versions;
202+
}
203+
196204
function runtime(): string {
197205
if (process.versions.bun) {
198206
return `bun ${process.versions.bun}`;

src/cli/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ declare global {
66

77
export type MainOptions = CLIOptions & {
88
args?: string[];
9+
meta?: {
10+
name?: string;
11+
version?: string;
12+
description?: string;
13+
};
914
usage?: {
1015
command?: string;
1116
docs?: string;

src/cli/usage.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import type { MainOptions } from "./types.ts";
33

44
export function usage(mainOpts: MainOptions): string {
55
const command = mainOpts.usage?.command || "srvx";
6+
7+
const name = mainOpts.meta?.name || command;
8+
const ver = mainOpts.meta?.version || "";
9+
const desc = mainOpts.meta?.description;
10+
611
return `
7-
${c.cyan(command)} - Universal Server CLI
12+
${c.cyan(name)}${c.gray(`${ver ? ` ${ver}` : ""} ${desc ? `- ${desc}` : ""}`)}
813
914
${c.bold("SERVE MODE")}
1015

0 commit comments

Comments
 (0)