-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plop): ✨ update component generators and add example component&page
Changes include: - generators/component/Component.stories.tsx.hbs: Modify storybook template for components - generators/component/Component.tsx.hbs: Modify component template - generators/component/index.js: Modify component generator - generators/component/index.ts.hbs: Modify typescript template for component - generators/page/index.js: Add new page generator - generators/page/layout.tsx.hbs: Add new layout template for pages - generators/page/page.tsx.hbs: Add new page template - plopfile.js: Modify plopfile to include new generators - src/app/example-page/layout.tsx: Add new example page layout - src/app/example-page/page.tsx: Add new example page - src/components/example-component/example-component.stories.tsx: Add new story for example component - src/components/example-component/example-component.tsx: Add new example component - src/components/example-component/index.ts: Add new index file for example component This commit updates the plop generators, adds a new page generator, and include examples for reference.
- Loading branch information
1 parent
02d07b7
commit ca64097
Showing
13 changed files
with
119 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import { Meta, Story } from '@storybook/react'; | ||
import { Meta, StoryObj } from '@storybook/react' | ||
|
||
import { {{ properCase name }} } from './{{ properCase name }}'; | ||
import { {{ properCase name }} } from './{{ kebabCaseName }}' | ||
|
||
const meta: Meta = { | ||
title: 'Components/{{ properCase name }}', | ||
component: {{ properCase name }}, | ||
parameters: { | ||
controls: { expanded: true }, | ||
}, | ||
}; | ||
controls: { expanded: true } | ||
} | ||
} | ||
|
||
export default meta; | ||
export default meta | ||
|
||
const Template: Story = (props) => <{{ properCase name }} {...props}>{{ properCase name}}</{{ properCase name }}>; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = {}; | ||
export const Default: StoryObj = { | ||
render: (props) => <{{ properCase name }} {...props}>{{ properCase name}}</{{ properCase name }}> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './{{ properCase name }}'; | ||
export * from './{{ kebabCaseName }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* | ||
* @type {import('plop').PlopGenerator} | ||
*/ | ||
module.exports = { | ||
description: 'Page Generator', | ||
prompts: [ | ||
{ | ||
type: 'input', | ||
name: 'name', | ||
message: 'Page name?' | ||
} | ||
], | ||
actions: (data) => { | ||
const changeCase = require('change-case') | ||
data.kebabCaseName = changeCase.paramCase(data.name) | ||
data.pascalCaseName = changeCase.pascalCase(data.name) | ||
|
||
const pageGeneratePath = 'src/app/{{kebabCaseName}}' | ||
return [ | ||
{ | ||
type: 'add', | ||
path: pageGeneratePath + '/page.tsx', | ||
templateFile: 'generators/page/page.tsx.hbs' | ||
}, | ||
{ | ||
type: 'add', | ||
path: pageGeneratePath + '/layout.tsx', | ||
templateFile: 'generators/page/layout.tsx.hbs' | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function {{ properCase name }}Layout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return <main>{children}</main> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Link from 'next/link' | ||
|
||
export default function {{properCase name}}() { | ||
return ( | ||
<> | ||
<h1>{{properCase name}} Page</h1> | ||
<p className='text-center text-2xl leading-tight'> | ||
<Link href='/'>← Go Back</Link> | ||
</p> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
const componentGenerator = require('./generators/component/index') | ||
const pageGenerator = require('./generators/page/index') | ||
|
||
/** | ||
* | ||
* @param {import('plop').NodePlopAPI} plop | ||
*/ | ||
module.exports = function (plop) { | ||
plop.setGenerator('component', componentGenerator) | ||
plop.setGenerator('page', pageGenerator) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function ExamplePageLayout({ | ||
children | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return <main>{children}</main> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Link from 'next/link' | ||
|
||
export default function ExamplePage() { | ||
return ( | ||
<> | ||
<h1>ExamplePage Page</h1> | ||
<p className='text-center text-2xl leading-tight'> | ||
<Link href='/'>← Go Back</Link> | ||
</p> | ||
</> | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
src/components/example-component/example-component.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Meta, StoryObj } from '@storybook/react' | ||
|
||
import { ExampleComponent } from './example-component' | ||
|
||
const meta: Meta = { | ||
title: 'Components/ExampleComponent', | ||
component: ExampleComponent, | ||
parameters: { | ||
controls: { expanded: true } | ||
} | ||
} | ||
|
||
export default meta | ||
|
||
export const Default: StoryObj = { | ||
render: () => <ExampleComponent /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// your imports here | ||
|
||
export const ExampleComponent = () => { | ||
return <div>ExampleComponent</div> | ||
} | ||
|
||
export default ExampleComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './example-component' |