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

Feature: Rapid UI component scaffolding #89

Draft
wants to merge 10 commits into
base: trunk
Choose a base branch
from

Conversation

willhowat
Copy link
Contributor

@willhowat willhowat commented Mar 3, 2022

Description of the Change

Added a micro-generator framework plop to rapidly scaffold UI components within the theme in an effort to:

  • Shave off the time this takes, whether from scratch or copy/paste/re-factor
  • Avoid incremental deviations from intended patterns and copy/paste errors
  • Provide a source of truth for intended patterns in the context of the longer term project lifecycle
  • Support the wider adoption of style guide component examples

One aspect I'm trying to address here by keeping this within the theme is the ability to start with common patterns, with the freedom to adapt them based on per-project needs.

From the theme root npm run new
Follow the guided menu to generate component files in a consistent manner:

  • component partial
  • styleguide example(s) of the partial
  • component CSS
  • component JS

All files are optional so can be as granular as required.
Including generated files needs to be done manually in the respective index files and/or styleguide template.
This was done to avoid accidental bloat.

Plop uses handlebars template files, these can be altered in [theme]/plop-templates.
Config files lives at [theme]/plopfile.js.

Closes #88

CC: @brentvr @joesnellpdx @rdimascio @ian-pvd

Alternate Designs

Alternatives were investigated to Plop, but this seems the simplest to configure and adopt across experience levels.
One strong contender was Hygen however, Plop does provide a super useful menu to select a generator allowing for a single npm script and contextual menu, whereas Hygen relies on directly running individual generators.

The templates follow some opinions in their patterns.
These have had real world testing in recent projects and have proven beneficial. They can be easily reconfigured through the plop templates if required.

Possible Drawbacks

The use of handlebars templates may not be ideal should this be extended to include rapid block scaffolding. To this end the npm script new has been added rather than anything more plop specific to allow a more natural swap of tooling if required.

Faker has been included as a composer dependency to support component style guide examples through stubbing of data. This package is stable, but no longer in active development. An alternative would be nice, but I was unable to source anything appropriate. The project has been taken up as FakerJS, but this is FE and Node focussed and does not provide the PHP integration we would need.

Verification Process

  • ran npm run new for various configurations of UI component
  • verified all files output as expected
  • verified all files can be included and components render as expected
  • verified NPM builds complete as expected

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Added

  • plop.js as theme npm dependency
  • ./plopfile.js for configuration of component generation
  • ./plop-templates/ containing component generation templates
  • fzaninotto/faker as composer dependency for styleguide example data
  • example-ui-component (partial, style guide partial examples, CSS, JS)
  • commented includes for example-ui-component files (style guide partial examples, CSS, JS)

Updated

  • styleguide.css with styling for sub-headers
  • Readme

@willhowat willhowat self-assigned this Mar 3, 2022
@willhowat willhowat mentioned this pull request Mar 3, 2022
1 task
themes/10up-theme/package.json Outdated Show resolved Hide resolved
@nicholasio
Copy link
Member

nicholasio commented Mar 5, 2022

I like this, but I'm not sure if the scaffold itself is the best to place to put the templates and all of the logic behind template generation.

I feel like 10up-toolkit would be a better place to put this in by exposing a new command: 10up-toolkit scaffold fe:component, which could be expanded in the future to include things like blocks etc... There's some previous work that never got merged: 10up/10up-toolkit#29

Copy link

@ian-pvd ian-pvd left a comment

Choose a reason for hiding this comment

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

This looks great. Tested the script and its outputting components like I'd expect.
I'm looking forward to testing this with my own custom component templates.

themes/10up-theme/plopfile.js Show resolved Hide resolved
@willhowat willhowat marked this pull request as ready for review March 10, 2022 13:06
@joesnellpdx
Copy link
Contributor

I like this, but I'm not sure if the scaffold itself is the best to place to put the templates and all of the logic behind template generation.

I feel like 10up-toolkit would be a better place to put this in by exposing a new command: 10up-toolkit scaffold fe:component, which could be expanded in the future to include things like blocks etc... There's some previous work that never got merged: 10up/10up-toolkit#29

@willhowat What are your thoughts per @nicholasio 's suggestion moving to 10up-toolkit?

@willhowat
Copy link
Contributor Author

I like this, but I'm not sure if the scaffold itself is the best to place to put the templates and all of the logic behind template generation.
I feel like 10up-toolkit would be a better place to put this in by exposing a new command: 10up-toolkit scaffold fe:component, which could be expanded in the future to include things like blocks etc... There's some previous work that never got merged: 10up/10up-toolkit#29

@willhowat What are your thoughts per @nicholasio 's suggestion moving to 10up-toolkit?

