|
| 1 | +# Scripts Directory |
| 2 | + |
| 3 | +This directory contains utility scripts for the WDS Block Theme project. |
| 4 | + |
| 5 | +## update-cursorrules.sh |
| 6 | + |
| 7 | +This script automatically extracts the PHP version from `composer.json` and updates the Cursor rules files in the `.cursor/rules/` directory to ensure Cursor uses the correct PHP version for code analysis and suggestions. |
| 8 | + |
| 9 | +### Features |
| 10 | + |
| 11 | +- **Automatic PHP Version Detection**: Uses `jq` to parse `composer.json` and extract the PHP version |
| 12 | +- **Multiple Version Sources**: Checks multiple locations in composer.json: |
| 13 | + - `config.platform.php` (preferred) |
| 14 | + - `require-dev.php` |
| 15 | + - `require.php` |
| 16 | +- **Version String Cleaning**: Removes version constraints (>=, ^, ~, etc.) to get the base version |
| 17 | +- **Modern Cursor Rules Structure**: Creates separate `.mdc` files in `.cursor/rules/` directory: |
| 18 | + - `dependency-management.mdc` - PHP version and package management |
| 19 | + - `development-workflow.mdc` - Project structure and workflow |
| 20 | + - `javascript-standards.mdc` - Frontend development standards |
| 21 | + - `php-code-standards.mdc` - Comprehensive PHP coding standards |
| 22 | + - `theme-development.mdc` - WordPress theme development guidelines |
| 23 | + |
| 24 | +### Prerequisites |
| 25 | + |
| 26 | +- `jq` must be installed on your system |
| 27 | + - macOS: `brew install jq` |
| 28 | + - Ubuntu/Debian: `sudo apt-get install jq` |
| 29 | + - Windows: Download from https://stedolan.github.io/jq/download/ |
| 30 | + |
| 31 | +### Usage |
| 32 | + |
| 33 | +#### Manual Execution |
| 34 | +```bash |
| 35 | +./scripts/update-cursorrules.sh |
| 36 | +``` |
| 37 | + |
| 38 | +#### Via NPM Script |
| 39 | +```bash |
| 40 | +npm run update-cursorrules |
| 41 | +``` |
| 42 | + |
| 43 | +#### Automatic Execution |
| 44 | +The script runs automatically after: |
| 45 | +- `npm install` (via postinstall script) |
| 46 | +- `composer install` (via post-install-cmd script) |
| 47 | + |
| 48 | +### Output |
| 49 | + |
| 50 | +The script creates/updates files in `.cursor/rules/` directory: |
| 51 | + |
| 52 | +``` |
| 53 | +.cursor/rules/ |
| 54 | +├── dependency-management.mdc # PHP version and package management |
| 55 | +├── development-workflow.mdc # Project structure and workflow |
| 56 | +├── javascript-standards.mdc # Frontend development standards |
| 57 | +├── php-code-standards.mdc # Comprehensive PHP coding standards |
| 58 | +└── theme-development.mdc # WordPress theme development guidelines |
| 59 | +``` |
| 60 | + |
| 61 | +Each file contains specific guidelines for different aspects of development: |
| 62 | + |
| 63 | +#### dependency-management.mdc |
| 64 | +- PHP version configuration (automatically updated) |
| 65 | +- Package management guidelines |
| 66 | +- Development environment setup |
| 67 | +- Build process instructions |
| 68 | + |
| 69 | +#### development-workflow.mdc |
| 70 | +- Project structure overview |
| 71 | +- Code standards and quality assurance |
| 72 | +- Testing and error handling |
| 73 | +- Performance optimization |
| 74 | + |
| 75 | +#### javascript-standards.mdc |
| 76 | +- Modern JavaScript (ES6+) standards |
| 77 | +- Block development guidelines |
| 78 | +- Code style and documentation |
| 79 | +- Testing and build processes |
| 80 | + |
| 81 | +#### php-code-standards.mdc |
| 82 | +- WordPress PHP Coding Standards (WPCS) |
| 83 | +- Code style and naming conventions |
| 84 | +- Security and performance guidelines |
| 85 | +- Testing and error handling |
| 86 | +- Database best practices |
| 87 | + |
| 88 | +#### theme-development.mdc |
| 89 | +- WordPress block theme standards |
| 90 | +- Theme structure and setup |
| 91 | +- Block patterns and templates |
| 92 | +- Internationalization and accessibility |
| 93 | +- Performance optimization |
| 94 | + |
| 95 | +### Error Handling |
| 96 | + |
| 97 | +The script includes comprehensive error handling: |
| 98 | +- Checks for `jq` installation |
| 99 | +- Validates `composer.json` exists |
| 100 | +- Provides helpful error messages if PHP version cannot be extracted |
| 101 | +- Uses colored output for better readability |
| 102 | + |
| 103 | +### Integration |
| 104 | + |
| 105 | +This script is integrated into the project's build process: |
| 106 | + |
| 107 | +1. **NPM Integration**: Added to `package.json` postinstall script |
| 108 | +2. **Composer Integration**: Added to `composer.json` post-install-cmd script |
| 109 | +3. **Manual Script**: Available as `npm run update-cursorrules` |
| 110 | + |
| 111 | +### Benefits |
| 112 | + |
| 113 | +- **Consistent PHP Version**: Ensures Cursor always uses the correct PHP version |
| 114 | +- **Organized Rules**: Separates concerns into focused rule files |
| 115 | +- **Automatic Updates**: No manual intervention required |
| 116 | +- **Project-Specific Rules**: Tailored to WordPress block theme development |
| 117 | +- **Modern PHP Features**: Leverages PHP 8.2+ features in suggestions |
| 118 | +- **WordPress Standards**: Includes WordPress-specific coding guidelines |
| 119 | +- **Comprehensive Coverage**: Covers all aspects of theme development |
| 120 | + |
| 121 | +## test-update-cursorrules.sh |
| 122 | + |
| 123 | +This script is used to test the extraction and update logic for the Cursor rules automation. |
0 commit comments