Skip to content

Commit 0b0d6c4

Browse files
committed
Update copilot-instructions.md to reflect the monorepo structure and clarify build instructions for WordPress block development examples. Enhanced details on environment requirements, dependency management, and project architecture.
1 parent 2672213 commit 0b0d6c4

File tree

1 file changed

+144
-74
lines changed

1 file changed

+144
-74
lines changed

.github/workflows/copilot-instructions.md

Lines changed: 144 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22

33
## Repository Overview
44

5-
This is a WordPress plugin
5+
This is a monorepo containing WordPress block development examples for educational and reference purposes.
66

7-
- **Repository Type:** WordPress Plugin
8-
- **Primary Language:** PHP, JavaScript (React/JSX)
9-
- **Frameworks:** WordPress, WordPress Block Editor (Gutenberg), @wordpress/scripts
7+
- **Repository Type:** WordPress Block Development Examples Monorepo
8+
- **Purpose:** Educational examples demonstrating various WordPress block development patterns
9+
- **Primary Languages:** JavaScript (React/JSX), PHP
10+
- **Frameworks:** WordPress Block Editor (Gutenberg), @wordpress/scripts
11+
- **Package Manager:** pnpm (workspace-based monorepo)
1012
- **Target Runtime:** WordPress 6.8+, PHP 8.1+, Node.js 20+
1113

1214
## Critical Build Instructions
1315

1416
### Environment Requirements
1517

1618
- **Node.js:** greater than v20.19.5
17-
- **npm:** greater than v10.8.2
18-
- **PHP:** 8.1 or higher (plugin requires PHP 8.1+)
19+
- **pnpm:** 8.0 or higher (REQUIRED - this is a pnpm workspace)
20+
- **PHP:** 8.1 or higher (plugins require PHP 8.1+)
1921
- **Composer:** 2.8.12 or higher
22+
- **WordPress Environment:** wp-env (included in devDependencies)
2023

2124
### Dependency Versions
2225

@@ -30,14 +33,15 @@ This is a WordPress plugin
3033

3134
**ALWAYS install dependencies in this exact order before any build operations:**
3235

33-
1. **npm dependencies (REQUIRED FIRST):**
36+
1. **pnpm dependencies (REQUIRED FIRST):**
3437
```bash
35-
npm install
38+
pnpm install
3639
```
37-
- Takes approximately 60 seconds on first install
40+
- Installs all workspace dependencies including individual plugin examples
41+
- Takes approximately 30-60 seconds on first install
3842
- May show deprecation warnings (these are non-critical)
39-
- May show 2 moderate severity vulnerabilities (these are from dev dependencies and are non-critical)
40-
- Creates `node_modules/` directory (ignored by git)
43+
- Creates `node_modules/` directories at root and in each plugin (ignored by git)
44+
- Uses pnpm workspace configuration from `pnpm-workspace.yaml`
4145

