From aceebdbe08885582f201e2d52164e62919529094 Mon Sep 17 00:00:00 2001 From: tosaken1116 Date: Fri, 3 Nov 2023 04:04:11 +0900 Subject: [PATCH 1/3] fix: change model component template --- _templates/generator/model/component.ejs.t | 25 ++++++++++++---------- _templates/generator/model/empty.ejs.t | 4 +++- _templates/generator/model/error.ejs.t | 4 +++- _templates/generator/model/hooks.ejs.t | 4 +++- _templates/generator/model/index.ejs.t | 10 ++++++++- _templates/generator/model/loading.ejs.t | 4 +++- src/libs/ErrorBoundary.tsx | 0 src/libs/ErrorBoundary/index.tsx | 1 + 8 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 src/libs/ErrorBoundary.tsx create mode 100644 src/libs/ErrorBoundary/index.tsx diff --git a/_templates/generator/model/component.ejs.t b/_templates/generator/model/component.ejs.t index 8f9f973..da98a7e 100644 --- a/_templates/generator/model/component.ejs.t +++ b/_templates/generator/model/component.ejs.t @@ -1,19 +1,22 @@ --- to: "<%= `src/components/model/${name}/index.tsx` %>" --- -<% if (have_hooks) { %>import { use<%= name %> } from './hooks';<% } %> -<% gen_files.forEach(file=>{%>import { <%= name %><%= file %>Presentation } from './presentations/<%= file.toLowerCase() %>'; +import type { FC } from 'react'; +import { Suspense } from 'react'; + +import { <%= name %>Presentation } from './presentations'; +<% gen_files.filter((file)=>file!="Empty").forEach(file=>{%>import { <%= name %><%= file %>Presentation } from './presentations/<%= file.toLowerCase() %>'; <%})%> +import { ErrorBoundary } from '@/libs/ErrorBoundary'; + <% if (have_props) { %>type Props = {};<% } %> -export const <%= name %>:React.FC<% if (have_props) { %><% } %> = (<% if (have_props) { %>{}<% } %>) => { - <% if (have_hooks) { %>const {} = use<%= name %>();<% } %> - return ( - <> - this is <%= name %> component - <% gen_files.forEach(file=>{%><<%= name %><%= file %>Presentation /> - <%})%> - ); -}; +export const <%= name %>: FC<% if (have_props) { %><% } %> = (<% if (have_props) { %>{}<% } %>) => ( + <% if (gen_files.includes("Error")) { %>ErrorPresentation />}><% } %> + <% if (gen_files.includes("Loading")) { %>LoadingPresentation />}><% } %> + <<%= name %>Presentation /> + <% if (gen_files.includes("Loading")) { %><% } %> + <% if (gen_files.includes("Error")) { %><% } %> +); diff --git a/_templates/generator/model/empty.ejs.t b/_templates/generator/model/empty.ejs.t index be9d10a..fb7fe65 100644 --- a/_templates/generator/model/empty.ejs.t +++ b/_templates/generator/model/empty.ejs.t @@ -1,6 +1,8 @@ --- to: "<%= gen_files.includes('Empty') ? `src/components/model/${name}/presentations/empty.tsx` : null %>" --- -export const <%= name %>EmptyPresentation:React.FC = () => { +import type { FC } from 'react'; + +export const <%= name %>EmptyPresentation:FC = () => { return <>this is <%= name %> empty presentation; }; diff --git a/_templates/generator/model/error.ejs.t b/_templates/generator/model/error.ejs.t index d72a672..6d320ac 100644 --- a/_templates/generator/model/error.ejs.t +++ b/_templates/generator/model/error.ejs.t @@ -1,6 +1,8 @@ --- to: "<%= gen_files.includes('Error') ? `src/components/model/${name}/presentations/error.tsx` : null %>" --- -export const <%= name %>ErrorPresentation:React.FC = () => { +import type { FC } from 'react'; + +export const <%= name %>ErrorPresentation:FC = () => { return <>this is <%= name %> error presentation; }; diff --git a/_templates/generator/model/hooks.ejs.t b/_templates/generator/model/hooks.ejs.t index 55db476..c7d845a 100644 --- a/_templates/generator/model/hooks.ejs.t +++ b/_templates/generator/model/hooks.ejs.t @@ -7,9 +7,11 @@ import { useState } from 'react'; type IUse<%= name %> = { state: string; setState: Dispatch>; + <% if (have_hooks) { %>isEmpty: boolean;<%} %> } export const use<%= name %> = ():IUse<%= name %> => { const [state, setState] = useState(""); - return {state,setState} + <% if(gen_files.includes("Empty")){ %>const isEmpty = true;<% }%> + return {state,setState<% if(gen_files.includes("Empty")){ %>, isEmpty <% }%>} }; diff --git a/_templates/generator/model/index.ejs.t b/_templates/generator/model/index.ejs.t index 3975666..eac46d3 100644 --- a/_templates/generator/model/index.ejs.t +++ b/_templates/generator/model/index.ejs.t @@ -1,6 +1,14 @@ --- to: "<%= `src/components/model/${name}/presentations/index.tsx` %>" --- -export const <%= name %>Presentation:React.FC = () => { +import type { FC } from 'react'; + +<% if (have_hooks) { %>import { use<%= name %> } from '../hooks';<% } %> + +export const <%= name %>Presentation: FC = () => { + <% if (have_hooks) { %>const {<% if(gen_files.includes("Empty")){ %> isEmpty <% }%>} = use<%= name %>();<% } %> + <% if (have_hooks && gen_files.includes("Empty")) { %>if (isEmpty){ + return <<%= name %>Presentation />; + }<%} %> return
this is <%= name %> presentation
; }; diff --git a/_templates/generator/model/loading.ejs.t b/_templates/generator/model/loading.ejs.t index d14e2d8..39aaf46 100644 --- a/_templates/generator/model/loading.ejs.t +++ b/_templates/generator/model/loading.ejs.t @@ -1,6 +1,8 @@ --- to: "<%= gen_files.includes('Loading') ? `src/components/model/${name}/presentations/loading.tsx` : null %>" --- -export const <%= name %>LoadingPresentation:React.FC = () => { +import type { FC } from 'react'; + +export const <%= name %>LoadingPresentation:FC = () => { return <>this is <%= name %> component; }; diff --git a/src/libs/ErrorBoundary.tsx b/src/libs/ErrorBoundary.tsx new file mode 100644 index 0000000..e69de29 diff --git a/src/libs/ErrorBoundary/index.tsx b/src/libs/ErrorBoundary/index.tsx new file mode 100644 index 0000000..94bafbf --- /dev/null +++ b/src/libs/ErrorBoundary/index.tsx @@ -0,0 +1 @@ +export { ErrorBoundary } from 'react-error-boundary'; From e9cacdf96669200679da99698a25a114ee21d5a4 Mon Sep 17 00:00:00 2001 From: tosaken1116 Date: Fri, 3 Nov 2023 04:08:23 +0900 Subject: [PATCH 2/3] fix: change test template --- _templates/generator/model/test.ejs.t | 2 +- _templates/generator/ui/index.test.t | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 _templates/generator/ui/index.test.t diff --git a/_templates/generator/model/test.ejs.t b/_templates/generator/model/test.ejs.t index 33bf989..00f9979 100644 --- a/_templates/generator/model/test.ejs.t +++ b/_templates/generator/model/test.ejs.t @@ -6,7 +6,7 @@ import { render, screen } from "@testing-library/react"; import "@testing-library/jest-dom"; import { <%= name %> } from "."; -describe("model/<%= name %>のテスト", () => { +describe("model/<%= name %>", () => { it("title is exist", () => { render(<<%= name %> />); diff --git a/_templates/generator/ui/index.test.t b/_templates/generator/ui/index.test.t new file mode 100644 index 0000000..00826fc --- /dev/null +++ b/_templates/generator/ui/index.test.t @@ -0,0 +1,17 @@ +--- +to: src/components/ui/<%= name %>/index.test.tsx +--- +import { render, screen } from "@testing-library/react"; + +import "@testing-library/jest-dom"; +import { <%= name %> } from "."; + +describe("ui/<%= name %>", () => { + it("title is exist", () => { + render(<<%= name %> />); + + const title = screen.getByText(/this is <%= name %> component/); + + expect(title).toBeInTheDocument(); + }); +}); \ No newline at end of file From 0b87e728e20c91526b3bbaf8ddfd9fab354e664f Mon Sep 17 00:00:00 2001 From: tosaken1116 Date: Fri, 3 Nov 2023 04:09:14 +0900 Subject: [PATCH 3/3] fix: change import type --- _templates/generator/page/index.ejs.t | 4 +++- _templates/generator/page/page.ejs.t | 4 +++- _templates/generator/ui/index.ejs.t | 4 +++- src/libs/ErrorBoundary.tsx | 0 4 files changed, 9 insertions(+), 3 deletions(-) delete mode 100644 src/libs/ErrorBoundary.tsx diff --git a/_templates/generator/page/index.ejs.t b/_templates/generator/page/index.ejs.t index 2c1feff..0eda710 100644 --- a/_templates/generator/page/index.ejs.t +++ b/_templates/generator/page/index.ejs.t @@ -1,8 +1,10 @@ --- to: "<%= `src/components/page/${name}/index.tsx` %>" --- +import type { FC } from 'react'; + <% used_models.forEach(use_model=>{%>import { <%= use_model %> } from '@/components/model/<%= use_model %>'; <%})%> -export const Screen:React.FC = () => { +export const Screen:FC = () => { return <>this is page of <%= name %> ; }; diff --git a/_templates/generator/page/page.ejs.t b/_templates/generator/page/page.ejs.t index cfbaab1..4efca27 100644 --- a/_templates/generator/page/page.ejs.t +++ b/_templates/generator/page/page.ejs.t @@ -1,8 +1,10 @@ --- to: "<%= `src/app/${url}/page.tsx` %>" --- +import type { FC } from 'react'; + import { Screen } from '@/components/page/<%= name %>' -const <%= name %>:React.FC = () => ; +const <%= name %>:FC = () => ; export default <%= name %>; \ No newline at end of file diff --git a/_templates/generator/ui/index.ejs.t b/_templates/generator/ui/index.ejs.t index baffeb4..5023af5 100644 --- a/_templates/generator/ui/index.ejs.t +++ b/_templates/generator/ui/index.ejs.t @@ -1,8 +1,10 @@ --- to: "<%= `src/components/ui/${name}/index.tsx` %>" --- +import type { FC } from 'react'; + type Props = {}; -export const <%= name %>:React.FC = ({}) => { +export const <%= name %>:FC = ({}) => { return <>this is ui of <%= name %> ; }; diff --git a/src/libs/ErrorBoundary.tsx b/src/libs/ErrorBoundary.tsx deleted file mode 100644 index e69de29..0000000