@joesnellpdx @nicholasio I've been thinking about this a lot and I can see value in that approach as well.
This tools is intended to provide rapid scaffolding of elements within the context of wp-scaffold.
The structure of files generated is by nature aligned with the structure of wp-scaffold and other aspects such as the styleguide, which live within wp-scaffold.
If this were to move to 10up-toolkit I think we would have to carefully consider how we allow configuration in a standalone world to ensure there isn't an assumed dependency.

My preference at this time would be to move forward in wp-scaffold.
In that way provide an immediate benefit and open this up for feedback.
We can then if suitable take those learnings and look at how to build something that could be within 10up-toolkit or other.

@nicholasio
Copy link
Member

I like this, but I'm not sure if the scaffold itself is the best to place to put the templates and all of the logic behind template generation.
I feel like 10up-toolkit would be a better place to put this in by exposing a new command: 10up-toolkit scaffold fe:component, which could be expanded in the future to include things like blocks etc... There's some previous work that never got merged: 10up/10up-toolkit#29

@willhowat What are your thoughts per @nicholasio 's suggestion moving to 10up-toolkit?

@joesnellpdx @nicholasio I've been thinking about this a lot and I can see value in that approach as well. This tools is intended to provide rapid scaffolding of elements within the context of wp-scaffold. The structure of files generated is by nature aligned with the structure of wp-scaffold and other aspects such as the styleguide, which live within wp-scaffold. If this were to move to 10up-toolkit I think we would have to carefully consider how we allow configuration in a standalone world to ensure there isn't an assumed dependency.

My preference at this time would be to move forward in wp-scaffold. In that way provide an immediate benefit and open this up for feedback. We can then if suitable take those learnings and look at how to build something that could be within 10up-toolkit or other.

I think we could have a default opinionated template focused in wp-scaffold while letting projects specify their own template at the project level, at that point toolkit would be a abstraction around plop. npx 10up-toolkit scaffold template-name

@willhowat
Copy link
Contributor Author

I like this, but I'm not sure if the scaffold itself is the best to place to put the templates and all of the logic behind template generation.
I feel like 10up-toolkit would be a better place to put this in by exposing a new command: 10up-toolkit scaffold fe:component, which could be expanded in the future to include things like blocks etc... There's some previous work that never got merged: 10up/10up-toolkit#29

@willhowat What are your thoughts per @nicholasio 's suggestion moving to 10up-toolkit?

@joesnellpdx @nicholasio I've been thinking about this a lot and I can see value in that approach as well. This tools is intended to provide rapid scaffolding of elements within the context of wp-scaffold. The structure of files generated is by nature aligned with the structure of wp-scaffold and other aspects such as the styleguide, which live within wp-scaffold. If this were to move to 10up-toolkit I think we would have to carefully consider how we allow configuration in a standalone world to ensure there isn't an assumed dependency.
My preference at this time would be to move forward in wp-scaffold. In that way provide an immediate benefit and open this up for feedback. We can then if suitable take those learnings and look at how to build something that could be within 10up-toolkit or other.

I think we could have a default opinionated template focused in wp-scaffold while letting projects specify their own template at the project level, at that point toolkit would be a abstraction around plop. npx 10up-toolkit scaffold template-name

I do think there's a lot of value in adding this into toolkit.

@nicholasio I'd be happy to see how I can help in that respect however, if you are able to provide some guidance around how best to manage the integration that would be really appreciated.

@joesnellpdx for now would it be acceptable to add this in to scaffold as is? On the basis we can update the 'new' script to wire into toolkit once it lands there

@willhowat willhowat requested review from joesnellpdx and removed request for rdimascio September 14, 2022 14:42
@joesnellpdx
Copy link
Contributor

@fabiankaegy adding you to the conversation.

@willhowat has done some great work here, and I know there is something in the works from Core as well - so the two of you should connect.

@joesnellpdx joesnellpdx requested a review from ian-pvd September 22, 2022 22:17
@darylldoyle
Copy link
Collaborator

I love this idea, but I'd also love to explore if there's a more generic way to handle it so that we can generate things outside of FE components and the theme.

For example, I've also wondered if we could do something like this to generate code for the mu-plugin, or to spin up a new block. I'd love to see something similar to how Laravel Artisan handles it:

php artisan make:controller PostsController

I've had thoughts of something similar for the scaffold:

$ php 10up make:cpt Event --mu-plugin=10up-plugin 
$ php 10up make:block MyCustomBlock --theme=10up-theme
$ php 10up make:component Carousel --theme=10up-theme --type=atom

We'd then have a directory of stub files within the project that each project could customise to their needs. Whilst it looks like PlopJS could do this, my concern would be that plopfile.js would get unwieldy. I would like to explore if this could be a better experience for engineers if this happened via PHP, where we could define a distinct class per feature.

Again, I'm not at all against this, and I think it's a great idea; I just want to ensure that we're not diving into adopting a system that will stop us from expanding it to other parts of the scaffold in the future.

@fabiankaegy fabiankaegy marked this pull request as draft February 20, 2024 08:12
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.

Rapid UI component scaffolding
6 participants