10up / wp-scaffold

10up WordPress project scaffold.
MIT License
194 stars 46 forks source link

Add scaffolding command for quickly generating blocks #195

Closed fabiankaegy closed 11 months ago

fabiankaegy commented 1 year ago

Description of the Change

This PR adds a new scaffold:block command to the 10up starter theme which allows anyone to easily scaffold out a new block. It is based on the @wordpress/create-block package with custom block templates that are bundled in the scaffold itself.

Closes #

How to test the Change

To test this you can run npm run scaffold:block -w themes/10up-theme in the wp-content folder. This will run through a few prompts and generate the block for you.

Changelog Entry

Added - Block Scaffolding command to easily build out new blocks

Credits

Props @fabiankaegy

Checklist:

fabiankaegy commented 1 year ago

@nicholasio I'd love to get your take on this. Do you think this should live in the scaffold here or in toolkit.

My reason for including it in the scaffold is that I want project teams to be able to modify the starter block templates to their linings. Which would be more difficult in toolkit since it doesn't get exposed.

However if it were in toolkit it would be easier to ship updates to the scaffolding tool compared to here where essentially it gets stale once the project is scaffolded unless someone manually updates it.

ivanlopez commented 1 year ago

@fabiankaegy If we were to add it to the toolkit, we could also create a command to publish the templates into the project to be customized, like Laravel does here: https://laravel.com/docs/10.x/artisan#stub-customization.

fabiankaegy commented 1 year ago

@ivanlopez 👀 That does sound like an interesting solution that would cover both cases!

nicholasio commented 1 year ago

@fabiankaegy Since the actual logic to create scaffold the block is handled by @wordpress/create-block I don't think there's much value in moving this to toolkit as it would essentially wrap @wordpress/create-block. One thing that toolkit could do it let projects override the default template, so if nothing is provided at the project level it would use the one shipped with toolkit.

With that said, it's probably fine to ship this directly in the scaffold for now.

fabiankaegy commented 1 year ago

Okay, in that case, let's keep it simple for now.

We can ship this as is and iterate on it if we find we want more flexibility in the future