From 54b3666491f6857e7991360ca268a4870fcdeeff Mon Sep 17 00:00:00 2001 From: weareoutman Date: Fri, 2 Aug 2024 14:44:16 +0800 Subject: [PATCH] fix(): refine brick template --- packages/yo/src/plopfile.js | 22 +++++++++++-------- packages/yo/src/templates/brick/index.tsx.hbs | 14 +++++++----- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/packages/yo/src/plopfile.js b/packages/yo/src/plopfile.js index efd89cc2f2..703a30402d 100644 --- a/packages/yo/src/plopfile.js +++ b/packages/yo/src/plopfile.js @@ -67,12 +67,16 @@ export default function ( "libDevDependencies", getObjectPartialInPackageJson(libDevDependencies) ); - plop.setHelper("getTagName", (brickType, pkgName, brickName, lastNameOnly) => - brickType === "common" - ? `eo-${brickName}` - : lastNameOnly - ? brickName - : `${pkgName}.${brickName}` + plop.setHelper( + "getTagName", + (brickType, pkgName, brickName, lastNameOnly, stripEo) => + brickType === "common" + ? stripEo + ? brickName + : `eo-${brickName}` + : lastNameOnly + ? brickName + : `${pkgName}.${brickName}` ); plop.setHelper("getDirectory", (type, pkgName, libName) => type === "bricks" @@ -83,15 +87,15 @@ export default function ( ); plop.setPartial( "tagName", - "{{getTagName brickType pkgName brickName false}}" + "{{getTagName brickType pkgName brickName false false}}" ); plop.setPartial( "lastTagName", - "{{getTagName brickType pkgName brickName true}}" + "{{getTagName brickType pkgName brickName true false}}" ); plop.setPartial( "className", - "{{pascalCase (getTagName brickType pkgName brickName true)}}" + "{{pascalCase (getTagName brickType pkgName brickName true true)}}" ); // create your generators here diff --git a/packages/yo/src/templates/brick/index.tsx.hbs b/packages/yo/src/templates/brick/index.tsx.hbs index 408dd1af43..d9db25d363 100644 --- a/packages/yo/src/templates/brick/index.tsx.hbs +++ b/packages/yo/src/templates/brick/index.tsx.hbs @@ -10,10 +10,14 @@ import styleText from "./styles.shadow.css"; {{#if useI18n}} initializeReactI18n(NS, locales); -{{/if}} +{{/if}} const { defineElement, property } = createDecorators(); +export interface {{>className}}Props { + // Define props here. +} + /** * 构件 `{{>tagName}}` */ @@ -21,7 +25,7 @@ export @defineElement("{{>tagName}}", { styleTexts: [styleText], }) -class {{>className}} extends ReactNextElement { +class {{>className}} extends ReactNextElement implements {{>className}}Props { render() { return ( <{{>className}}Component /> @@ -29,11 +33,11 @@ class {{>className}} extends ReactNextElement { } } -export interface {{>className}}Props { - // Define props here. +export interface {{>className}}ComponentProps extends {{>className}}Props { + // Define event handlers here. } -export function {{>className}}Component(props: {{>className}}Props) { +export function {{>className}}Component(props: {{>className}}ComponentProps) { {{#if useI18n}} const { t } = useTranslation(NS); const hello = t(K.HELLO);