4246
2. **Composer dependencies (for PHP linting only):**
4347
```bash
@@ -51,30 +55,33 @@ This is a WordPress plugin
5155

5256
### Build Process
5357

54-
**ALWAYS run build after making JavaScript/CSS changes:**
58+
**Build all plugin examples:**
59+
```bash
60+
pnpm run build
61+
```
62+
- Recursively builds all plugins in the workspace
63+
- Takes approximately 10-30 seconds depending on number of plugins
64+
- Creates `build/` directories in each plugin folder
65+
- Generates minified JavaScript, CSS, and asset dependency files
5566

67+
**Build a specific plugin:**
5668
```bash
57-
npm run build
69+
cd plugins/[plugin-name]
70+
pnpm run build
5871
```
59-
- Takes approximately 1-2 seconds
60-
- Uses webpack via @wordpress/scripts
61-
- Generates files in `build/` directory (ignored by git, but required for plugin to function)
62-
- Creates `build/blocks-manifest.php` (automatically generated, do NOT edit manually)
63-
- Creates minified JavaScript, CSS, and asset dependency files in `build/[your-block-name]/`
64-
- Build output includes RTL CSS variants automatically
65-
66-
**For development with hot reload:**
72+
73+
**For development with hot reload (all plugins):**
6774
```bash
68-
npm run start
75+
pnpm run start
6976
```
70-
- Watches for file changes and rebuilds automatically
77+
- Watches all plugins for file changes and rebuilds automatically
7178
- Generates unminified source maps for debugging
7279
- Use Ctrl+C to stop the watch process
7380

74-
**To clean and rebuild:**
81+
**To clean and rebuild all:**
7582
```bash
76-
rm -rf build/
77-
npm run build
83+
pnpm run admin:clear:build
84+
pnpm run build
7885
```
7986

8087
### Linting and Code Quality
@@ -118,35 +125,54 @@ npm run format
118125

119126
### Plugin Distribution
120127

121-
**To create a distributable ZIP file:**
128+
**To create distributable ZIP files for all plugins:**
122129
```bash
123-
npm run plugin-zip
130+
pnpm run plugin-zip
124131
```
125-
- Creates `[your-plugin-name].zip` in the repository root (ignored by git)
126-
- Includes only necessary files: `[your-plugin-file.php]`, `build/` directory contents
127-
- Excludes: `src/`, `node_modules/`, `vendor/`, development files
128-
- Takes approximately 1-2 seconds
132+
- Creates `.zip` files for all plugin examples
133+
- Each plugin gets its own distributable ZIP
134+
135+
**Deploy all plugins to zips folder:**
136+
```bash
137+
pnpm run deploy
138+
```
139+
- Builds all plugins
140+
- Creates ZIP files for each
141+
- Moves all ZIPs to `zips/` folder for distribution
129142

130143
## Project Architecture
131144

132145
### Directory Structure
133146

134147
```
135-
[your-plugin-name]/
136-
├── .editorconfig # Editor configuration (tabs, not spaces)
137-
├── .gitignore # Excludes build/, node_modules/, vendor/, *.zip
138-
├── composer.json # PHP dependencies (WordPress Coding Standards)
139-
├── package.json # npm dependencies and scripts
140-
├── [your-plugin-file.php] # Main plugin file - registers blocks
141-
└── src/
142-
└── [your-block-name]/ # Block source files
143-
├── block.json # Block metadata (schema, scripts, styles)
144-
├── index.js # Block registration entry point
145-
├── edit.js # Block editor component (React)
146-
├── save.js # Block save/render component (React)
147-
├── view.js # Front-end JavaScript
148-
├── editor.scss # Editor-only styles
149-
└── style.scss # Front-end and editor styles
148+
block-development-examples/ # Monorepo root
149+
├── .editorconfig # Editor configuration (tabs, not spaces)
150+
├── .gitignore # Excludes build/, node_modules/, vendor/, *.zip
151+
├── .wp-env.json # WordPress local environment config
152+
├── pnpm-workspace.yaml # pnpm workspace configuration
153+
├── package.json # Root package scripts and dev dependencies
154+
├── composer.json # PHP dependencies (WordPress Coding Standards)
155+
├── _app/ # Documentation site source
156+
├── _bin/ # Utility scripts for managing examples
157+
├── _data/ # Data files for documentation
158+
├── templates/ # Block templates for creating new examples
159+
│ └── block-examples/ # Template for new block examples
160+
└── plugins/ # Individual block example plugins
161+
├── basic-esnext-*/ # Example: Basic ESNext block
162+
├── block-dynamic-rendering-*/ # Example: Dynamic rendering
163+
├── block-supports-*/ # Example: Block supports
164+
└── [plugin-name]/ # Each plugin follows this structure:
165+
├── package.json # Plugin-specific dependencies
166+
├── [plugin-name].php # Main plugin file
167+
└── src/ # Block source files
168+
└── [block-name]/ # Block components
169+
├── block.json # Block metadata
170+
├── index.js # Block registration
171+
├── edit.js # Editor component
172+
├── save.js # Save component
173+
├── view.js # Frontend script
174+
├── editor.scss # Editor styles
175+
└── style.scss # Frontend styles
150176
```
151177

152178
### Build Output Structure
@@ -188,14 +214,18 @@ build/ # Generated by npm run build (DO NOT EDIT)
188214
- Defines saved HTML output
189215
- Uses `useBlockProps.save()` for proper block wrapper attributes
190216

191-
**`package.json` scripts:**
192-
- `build`: Production build with minification and manifest generation
193-
- `start`: Development build with watch mode
194-
- `format`: Auto-format all code with Prettier
195-
- `lint:js`: Lint JavaScript with ESLint
196-
- `lint:css`: Lint CSS/SCSS with stylelint
197-
- `plugin-zip`: Create distributable ZIP
198-
- `packages-update`: Update @wordpress/* packages
217+
**Root `package.json` scripts:**
218+
- `build`: Build all plugins in workspace
219+
- `start`: Start development mode for all plugins
220+
- `env:start`: Start WordPress local environment
221+
- `env:stop`: Stop WordPress environment
222+
- `test:e2e`: Run Playwright end-to-end tests
223+
- `create-example`: Create new block example from template
224+
- `table:update`: Update documentation tables
225+
- `deploy`: Build and package all plugins to zips/
226+
- `lint`: Run all linters
227+
- `plugin-zip`: Create distributable ZIPs for all plugins
228+
- `packages-update`: Update @wordpress/* packages in all plugins
199229

200230
## WordPress Coding Guidelines
201231

@@ -217,21 +247,41 @@ function my_function() {
217247

218248
**Before committing any code changes, ALWAYS run in this order:**
219249

220-
1. Format code: `npm run format`
221-
2. Lint JavaScript: `npm run lint:js`
222-
3. Lint CSS: `npm run lint:css`
223-
4. Build: `npm run build`
224-
5. Verify build output exists in `build/[your-block-name]/`
250+
1. Install dependencies: `pnpm install`
251+
2. Format code: `pnpm run format` (if available in specific plugin)
252+
3. Lint JavaScript: `pnpm run lint:js`
253+
4. Lint CSS: `pnpm run lint:css`
254+
5. Build all: `pnpm run build`
255+
6. Verify build outputs exist in `plugins/*/build/`
225256

226-
**For PHP changes only:**
257+
**For PHP changes:**
227258
1. Format and lint as above (if any JS/CSS was touched)
228-
2. Check PHP: `./vendor/bin/phpcs [your-plugin-file.php]` (warnings acceptable)
229-
3. Build: `npm run build`
259+
2. Check PHP: `composer run lint` or `./vendor/bin/phpcs`
260+
3. Build: `pnpm run build`
261+
262+
## WordPress Environment
263+
264+
**Start local WordPress environment:**
265+
```bash
266+
pnpm run env:start
267+
```
268+
- Runs WordPress locally using Docker via wp-env
269+
- Access at http://localhost:8888
270+
- Admin at http://localhost:8888/wp-admin (admin/password)
271+
- All plugins in `plugins/` are automatically mounted
272+
273+
**Creating new block examples:**
274+
```bash
275+
pnpm run create-example
276+
```
277+
- Uses the template in `templates/block-examples/`
278+
- Prompts for block details
279+
- Automatically sets up the new plugin structure
230280

231281
## Common Issues and Solutions
232282

233-
**Issue:** `npm run build` fails with "Cannot find module"
234-
- **Solution:** Run `npm install` first - dependencies not installed
283+
**Issue:** `pnpm run build` fails with "Cannot find module"
284+
- **Solution:** Run `pnpm install` first - dependencies not installed
235285

236286
**Issue:** Lint errors about Prettier formatting
237287
- **Solution:** Run `npm run format` first, then lint again
@@ -242,26 +292,46 @@ function my_function() {
242292
**Issue:** Composer hangs asking for GitHub token
243293
- **Solution:** Use `composer install --no-interaction` or let it clone from cache (slower but works)
244294

245-
**Issue:** Build directory is empty after `npm run build`
246-
- **Solution:** Check for errors in console; ensure `src/[your-block-name]/` files exist
295+
**Issue:** Build directories are empty after `pnpm run build`
296+
- **Solution:** Check for errors in console; ensure plugin `src/` directories exist
247297

248298
**Issue:** Plugin not working in WordPress after changes
249-
- **Solution:** ALWAYS run `npm run build` after changing any file in `src/`
299+
- **Solution:** ALWAYS run `pnpm run build` after changing any file in `src/`
300+
301+
**Issue:** "only-allow pnpm" error when using npm
302+
- **Solution:** Use `pnpm` instead of `npm` - this is a pnpm-only workspace
250303

251304
## Important Notes
252305

253-
- The `build/` directory is git-ignored but REQUIRED for the plugin to function
306+
- This is a **monorepo** containing multiple WordPress block examples
307+
- Each plugin in `plugins/` is a standalone WordPress plugin demonstrating specific block concepts
308+
- The `build/` directories are git-ignored but REQUIRED for plugins to function
254309
- Never edit files in `build/` directly - they are auto-generated
255-
- The plugin uses WordPress 6.8+ block registration API with blocks-manifest.php for improved performance
256-
- All source files are in `src/[your-block-name]/`, all build outputs go to `build/[your-block-name]/`
310+
- All plugins use WordPress 6.8+ block registration API
311+
- Source files are in `plugins/*/src/`, build outputs go to `plugins/*/build/`
257312
- This project follows WordPress coding standards, which use TABS for indentation
258-
- Do not generate additional files beyond what is required for the assigned task (e.g., summary or documentation files) unless explicitly requested
313+
- Use `pnpm` exclusively - do not use `npm` or `yarn`
314+
- The repository includes a documentation site in `_app/` and utilities in `_bin/`
315+
- Examples are meant to be educational and demonstrate best practices
316+
317+
## Additional Resources
318+
319+
- **GitHub Wiki:** https://github.com/WordPress/block-development-examples/wiki - Extended documentation and guides
320+
- **Documentation Site:** Built from `_app/` and deployed via GitHub Pages
321+
- **Example Categories:** Each plugin demonstrates different aspects of block development:
322+
- Basic blocks (static/dynamic rendering)
323+
- Block supports and attributes
324+
- Interactivity API examples
325+
- Data layer interactions
326+
- Custom controls and toolbars
327+
- Internationalization examples
328+
- And more...
259329

260330
## Trust These Instructions
261331

262-
These instructions have been thoroughly tested and validated. Only perform additional searches or exploration if:
332+
These instructions have been tailored for the WordPress Block Development Examples monorepo. The repository serves as a comprehensive learning resource for WordPress block development. Only perform additional searches or exploration if:
263333
- The information here is incomplete for your specific task
264334
- You encounter an error not documented in "Common Issues"
265335
- You are adding new functionality not covered by existing patterns
266336

267-
For routine code changes, trust this documentation and avoid unnecessary exploration.
337+
For routine code changes and example additions, trust this documentation and the existing patterns in the repository.

0 commit comments

Comments
 (0)