From 07d454d32caa6e84b272f3e7fc8bd4bb5f9a669b Mon Sep 17 00:00:00 2001 From: Solomon Hawk Date: Thu, 21 Nov 2024 01:51:39 -0500 Subject: [PATCH] Update component generators --- turbo/generators/config.ts | 63 ++++++++++++++++--- .../ui/component/component.stories.tsx.hbs | 21 +++++++ .../templates/ui/component/component.tsx.hbs | 8 +++ .../component/core/component.stories.tsx.hbs | 21 +++++++ .../ui/component/core/component.tsx.hbs | 17 +++++ .../templates/ui/component/core/index.ts.hbs | 1 + .../templates/ui/component/index.hbs | 15 ----- .../templates/ui/component/index.ts.hbs | 1 + 8 files changed, 125 insertions(+), 22 deletions(-) create mode 100644 turbo/generators/templates/ui/component/component.stories.tsx.hbs create mode 100644 turbo/generators/templates/ui/component/component.tsx.hbs create mode 100644 turbo/generators/templates/ui/component/core/component.stories.tsx.hbs create mode 100644 turbo/generators/templates/ui/component/core/component.tsx.hbs create mode 100644 turbo/generators/templates/ui/component/core/index.ts.hbs delete mode 100644 turbo/generators/templates/ui/component/index.hbs create mode 100644 turbo/generators/templates/ui/component/index.ts.hbs diff --git a/turbo/generators/config.ts b/turbo/generators/config.ts index c114bf1..8d352d9 100644 --- a/turbo/generators/config.ts +++ b/turbo/generators/config.ts @@ -5,6 +5,13 @@ export default function generator(plop: PlopTypes.NodePlopAPI): void { plop.setGenerator("ui/component", { description: "A new UI component", prompts: [ + { + type: "confirm", + name: "core", + message: "Is this a core component?", + default: false, + }, + { type: "input", name: "component_name", @@ -22,12 +29,54 @@ export default function generator(plop: PlopTypes.NodePlopAPI): void { }, }, ], - actions: [ - { - type: "add", - path: "{{ turbo.paths.root }}/packages/ui/src/components/{{ dashCase component_name }}.tsx", - templateFile: "templates/ui/component/index.hbs", - }, - ], + + actions: (asdf) => { + const isCoreComponent = asdf?.core ?? false; + + if (isCoreComponent) { + return [ + // components/core//index.ts + { + type: "add", + path: "{{ turbo.paths.root }}/packages/ui/src/components/core/{{ dashCase component_name }}/index.ts", + templateFile: "templates/ui/component/core/index.ts.hbs", + }, + // components/core//.tsx + { + type: "add", + path: "{{ turbo.paths.root }}/packages/ui/src/components/core/{{ dashCase component_name }}/{{ dashCase component_name }}.tsx", + templateFile: "templates/ui/component/core/component.tsx.hbs", + }, + // components/core//.stories.tsx + { + type: "add", + path: "{{ turbo.paths.root }}/packages/ui/src/components/core/{{ dashCase component_name }}/{{ dashCase component_name }}.stories.tsx", + templateFile: + "templates/ui/component/core/component.stories.tsx.hbs", + }, + ]; + } + + return [ + // components//index.ts + { + type: "add", + path: "{{ turbo.paths.root }}/packages/ui/src/components/{{ dashCase component_name }}/index.ts", + templateFile: "templates/ui/component/index.ts.hbs", + }, + // components//.tsx + { + type: "add", + path: "{{ turbo.paths.root }}/packages/ui/src/components/{{ dashCase component_name }}/{{ dashCase component_name }}.tsx", + templateFile: "templates/ui/component/component.tsx.hbs", + }, + // components//.stories.tsx + { + type: "add", + path: "{{ turbo.paths.root }}/packages/ui/src/components/{{ dashCase component_name }}/{{ dashCase component_name }}.stories.tsx", + templateFile: "templates/ui/component/component.stories.tsx.hbs", + }, + ]; + }, }); } diff --git a/turbo/generators/templates/ui/component/component.stories.tsx.hbs b/turbo/generators/templates/ui/component/component.stories.tsx.hbs new file mode 100644 index 0000000..a83fbc6 --- /dev/null +++ b/turbo/generators/templates/ui/component/component.stories.tsx.hbs @@ -0,0 +1,21 @@ +import type { Meta, StoryObj } from "@storybook/react"; + +import { {{ component_name }} } from "./{{ dashCase component_name }}"; + +const meta = { + title: "UI/{{ component_name }}", + component: {{ component_name }}, + tags: ["autodocs"], + parameters: { + layout: "centered", + }, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const Default: Story = { + args: { + children: null, + }, +}; diff --git a/turbo/generators/templates/ui/component/component.tsx.hbs b/turbo/generators/templates/ui/component/component.tsx.hbs new file mode 100644 index 0000000..e5a3d0d --- /dev/null +++ b/turbo/generators/templates/ui/component/component.tsx.hbs @@ -0,0 +1,8 @@ +export type {{ component_name }}Props = { + className?: string; + children: React.ReactNode; +}; + +export function {{ component_name }}({ className, children }: {{ component_name }}Props) { + return
{children}
+} diff --git a/turbo/generators/templates/ui/component/core/component.stories.tsx.hbs b/turbo/generators/templates/ui/component/core/component.stories.tsx.hbs new file mode 100644 index 0000000..be74e1a --- /dev/null +++ b/turbo/generators/templates/ui/component/core/component.stories.tsx.hbs @@ -0,0 +1,21 @@ +import type { Meta, StoryObj } from "@storybook/react"; + +import { {{ component_name }} } from "./{{ dashCase component_name }}"; + +const meta = { + title: "UI/Core/{{ component_name }}", + component: {{ component_name }}, + tags: ["autodocs"], + parameters: { + layout: "centered", + }, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const Default: Story = { + args: { + children: null, + }, +}; diff --git a/turbo/generators/templates/ui/component/core/component.tsx.hbs b/turbo/generators/templates/ui/component/core/component.tsx.hbs new file mode 100644 index 0000000..159c282 --- /dev/null +++ b/turbo/generators/templates/ui/component/core/component.tsx.hbs @@ -0,0 +1,17 @@ +import React, { forwardRef } from "react"; + +import { cn } from "#lib/utils.js"; + +export interface {{ component_name }}Props extends React.HTMLAttributes {} + +export const {{ component_name }} = forwardRef( + ({ className, children, ...props }) => { + return ( +
+ {children} +
+ ); + }, +); + +{{ component_name }}.displayName = "{{ component_name }}"; diff --git a/turbo/generators/templates/ui/component/core/index.ts.hbs b/turbo/generators/templates/ui/component/core/index.ts.hbs new file mode 100644 index 0000000..d87f3c7 --- /dev/null +++ b/turbo/generators/templates/ui/component/core/index.ts.hbs @@ -0,0 +1 @@ +export * from "./{{ dashCase component_name }}" diff --git a/turbo/generators/templates/ui/component/index.hbs b/turbo/generators/templates/ui/component/index.hbs deleted file mode 100644 index 8299a64..0000000 --- a/turbo/generators/templates/ui/component/index.hbs +++ /dev/null @@ -1,15 +0,0 @@ -type Props = { - className?: string; - children: React.ReactNode; -}; - -export function {{ component_name }}({ - className, - children -}: Props) { - return ( -
- {children} -
- ); -} diff --git a/turbo/generators/templates/ui/component/index.ts.hbs b/turbo/generators/templates/ui/component/index.ts.hbs new file mode 100644 index 0000000..d87f3c7 --- /dev/null +++ b/turbo/generators/templates/ui/component/index.ts.hbs @@ -0,0 +1 @@ +export * from "./{{ dashCase component_name }}"