diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json new file mode 100644 index 0000000..4a1df39 --- /dev/null +++ b/.claude-plugin/marketplace.json @@ -0,0 +1,15 @@ +{ + "name": "create-wp-plugin-cli", + "description": "Claude Code plugin for scaffolding modern WordPress and WooCommerce plugins with create-wp-plugin-cli.", + "owner": { + "name": "Akshat Saxena", + "url": "https://github.com/akshat009" + }, + "plugins": [ + { + "name": "create-wp-plugin", + "source": "./plugins/create-wp-plugin", + "description": "Scaffold a PHP 8.2, PSR-4 WordPress/WooCommerce plugin with tests, WPCS/VIP linting and CI using create-wp-plugin-cli." + } + ] +} diff --git a/README.md b/README.md index 74e939c..f7031a0 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,31 @@ prompt. Emoji output falls back to ASCII when `NO_COLOR` is set or the terminal can't render it. A failure partway through generation rolls back the directory it created. +### With Claude Code + +This repo is also a Claude Code plugin marketplace. Its `scaffold` skill turns a +plain-English request ("a WooCommerce plugin with a settings page and a Store API +extension") into the right modules, runs the generator non-interactively, then +installs dependencies and runs lint and tests. + +```bash +claude plugin marketplace add akshat009/create-wp-plugin-cli +claude plugin install create-wp-plugin@create-wp-plugin-cli +``` + +Then, in a Claude Code session: + +``` +/create-wp-plugin:scaffold WooCommerce plugin with a settings page and WP-CLI commands +``` + +Claude also picks the skill up on its own when you ask for a new WordPress plugin. +To install only the skill, for Claude Code or another agent that reads `SKILL.md`: + +```bash +npx skills add akshat009/create-wp-plugin-cli +``` + ### Flags `--help`, `--version`, `--yes`, `--name`, `--slug`, `--namespace`, `--prefix`, diff --git a/plugins/create-wp-plugin/.claude-plugin/plugin.json b/plugins/create-wp-plugin/.claude-plugin/plugin.json new file mode 100644 index 0000000..b7caed1 --- /dev/null +++ b/plugins/create-wp-plugin/.claude-plugin/plugin.json @@ -0,0 +1,13 @@ +{ + "name": "create-wp-plugin", + "description": "Scaffold a PHP 8.2, PSR-4 WordPress/WooCommerce plugin with tests, WPCS/VIP linting and CI using create-wp-plugin-cli.", + "version": "1.0.0", + "author": { + "name": "Akshat Saxena", + "url": "https://github.com/akshat009" + }, + "homepage": "https://github.com/akshat009/create-wp-plugin-cli", + "repository": "https://github.com/akshat009/create-wp-plugin-cli", + "license": "GPL-2.0-or-later", + "keywords": ["wordpress", "woocommerce", "plugin", "scaffold", "wpcs", "phpunit"] +} diff --git a/plugins/create-wp-plugin/skills/scaffold/SKILL.md b/plugins/create-wp-plugin/skills/scaffold/SKILL.md new file mode 100644 index 0000000..d591f21 --- /dev/null +++ b/plugins/create-wp-plugin/skills/scaffold/SKILL.md @@ -0,0 +1,109 @@ +--- +name: scaffold +description: Scaffold a new WordPress or WooCommerce plugin with create-wp-plugin-cli. Use when the user asks to create, start or scaffold a new WordPress plugin, or to build on a plugin generated by it. +argument-hint: [plugin idea or name] +--- + +# Scaffold a plugin with create-wp-plugin-cli + +[create-wp-plugin-cli](https://github.com/akshat009/create-wp-plugin-cli) generates a PHP 8.2, PSR-4 WordPress plugin with a singleton `Plugin` bootloader, opt-in modules, PHPCS (WPCS and/or VIP), a PHPUnit + Brain Monkey unit suite, and GitHub Actions CI. It is a **boilerplate**: wiring plus tests. The developer writes the business logic. + +Request: $ARGUMENTS + +## 0. Check the live CLI first + +Run `npx -y create-wp-plugin-cli@latest --help` before anything else. If its flags or module list differ from this skill, **the --help output wins**. When the user asks what a module or flag does, run the CLI or read its README; don't answer from memory. This skill was written against v3.1.1. Requires Node 20+, PHP 8.2+ and Composer. + +## 1. Work out the inputs + +Settle these from the request. Ask only for what you can't sensibly infer, in one short message: + +- **Name** (required), e.g. "Flash Sale Stock Guard for WooCommerce". +- **Slug**: defaults to the slugified name. Lowercase letters, numbers, single hyphens. +- **Prefix**: pass one explicitly; the auto-suggestion can be awkward ("Test Plugin for WooCommerce" becomes `tpww`). Rules: 4–15 characters, starts with a lowercase letter, only `a-z 0-9 _`, no hyphens, not `wp`, `wordpress` or `php`. It's used for constants (`PREFIX_VERSION`), the `_cache_keys` filter and `wp ` CLI commands. +- **Namespace**: StudlyCase. Defaults from the name minus filler words. +- **Description**: one line for the plugin header and readme.txt. +- **Author**: use `--author`, `--author-uri` and `--email` only with values the user gives. You may suggest `git config user.name` as the author name, but confirm it. +- **Lint target**: `wp-org` (default: WordPress-Extra + WordPress-Docs) for WordPress.org plugins; `vip` for WordPress VIP projects; `both` if it must pass both. +- **React admin app**: `--react` only if the admin UI is a React app; otherwise `--no-react`. +- **Output dir**: must not exist, or must be empty; the CLI refuses otherwise. Default `./`. + +## 2. Map features to modules + +| Feature asked for | Module | +|---|---| +| Settings page | `admin_settings` | +| Shortcode | `shortcode` | +| REST endpoint | `rest_api` | +| admin-ajax handler | `ajax_handler` | +| Custom post type / taxonomy | `cpt_taxonomy` | +| Scheduled job | `cron` | +| Object cache / transients | `caching` | +| Own database table | `custom_table` | +| Elementor widget | `elementor_widget` | +| Gutenberg block | `block:dynamic` (render.php) and/or `block:static` (save()); `block` = both | +| Front-end interactivity without React/jQuery | `interactivity` | +| WP-CLI commands | `cli` | +| VS Code snippets/settings | `editor_config` | +| Real-WordPress integration tests (wp-env) | `integration_tests` | +| WooCommerce payment gateway | `woo:gateway` | +| Shipping method | `woo:shipping` | +| Custom WooCommerce email | `woo:email` | +| Custom order status | `woo:order-status` | +| Custom product type | `woo:product-type` | +| Cart/Checkout blocks integration | `woo:blocks` | +| Background jobs via Action Scheduler | `woo:action-scheduler` | +| Store API extension | `woo:store-api` | +| My Account endpoint/tab | `woo:my-account` | +| Every WooCommerce component | `woo:all` | + +All modules combine freely. Pick the smallest set that covers the request; don't add modules "just in case". Unless the user already listed the modules, show them the planned command in one line before running it. + +## 3. Run it non-interactively + +Claude Code has no TTY, so always pass `--yes`; without it the CLI exits with an error. + +```bash +npx -y create-wp-plugin-cli@latest --yes \ + --name "Plugin Name" --slug plugin-slug --prefix pfxname --namespace PluginName \ + --description "One line description." \ + --modules "admin_settings,rest_api,woo:store-api" \ + --lint-target wp-org --no-react \ + --out ./plugin-slug +``` + +If validation fails, fix the value it names and rerun. A failed run rolls back the directory it created. + +## 4. Install and verify + +```bash +cd +composer install # allow-plugins for the PHPCS installer is preconfigured +composer lint +composer test # Brain Monkey unit suite, no WordPress install needed +``` + +If there's a JS pipeline (`--react`, `block`, `interactivity`, `woo:gateway` or `woo:blocks`): `npm install && npm run build`, then `npm run lint:js`, `npm run lint:style` and `npm run test:js`. Playwright (`npm run test:e2e`) needs a running WordPress site, so skip it unless one is up. With `integration_tests`: `npx @wordpress/env start`, then `composer test:integration`, only if Docker is available. + +Report anything that fails. Don't hide it with `phpcs:ignore`; the generated code is meant to pass clean. Only run `git init` and commit if the user asks. + +## 5. Summarise, then stop + +Tell the user the command you ran, the classes created under `src/`, what passed (lint, tests, build) and where to start writing logic. Don't write the plugin's business logic unless they ask. + +## Building on the scaffold + +When asked to add features, follow the generated architecture: + +- A feature is a plain class with an `init_hooks()` method, wired by adding one `( new Feature\Class() )->init_hooks();` line to `Plugin::boot()`. No base classes, auto-discovery or service containers. +- WooCommerce code lives under `src/Woo/` and is wired inside the existing `class_exists( 'WooCommerce' )` guard in `boot()`. +- Shared collaborators come from the static `Services` locator and are passed in by constructor injection. +- Anything that caches registers its keys on the `_cache_keys` filter; the CLI command and the uninstaller read it. +- Extra blocks: `npx @wordpress/create-block --no-plugin --target-dir assets/src/blocks/` (add `--variant dynamic` for a render.php block), then `npm run build`. `Block_Registrar` picks them up with no PHP changes. +- React only in wp-admin; the Interactivity API on the front end. +- PHP 8.2 style: constructor property promotion, `readonly`, first-class callables. +- Keep `composer lint` and `composer test` green after each change, and add a unit test for new logic. + +## Releasing + +`package.json`'s `files` field decides what ships; there's no `.distignore`. If there's a JS pipeline, run `npm install && npm run build` first, then `npm run plugin-zip` (it runs `composer prepare-dist` itself) to get `.zip`. Before a WordPress.org release, bump the version in the plugin header, the `PREFIX_VERSION` constant and readme.txt's Stable tag, and update "Tested up to". The scaffold seeds a recent value as a starting point, not as a claim that it was tested.