diff --git a/src/components/WranglerNamespace.astro b/src/components/WranglerNamespace.astro new file mode 100644 index 000000000000000..7f58d1143a5914a --- /dev/null +++ b/src/components/WranglerNamespace.astro @@ -0,0 +1,46 @@ +--- +import { z } from "astro:schema"; +import { experimental_getWranglerCommands } from "wrangler"; +import WranglerCommand from "./WranglerCommand.astro"; + +const props = z.object({ + namespace: z.string(), +}); + +const { namespace } = props.parse(Astro.props); + +const defs = experimental_getWranglerCommands(); + +const node = defs.subtree.get(namespace); + +if (!node || node.subtree.size === 0) { + throw new Error(`[WranglerNamespace] Namespace "${namespace}" not found`); +} + +const definitions: NonNullable<(typeof node)["definition"]>[] = []; + +function flattenSubtree(node: (typeof defs)["subtree"]) { + for (const value of node.values()) { + if (value.definition?.type === "command") { + definitions.push(value.definition); + } else { + flattenSubtree(value.subtree); + } + } +} + +flattenSubtree(node.subtree); +--- + +{ + definitions.map((definition) => { + if (definition.type !== "command") { + throw new Error( + `[WranglerNamespace] Expected "command" but got "${definition.type}" for "${definition.command}"`, + ); + } + return ( + + ); + }) +} diff --git a/src/components/index.ts b/src/components/index.ts index c340a2147fbca9d..901724378c654e5 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -58,6 +58,7 @@ export { default as TunnelCalculator } from "./TunnelCalculator.astro"; export { default as Type } from "./Type.astro"; export { default as TypeScriptExample } from "./TypeScriptExample.astro"; export { default as WranglerCommand } from "./WranglerCommand.astro"; +export { default as WranglerNamespace } from "./WranglerNamespace.astro"; export { default as WranglerConfig } from "./WranglerConfig.astro"; export { default as WARPReleases } from "./WARPReleases.astro"; export { default as Width } from "./Width.astro"; diff --git a/src/content/docs/style-guide/components/wrangler-namespace.mdx b/src/content/docs/style-guide/components/wrangler-namespace.mdx new file mode 100644 index 000000000000000..f1cefa1125f11f7 --- /dev/null +++ b/src/content/docs/style-guide/components/wrangler-namespace.mdx @@ -0,0 +1,23 @@ +--- +title: WranglerNamespace +styleGuide: + component: WranglerNamespace +--- + +The `WranglerNamespace` component documents the available commands for a given namespace. + +This is generated using the Wrangler version in the [`cloudflare-docs` repository](https://github.com/cloudflare/cloudflare-docs/blob/production/package.json). + +## Import + +```mdx +import { WranglerNamespace } from "~/components"; +``` + +## Usage + +```mdx live +import { WranglerNamespace } from "~/components"; + + +```