Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add plop for generating component files from a template #366

Merged
merged 6 commits into from
Mar 26, 2021

Conversation

dierat
Copy link
Contributor

@dierat dierat commented Mar 24, 2021

Summary

This PR adds a command line feature that allows developers to easily generate template files for creating a new component. This change is heavily based on #309

Video

plop1.mp4

Test Plan:

In your terminal, in the edu-design-system directory, run plop (or npx plop),
verify you're asked for a component name,
type in two words separated by a space,
and verify you're told the script succeeded with 6 actions.

Navigate to storybook,
verify a component with the name you input (now with pascal case) is present in the list,
and verify there are 2 stories, one with purple text on the left and one with purple text on the right.

Open your text editor,
verify a directory in src now exists with your component name (in pascal case),
check out the files inside,
verify they match the PlopTest files (with your component name used instead of "PlopTest"),
open packages/components/src/index.ts,
and verify your component is now listed as an export.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size-limit report

Path Size
components 4.68 KB (+15.6% 🔺)
styles 3.81 KB (0%)

@codecov
Copy link

codecov bot commented Mar 25, 2021

Codecov Report

Merging #366 (d1454ef) into main (4ae48f7) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #366   +/-   ##
=======================================
  Coverage   85.39%   85.39%           
=======================================
  Files           8        8           
  Lines          89       89           
  Branches       37       37           
=======================================
  Hits           76       76           
  Partials       13       13           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ae48f7...d1454ef. Read the comment docs.

@dierat dierat force-pushed the diedra/plop-2 branch 3 times, most recently from 168ac37 to fdc89e8 Compare March 25, 2021 15:58
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size-limit report

Path Size
components 4.68 KB (+15.7% 🔺)
styles 3.81 KB (0%)

Comment on lines +19 to +23
type: "add",
path:
"packages/components/src/{{pascalCase name}}/{{pascalCase name}}.module.css",
templateFile: "plop-templates/Component/Component.module.css.hbs",
},
Copy link
Contributor Author

@dierat dierat Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is the only change I made in this file from the original PR #309

@@ -0,0 +1,24 @@
import * as React from "react";
import { Story } from "@storybook/react/types-6-0";
import TestComponent from "./TestComponent";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: This import is not automatically alphabetized by the generator, so, in this case, I had to manually move the component import down one line to be below Story.

Copy link
Contributor

@anniehu4 anniehu4 Mar 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dang that's mildly annoying. we do have a lint sort-imports rule setup but I'm not sure it can auto-fix 🤔 def can be a future followup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I make a ticket?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that'd be great, thanks! we can put it in the DS: Strategy/Infra epic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package-lock.json Outdated Show resolved Hide resolved
@dierat dierat marked this pull request as ready for review March 25, 2021 16:35
@dierat dierat requested review from dcwither, anniehu4 and ahuth March 25, 2021 16:35
Copy link
Contributor

@anniehu4 anniehu4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! 🙏 If you'd like, I think we could go ahead and use camelCase names for the styles / remove classNames.bind?

package.json Outdated Show resolved Hide resolved
packages/components/src/index.ts Outdated Show resolved Hide resolved
import classNames from "classnames/bind";
import styles from "./{{pascalCase name}}.module.css";

const cx = classNames.bind(styles);
Copy link
Contributor

@anniehu4 anniehu4 Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

things be changing every day 😅 It seems we're all on board with camelcase classnames and replacing classNames.bind with clsx (and you wouldn't need to worry about paramCase)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😞 sorry for flip flopping - I think we're set now with camelCase + clsx (#362 option 3)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Np! It's expected while these things are still being settled.

plop-templates/Component/Component.tsx.hbs Outdated Show resolved Hide resolved
plop-templates/Component/Component.tsx.hbs Outdated Show resolved Hide resolved
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size-limit report

Path Size
components 4.94 KB (+14.24% 🔺)
styles 3.81 KB (0%)

Copy link
Contributor

@anniehu4 anniehu4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woohooo

@@ -0,0 +1,24 @@
import * as React from "react";
import { Story } from "@storybook/react/types-6-0";
import TestComponent from "./TestComponent";
Copy link
Contributor

@anniehu4 anniehu4 Mar 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dang that's mildly annoying. we do have a lint sort-imports rule setup but I'm not sure it can auto-fix 🤔 def can be a future followup

@dierat
Copy link
Contributor Author

dierat commented Mar 26, 2021

Broken test is the snapshot, which I'm going to remove anyway.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size-limit report

Path Size
components 4.24 KB (0%)
styles 3.81 KB (0%)

@dierat dierat changed the title chore: add plop for generating component files from a template [WIP] chore: add plop for generating component files from a template Mar 26, 2021
@dierat dierat merged commit 9dd52d8 into main Mar 26, 2021
@dierat dierat deleted the diedra/plop-2 branch March 26, 2021 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants