Skip to content

feat(blocks): Gutenberg custom block scaffolder (v2.0.0) - #107

Merged
PAMulligan merged 1 commit into
mainfrom
feat/gutenberg-block-scaffolding
Jun 7, 2026
Merged

PAMulligan merged 1 commit into
mainfrom
feat/gutenberg-block-scaffolding

Conversation

@PAMulligan

Copy link
Copy Markdown
Collaborator

Summary

Ships the v2.0.0 "Gutenberg custom block scaffolding" milestone: a generator that turns a block name + namespace + attribute spec into a complete, immediately activatable custom block plugin — with no build step required.

scripts/scaffold-block.sh emits a self-contained plugin under plugins/<name>/. The generated index.js uses the WordPress runtime globals and index.asset.php declares the package dependencies, mirroring the existing featured-event reference block.

Acceptance criteria

  • Slash command /scaffold-block (or pnpm run scaffold:block) accepts: block name, namespace, supported attributes
  • Generates block.json, edit + save JS, optional dynamic render callback (--dynamic → render.php + "render" field)
  • Generates a PHPUnit test stub (+ tests/bootstrap.php, phpunit.xml.dist)
  • Documented under docs/blocks/
  • Smoke test: scaffold a block, build, activate, render on a test page (scripts/smoke-block.sh)

Inputs

Input Flag Notes
Block name positional kebab-case; becomes plugin dir + block slug
Namespace --namespace block.json name = <namespace>/<block-name>
Attributes --attributes "name:type[:default]" types: string, number, boolean, array, object
Render mode --dynamic / --static dynamic adds render.php

Plus --title/--description/--category/--icon/--keywords/--text-domain/--php-namespace/--version/--dest/--force/--dry-run.

Outputs

plugins/<block-name>/
├── <block-name>.php              # plugin header + register_block_type()
├── blocks/<block-name>/
│   ├── block.json                # metadata, attributes, supports
│   ├── index.js                  # edit() + save() — no build step
│   ├── index.asset.php           # script dependencies + version
│   ├── editor.css / style.css
│   └── render.php                # dynamic only
├── tests/<Class>Test.php + bootstrap.php
├── phpunit.xml.dist
└── README.md

Verification (actually run)

  • Full WP E2E smoke test: 8/8 passed against the live Docker stack — block registered (flavian/smoke-callout) and rendered on a real page with the correct wrapper class + attribute value, then cleaned up.
  • PHPUnit: dynamic stub 3 tests/10 assertions ✓; static stub 2 tests/7 assertions ✓ (render template executes via bootstrap stubs).
  • bats: 13/13 passed (run on Linux; local Windows bats has an unrelated CRLF/load quirk that doesn't affect CI).
  • php -l, node --check, and JSON validation clean.

Also included

  • /scaffold-block slash command + pnpm run scaffold:block / pnpm run smoke:block
  • .github/workflows/block-validation.yml — bats job + PHP lint/PHPUnit job (static & dynamic)
  • CLAUDE.md quick-reference entry

Test plan

# Structural tests
./tests/libs/bats-core/bin/bats tests/unit/scaffold-block.bats

# Full E2E
docker compose up -d wordpress db
pnpm run smoke:block

🤖 Generated with Claude Code

Ship the v2.0.0 "Gutenberg custom block scaffolding" milestone.

scripts/scaffold-block.sh generates a self-contained, immediately
activatable block plugin under plugins/<name>/ with no build step
(WordPress runtime globals + an index.asset.php that declares the
package dependencies, mirroring the featured-event reference block).

Inputs: block name, --namespace (block.json name <ns>/<name>), and
--attributes "name:type[:default]" (string|number|boolean|array|object),
wired into block.json, editor controls, save markup and render. --dynamic
adds a server-side render.php callback.

Outputs: block.json, index.js (edit + save), index.asset.php, editor.css,
style.css, render.php (dynamic only), a PHPUnit test stub + bootstrap,
phpunit.xml.dist and a README.

Also adds:
- /scaffold-block slash command and pnpm run scaffold:block
- scripts/smoke-block.sh (pnpm run smoke:block): scaffold -> activate ->
  assert registration -> render on a throwaway page against the Docker stack
- docs/blocks/README.md
- tests/unit/scaffold-block.bats (13 cases) + .github/workflows/block-validation.yml
  (bats job + PHP lint/PHPUnit job for both static and dynamic output)

Verified: full WP E2E smoke test 8/8; generated PHPUnit stubs green
(dynamic 3/10, static 2/7); php -l, node --check and JSON validation clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@PAMulligan
PAMulligan merged commit 56cf28d into main Jun 7, 2026
24 checks passed
@PAMulligan
PAMulligan deleted the feat/gutenberg-block-scaffolding branch June 7, 2026 06:06
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.

1 participant