Scaffolding a block

The command npm run scaffold is available to scaffold a new block. Once run it will ask several questions in order to setup a new block.

? What is the name of the block, as it would appear in the block selector?
? What is the slug of the block?
? What is a description of the block?
? Is this block built for Nova?
? What category does the block belong to?
? Use @wordpress/icons for the icon?
? Add optional keywords separated by a comma.
? Will this block use post meta?
? Will this block use InnerBlocks?
? Will this block has any editor styles?

Once completed the new block will scaffold. It will create a block folder in the blocks/global directory and a test in the tests/blocks directory.

Context Notes

  • Block Name. Capital case.
  • The block slug is automatically created from the block name unless otherwise defined. All lowercase, and will force hyphens vs spaced.
  • Description of the block to display in the InspectorControls sidebar.
  • The "Is this block built for Nova?", if true, will support the nova_render_callback method in the block's block.php file.
  • All PMC blocks should be scaffolded into the pmc category (a custom category).
  • The dashicon question supports all of the built-in Dashicons (opens in a new tab) by default. Additionally supports icons via the @wordpress/icons package.
  • "Add options keywords". Add keywords that are searchable using the slash command or the inserter search field.
  • "Will this block use post meta?" will add the meta.json file as well as the necessary hooks/helpers in the edit.js file.
  • The "Will this block use InnerBlocks?", if true, will add the necessary <InnerBlocks.Content /> callback to the block registration allowing for $content to be made available to the render_callback method(s).
  • Finally, if styles will be needed an edit.scss file will be added

Look at the block breakdown for additional context.

Adding New Features

👩‍💻
Call for contribution on these updates.

New features can be added or unused or redudnant features can be removed as needed. Some features that have been requested but not implemented are (but are not limited to):

  • Add additional feature defaults including InspectorControls or BlockControls to name a couple.
  • Add the ability to define the supports object values.