Skip to content

Commit d103102

Browse files
authored
[Docs Site] Add WranglerCommands component (#24684)
* [Docs Site] Add WranglerCommands component * rename
1 parent 47be238 commit d103102

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
import { z } from "astro:schema";
3+
import { experimental_getWranglerCommands } from "wrangler";
4+
import WranglerCommand from "./WranglerCommand.astro";
5+
6+
const props = z.object({
7+
namespace: z.string(),
8+
});
9+
10+
const { namespace } = props.parse(Astro.props);
11+
12+
const defs = experimental_getWranglerCommands();
13+
14+
const node = defs.subtree.get(namespace);
15+
16+
if (!node || node.subtree.size === 0) {
17+
throw new Error(`[WranglerNamespace] Namespace "${namespace}" not found`);
18+
}
19+
20+
const definitions: NonNullable<(typeof node)["definition"]>[] = [];
21+
22+
function flattenSubtree(node: (typeof defs)["subtree"]) {
23+
for (const value of node.values()) {
24+
if (value.definition?.type === "command") {
25+
definitions.push(value.definition);
26+
} else {
27+
flattenSubtree(value.subtree);
28+
}
29+
}
30+
}
31+
32+
flattenSubtree(node.subtree);
33+
---
34+
35+
{
36+
definitions.map((definition) => {
37+
if (definition.type !== "command") {
38+
throw new Error(
39+
`[WranglerNamespace] Expected "command" but got "${definition.type}" for "${definition.command}"`,
40+
);
41+
}
42+
return (
43+
<WranglerCommand command={definition.command.replace("wrangler ", "")} />
44+
);
45+
})
46+
}

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export { default as TunnelCalculator } from "./TunnelCalculator.astro";
5858
export { default as Type } from "./Type.astro";
5959
export { default as TypeScriptExample } from "./TypeScriptExample.astro";
6060
export { default as WranglerCommand } from "./WranglerCommand.astro";
61+
export { default as WranglerNamespace } from "./WranglerNamespace.astro";
6162
export { default as WranglerConfig } from "./WranglerConfig.astro";
6263
export { default as WARPReleases } from "./WARPReleases.astro";
6364
export { default as Width } from "./Width.astro";
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: WranglerNamespace
3+
styleGuide:
4+
component: WranglerNamespace
5+
---
6+
7+
The `WranglerNamespace` component documents the available commands for a given namespace.
8+
9+
This is generated using the Wrangler version in the [`cloudflare-docs` repository](https://github.com/cloudflare/cloudflare-docs/blob/production/package.json).
10+
11+
## Import
12+
13+
```mdx
14+
import { WranglerNamespace } from "~/components";
15+
```
16+
17+
## Usage
18+
19+
```mdx live
20+
import { WranglerNamespace } from "~/components";
21+
22+
<WranglerNamespace namespace="d1" />
23+
```

0 commit comments

Comments
 (0)