|
| 1 | +# Copilot Instructions for WordPress Project |
| 2 | + |
| 3 | +## Overview |
| 4 | +WordPress project combining classic and block-based features (Gutenberg). Separates business logic (`plugin/`) from presentation (`theme/`). |
| 5 | + |
| 6 | +**Stack:** PHP 8.1+, JavaScript (ES6+), CSS, webpack 5, PostCSS, Babel, @wordpress/env (Docker), PHPUnit 10 |
| 7 | + |
| 8 | +**Versions:** Node.js v20.x, npm v10.x, PHP 8.1+, Composer v2.x, Docker v20.x+ |
| 9 | + |
| 10 | +## Code Modification Rules |
| 11 | +✅ **ALLOWED:** `plugin/` and `theme/` directories, documentation |
| 12 | +❌ **FORBIDDEN:** Code outside `plugin/`/`theme/`, generated/dependency directories (`vendor/`, `node_modules/`, `dist/`) |
| 13 | + |
| 14 | +## Installation (ALWAYS follow this order) |
| 15 | + |
| 16 | +1. **npm dependencies:** |
| 17 | + ```bash |
| 18 | + npm ci # ~15-20s, deprecation warnings OK |
| 19 | + ``` |
| 20 | + |
| 21 | +2. **Composer dependencies:** |
| 22 | + ```bash |
| 23 | + composer install --prefer-dist --optimize-autoloader --no-interaction |
| 24 | + ``` |
| 25 | + **Time:** 3-5 minutes |
| 26 | + **CRITICAL:** "Could not authenticate against github.com" warnings are NORMAL due to GitHub rate limits. Composer falls back to git clone. Installation WILL succeed. |
| 27 | + |
| 28 | +3. **Build:** |
| 29 | + ```bash |
| 30 | + npm run build # ~10-15s, compiles to theme/dist/, theme/admin/dist/, plugin/admin/dist/ |
| 31 | + ``` |
| 32 | + **Note:** `isModuleDeclaration` deprecation warning is safe to ignore |
| 33 | + |
| 34 | +## Build Commands |
| 35 | +- `npm run build` - Development (unminified) |
| 36 | +- `npm run release:build` - Production (minified, webpack --mode='production') |
| 37 | +- `npm run watch` - Watch mode with LiveReload (run AFTER `npm start`) |
| 38 | + |
| 39 | +## Linting (REQUIRED before commit) |
| 40 | +```bash |
| 41 | +npm run lint # ~5-10s, must exit 0 |
| 42 | +``` |
| 43 | +Runs: PHPCS (WordPress Standards), ESLint, Stylelint |
| 44 | + |
| 45 | +**Auto-fix:** |
| 46 | +```bash |
| 47 | +npm run lint:fix # All |
| 48 | +npm run fix:php # PHPCBF |
| 49 | +npm run fix:js # ESLint --fix |
| 50 | +npm run fix:css # Stylelint --fix |
| 51 | +``` |
| 52 | + |
| 53 | +**Individual:** `npm run lint:php|js|css` or `composer run lint|fix` |
| 54 | + |
| 55 | +## Testing |
| 56 | +```bash |
| 57 | +npm test # PHPUnit for plugin + theme, requires Docker running |
| 58 | +``` |
| 59 | +Individual: `npm run test:unit:env:plugin|theme` |
| 60 | + |
| 61 | +## Development Environment |
| 62 | +```bash |
| 63 | +npm start # First run: ~5-10min, subsequent: ~30s |
| 64 | +``` |
| 65 | +**Access:** http://localhost |
| 66 | +**Credentials:** username=`admin`, password=`password` |
| 67 | +**Prereq:** Docker running |
| 68 | +**First run auto-executes:** `npm install && composer install && npm run update:schemas && npm run build` |
| 69 | + |
| 70 | +```bash |
| 71 | +npm stop # Stop environment |
| 72 | +npm run env:clean # Remove containers/volumes |
| 73 | +npm run env:reset # Clean + reinitialize |
| 74 | +``` |
| 75 | + |
| 76 | +## Project Structure |
| 77 | + |
| 78 | +**Root Files:** `package.json`, `composer.json`, `webpack.config.js`, `phpcs.xml`, `.eslintrc`, `.stylelintrc.json`, `postcss.config.js`, `.wp-env.json` |
| 79 | + |
| 80 | +**`plugin/` - WordPress Plugin** |
| 81 | +- `lhpbpp.php` - Main file (text domain: `lhpbpp`) |
| 82 | +- `inc/` - Business logic |
| 83 | +- `admin/src/{js,css}/` - Admin source → `admin/dist/` (gitignored) |
| 84 | +- `blocks/demo/` - Example Gutenberg block |
| 85 | +- `tests/` - PHPUnit tests |
| 86 | +- `.distignore` - Excludes `/admin/src/` from releases |
| 87 | + |
| 88 | +**`theme/` - WordPress Theme** |
| 89 | +- `style.css` - Main stylesheet (text domain: `lhpbpt`) |
| 90 | +- `functions.php`, `inc/` - Theme logic |
| 91 | +- `src/{js,css}/` - Frontend source → `dist/` (gitignored) |
| 92 | +- `admin/src/{js,css}/` - Admin source → `admin/dist/` (gitignored) |
| 93 | +- `template-parts/` - Template files |
| 94 | +- `theme.json` - Block configuration |
| 95 | +- `tests/` - PHPUnit tests |
| 96 | +- `.distignore` - Excludes `/src` and `/admin/src` from releases |
| 97 | + |
| 98 | +**`bin/`** - Build scripts: archiveProject.js, updatePluginVersion.js, updateThemeVersion.js, updateThemeJsonSchema.js, lifecycleScripts/initialize.sh |
| 99 | + |
| 100 | +**`archives/`** - Release ZIPs (generated by `npm run release`) |
| 101 | + |
| 102 | +**webpack configs:** |
| 103 | +1. `themeFrontend` → theme/dist/ (Babel preset-env, vanilla JS) |
| 104 | +2. `themeBackend` → theme/admin/dist/ (WordPress preset, dependency extraction) |
| 105 | +3. `pluginBackend` → plugin/admin/dist/ (WordPress preset, dependency extraction) |
| 106 | + |
| 107 | +## GitHub CI Workflows |
| 108 | + |
| 109 | +**`main.yml` - Build & Deploy** (on push/PR to main) |
| 110 | +1. Setup Node 20, PHP 8.1, Composer v2 |
| 111 | +2. `composer install --prefer-dist --optimize-autoloader` |
| 112 | +3. `npm ci` |
| 113 | +4. **`npm run lint`** ← MUST PASS |
| 114 | +5. **`npm run release`** ← MUST BUILD |
| 115 | +Failure at any step stops workflow. |
| 116 | + |
| 117 | +**`release.yml` - Release Please** (on push to main) |
| 118 | +- Creates release PRs via release-please |
| 119 | +- On merge: lint → build → upload ZIP → deploy |
| 120 | +- **Requires:** `GH_ADMIN_TOKEN` secret |
| 121 | + |
| 122 | +**`lint-pr.yml`** - Validates PR titles follow Conventional Commits (feat:, fix:, chore:, docs:) |
| 123 | + |
| 124 | +## Commit & Branch Standards |
| 125 | + |
| 126 | +**Commits MUST follow Conventional Commits:** |
| 127 | +- `feat: add block` |
| 128 | +- `fix: resolve lint error` |
| 129 | +- `chore: update deps` |
| 130 | +- `docs: improve README` |
| 131 | + |
| 132 | +**Branches:** `add/`, `fix/`, `update/`, `try/` |
| 133 | + |
| 134 | +## Common Issues |
| 135 | + |
| 136 | +**Composer GitHub Auth Warnings** |
| 137 | +- "Could not authenticate" = NORMAL (rate limits) |
| 138 | +- Composer falls back to cloning from git |
| 139 | +- Installation completes successfully (just slower) |
| 140 | + |
| 141 | +**babel deprecation warning** |
| 142 | +- `isModuleDeclaration` warning = safe to ignore |
| 143 | +- Builds succeed normally |
| 144 | + |
| 145 | +**npm vulnerabilities** |
| 146 | +- Dev dependencies only, typically safe to ignore for development |
| 147 | + |
| 148 | +## Release Process |
| 149 | +```bash |
| 150 | +npm run release |
| 151 | +``` |
| 152 | +1. Production build (`webpack --mode='production'`) |
| 153 | +2. Update versions in `plugin/lhpbpp.php` and `theme/style.css` |
| 154 | +3. Create ZIPs in `archives/` (respects .distignore) |
| 155 | + |
| 156 | +## PHP Standards Customizations (phpcs.xml) |
| 157 | +- **Disabled:** YodaConditions, ValidHookName.UseUnderscores, FileName |
| 158 | +- **Target:** PHP 8.1+ (PHPCompatibilityWP) |
| 159 | +- **Text domains:** Plugin=`lhpbpp`, Theme=`lhpbpt` (phpcs.xml expects `lhpbp` - may need update) |
| 160 | +- CI ignores warnings (`ignore_warnings_on_exit`) |
| 161 | + |
| 162 | +## Quick Checklist |
| 163 | + |
| 164 | +**Before changes:** |
| 165 | +1. Docker running (if using wp-env) |
| 166 | +2. `npm ci && composer install --no-interaction` (first time) |
| 167 | +3. `npm run build` works |
| 168 | + |
| 169 | +**Before commit:** |
| 170 | +1. **`npm run lint`** exits 0 (required) |
| 171 | +2. Use `npm run lint:fix` for auto-fixes |
| 172 | +3. `npm run build` succeeds |
| 173 | +4. Follow Conventional Commits |
| 174 | + |
| 175 | +**For CI to pass:** |
| 176 | +- Linting passes |
| 177 | +- Production build succeeds |
| 178 | +- PR title follows Conventional Commits |
| 179 | + |
| 180 | +## Additional Info |
| 181 | +- **i18n:** `composer run i18n-make-pot`, `composer run i18n-make-json` |
| 182 | +- **PostCSS:** Reads vars from `theme/src/css/vars.css`, applies preset-env stage 1, cssnano minification |
| 183 | +- **Config files:** `.wp-env.json` (port 80, WP_DEBUG true), `phpunit.xml` (both dirs) |
| 184 | + |
| 185 | +**Trust these instructions as a starting point.** Search the codebase when you need to understand specific implementation details, encounter undocumented errors, or find instructions incomplete. |
0 commit comments