Skip to content

Commit

Permalink
feat: added plop
Browse files Browse the repository at this point in the history
  • Loading branch information
niebag committed Apr 17, 2024
1 parent b0ff228 commit 016cb2c
Show file tree
Hide file tree
Showing 6 changed files with 15,032 additions and 18,983 deletions.
13 changes: 13 additions & 0 deletions .plop-templates/component/index.stories.tsx.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Meta, StoryObj } from '@storybook/react';

import { {{pascalCase name}} } from '.';

const meta = {
title: '{{pascalCase type}}/{{pascalCase subType}}/{{pascalCase name}}',
component: {{pascalCase name}}
} satisfies Meta<typeof {{pascalCase name}}>;
export default meta;

type Story = StoryObj<typeof meta>;

export const Default = {} satisfies Story;
15 changes: 15 additions & 0 deletions .plop-templates/component/index.tsx.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react';

import { cn } from '~/lib/utils';

type Props = {
className?: string;
};

export function {{pascalCase name}}({ className, ...props }: Props) {
return (
<div data-testid='{{snakeCase name}}' className={cn('', className)}>
Hello, world!
</div>
);
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"start": "next start",
"storybook": "storybook dev -p 6006",
"storybook:build": "SKIP_ENV_VALIDATION=1 storybook build",
"storybook:test": "test-storybook --browsers chromium firefox webkit"
"storybook:test": "test-storybook --browsers chromium firefox webkit",
"plop": "plop"
},
"jest-junit": {
"ancestorSeparator": "",
Expand Down Expand Up @@ -71,6 +72,7 @@
"jest": "~29.7",
"jest-junit": "^16.0.0",
"lint-staged": "~15.2",
"plop": "^4.0.1",
"postcss": "~8.4",
"prettier": "~3.2",
"prettier-plugin-organize-imports": "~3.2",
Expand Down
50 changes: 50 additions & 0 deletions plopfile.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @param {import('plop').NodePlopAPI} plop - Plop provides the API methods for plop actions
*/
export default function (
plop
) {
plop.setGenerator('component', {
description: 'Create a new component according to the Atomic Design methodology',
prompts: [
{
type: 'input',
name: 'name',
message: 'What is your component name?'
},
{
type: 'list',
name: 'type',
message: 'What is your component type? ',
choices: ['atoms', 'molecules', 'organisms']
},
{
type: 'input',
name: 'subType',
message: `What is your component sub-type? (e.g. 'typography' for atoms, 'cards' for molecules or 'sections' for organisms)`,
},
{
type: 'confirm',
name: 'confirmation',
message: (answers) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
const pascalCaseName = answers.name.replace(/(^\w|-\w|\s\w|_\w)/g, (/** @type {string} */ s) => s.toUpperCase()).replace(/[-_\s]+/g, '');

return `Are you sure you want to create '~/components/${answers.type}/${answers.subType}/${pascalCaseName}'?`;
},
}
],
actions: [
{
type: 'add',
path: 'src/components/{{type}}/{{subType}}/{{pascalCase name}}/index.stories.tsx',
templateFile: '.plop-templates/component/index.stories.tsx.hbs'
},
{
type: 'add',
path: 'src/components/{{type}}/{{subType}}/{{pascalCase name}}/index.tsx',
templateFile: '.plop-templates/component/index.tsx.hbs'
},
]
});
}
Loading

0 comments on commit 016cb2c

Please sign in to comment.