Skip to content

Commit 13bb5c3

Browse files
authored
Merge branch 'main' into fix/break-circular-references
Signed-off-by: Ash Shaw <[email protected]>
2 parents f3f411a + 0795203 commit 13bb5c3

14 files changed

+393
-16
lines changed

README.md

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,86 @@ A multi-block WordPress plugin scaffold with support for:
3030
- Node.js 18+
3131
- [Secure Custom Fields](https://wordpress.org/plugins/secure-custom-fields/) plugin
3232

33-
## Installation
33+
## Using This Scaffold
3434

35-
1. Clone this repository to your WordPress plugins directory:
35+
This scaffold can be used in two ways:
36+
37+
### Option 1: Template Mode (Modify Scaffold Directly)
38+
39+
Use the scaffold as a template repository and process it in-place:
40+
41+
1. **Create from template** on GitHub or clone the repository
42+
2. **Process the scaffold** with your plugin details:
43+
44+
```bash
45+
node scripts/generate-plugin.js --in-place
46+
```
47+
48+
This will:
49+
- Prompt for confirmation (to prevent accidental overwrites)
50+
- Replace all `{{mustache}}` variables in files
51+
- Update file and directory names with your slug
52+
- Process the scaffold directory directly (no separate output)
53+
54+
3. **Install dependencies and build**:
55+
56+
```bash
57+
npm install
58+
composer install
59+
npm run build
60+
```
61+
62+
4. **Commit your customized plugin** to your repository
63+
64+
**⚠️ Important**: Template mode modifies files in-place. Always use on a fresh clone or when you're certain you want to replace the scaffold content.
65+
66+
### Option 2: Generator Mode (Create New Plugin)
67+
68+
Generate a new plugin in a separate output directory:
69+
70+
1. **Clone or download** this scaffold repository
71+
2. **Run the generator** to create a new plugin:
72+
73+
```bash
74+
node scripts/generate-plugin.js
75+
```
76+
77+
Or with a configuration file:
78+
79+
```bash
80+
node scripts/generate-plugin.js --config my-plugin-config.json
81+
```
82+
83+
3. **Find your generated plugin** in:
84+
- `generated-plugins/<your-slug>/` - Complete plugin ready to use
85+
86+
4. **Move to WordPress plugins directory**:
87+
88+
```bash
89+
mv generated-plugins/my-plugin/ /path/to/wordpress/wp-content/plugins/
90+
cd /path/to/wordpress/wp-content/plugins/my-plugin/
91+
npm install
92+
composer install
93+
npm run build
94+
```
95+
96+
**Benefits**: Keeps the scaffold repository clean and can generate multiple plugins.
97+
98+
See [docs/GENERATE-PLUGIN.md](docs/GENERATE-PLUGIN.md) for detailed usage instructions, configuration options, and examples.
99+
100+
## Installation (For Already-Generated Plugins)
101+
102+
If you've already processed the scaffold or received a generated plugin:
103+
104+
1. Ensure you're in your WordPress plugins directory:
36105

37106
```bash
38-
cd wp-content/plugins/
39-
git clone https://github.com/{{author}}/{{slug}}.git
107+
cd wp-content/plugins/your-plugin-name
40108
```
41109

42110
2. Install dependencies:
43111

44112
```bash
45-
cd {{slug}}
46113
npm install
47114
composer install
48115
```

docs/GENERATE-PLUGIN.md

Lines changed: 167 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,147 @@ JSON configuration files (`package.json`, `composer.json`, `block.json`) use pla
253253
}
254254
```
255255

256+
## Operational Modes
257+
258+
### Template Mode vs Generator Mode
259+
260+
The scaffold supports two operational modes:
261+
262+
#### Template Mode (`--in-place`)
263+
264+
**Use when**: You want to use the scaffold as a starting point for your plugin.
265+
266+
- Processes files directly in the scaffold directory
267+
- Replaces all mustache variables in-place
268+
- Renames files and directories to match your slug
269+
- **⚠️ Destructive**: Modifies the scaffold permanently
270+
- Includes confirmation prompt to prevent accidents
271+
- Best for GitHub template repositories
272+
273+
**Command:**
274+
275+
```bash
276+
node scripts/generate-plugin.js --in-place
277+
```
278+
279+
**Workflow:**
280+
281+
1. Clone/fork the scaffold repository
282+
2. Run generator with `--in-place` flag
283+
3. Confirm the operation (y/N prompt)
284+
4. Scaffold is processed in-place
285+
5. Install dependencies and build
286+
6. Commit your customized plugin
287+
288+
#### Generator Mode (Default)
289+
290+
**Use when**: You want to create multiple plugins or keep the scaffold clean.
291+
292+
- Creates new plugin in `generated-plugins/<slug>/`
293+
- Leaves scaffold directory unchanged
294+
- Can generate multiple plugins
295+
- Safe for repeated use
296+
- Best for maintaining the scaffold as a tool
297+
298+
**Command:**
299+
300+
```bash
301+
node scripts/generate-plugin.js
302+
```
303+
304+
**Workflow:**
305+
306+
1. Clone the scaffold repository once
307+
2. Run generator (no `--in-place` flag)
308+
3. Generated plugin appears in `generated-plugins/<slug>/`
309+
4. Move to WordPress plugins directory
310+
5. Install dependencies and build
311+
6. Generate another plugin anytime
312+
256313
## Generation Methods
257314

258-
### Method 1: AI-Assisted Generation (Recommended)
315+
### Method 1: Template Mode (In-Place Processing)
316+
317+
Use the scaffold as a GitHub template and process it directly:
318+
319+
```bash
320+
# Interactive mode with confirmation
321+
node scripts/generate-plugin.js --in-place
322+
323+
# With configuration file
324+
node scripts/generate-plugin.js --in-place --config plugin-config.json
325+
326+
# Skip confirmation (automation only - use with caution)
327+
node scripts/generate-plugin.js --in-place --yes
328+
```
329+
330+
**Process:**
331+
332+
1. Prompts for plugin configuration (or reads from config file)
333+
2. **Displays confirmation warning** about in-place modification
334+
3. Waits for user confirmation (y/N)
335+
4. Processes all files in the scaffold directory
336+
5. Replaces mustache variables throughout
337+
6. Renames files/directories to match your slug
338+
7. Reports completion with next steps
339+
340+
**⚠️ Important Notes:**
341+
342+
- Always use on a fresh clone or template repository
343+
- Cannot be undone without version control
344+
- Confirmation prompt defaults to "No" for safety
345+
- Use `--yes` flag only in automated workflows you trust
346+
347+
### Method 2: Generator Mode (Default)
348+
349+
Create a new plugin in a separate output directory:
350+
351+
```bash
352+
# Interactive mode - prompts for all configuration
353+
node scripts/generate-plugin.js
354+
355+
# With configuration file
356+
node scripts/generate-plugin.js --config plugin-config.json
357+
358+
# With inline arguments
359+
node scripts/generate-plugin.js \
360+
--slug tour-operator \
361+
--name "Tour Operator" \
362+
--description "Tour booking and display plugin" \
363+
--author "LightSpeed" \
364+
--author-uri "https://developer.lsdev.biz"
365+
```
366+
367+
**Process:**
368+
369+
1. Reads configuration from prompts, file, or arguments
370+
2. Validates configuration against schema
371+
3. Creates `generated-plugins/<slug>/` directory
372+
4. Copies and processes all scaffold files
373+
5. Replaces mustache variables
374+
6. Renames files/directories
375+
7. Leaves scaffold directory unchanged
376+
377+
**Output Location:**
378+
379+
```bash
380+
generated-plugins/
381+
└── tour-operator/ # Your generated plugin
382+
├── tour-operator.php
383+
├── package.json
384+
├── composer.json
385+
└── ... (complete plugin structure)
386+
```
387+
388+
**Best for:**
389+
390+
- Creating multiple plugins from the same scaffold
391+
- Keeping scaffold repository clean
392+
- Testing different configurations
393+
- CI/CD pipelines
394+
- Advanced users comfortable with CLI tools
395+
396+
### Method 3: AI-Assisted Generation (Recommended)
259397

260398
Use the workspace prompt for an interactive, guided experience:
261399

@@ -270,7 +408,7 @@ Use the workspace prompt for an interactive, guided experience:
270408
3. Collects all required information interactively
271409
4. Validates input at each stage
272410
5. Confirms configuration before generation
273-
6. Generates the complete plugin structure
411+
6. Generates the complete plugin structure (uses generator mode by default)
274412
7. Provides post-generation setup instructions
275413

276414
**Benefits:**
@@ -280,6 +418,7 @@ Use the workspace prompt for an interactive, guided experience:
280418
- Validation at each step
281419
- Smart defaults for common configurations
282420
- Best for first-time users
421+
- Can use either template or generator mode
283422

284423
**Stages:**
285424

@@ -291,7 +430,7 @@ Use the workspace prompt for an interactive, guided experience:
291430
6. **Templates & Patterns** - Template and pattern selection
292431
7. **Version & Compatibility** - WordPress/PHP requirements
293432

294-
### Method 2: Agent-Based Generation
433+
### Method 4: Agent-Based Generation
295434

296435
Request the scaffold generator agent directly:
297436

@@ -327,8 +466,9 @@ node scripts/generate-plugin.js
327466
# Prompts for all required information
328467
node scripts/generate-plugin.js
329468
```
469+
### Method 4: Agent-Based Generation
330470

331-
**Direct Mode:**
471+
Request the scaffold generator agent directly:
332472

333473
```bash
334474
# Provide all values via arguments
@@ -354,13 +494,24 @@ node scripts/validate-plugin-config.js my-plugin.json
354494
355495
# Generate plugin
356496
node scripts/generate-plugin.js --config my-plugin.json
497+
```text
498+
Generate a new multi-block plugin from scaffold
357499
```
358500

359-
**Best for:**
501+
Or be more specific:
360502

361-
- Automation and CI/CD pipelines
362-
- Batch plugin generation
363-
- Advanced users comfortable with CLI tools
503+
```text
504+
Create a tour operator plugin with tours CPT, destination taxonomy, and booking fields
505+
```
506+
507+
**Features:**
508+
509+
- Conversational interface
510+
- Can infer requirements from description
511+
- Validates configuration automatically
512+
- Follows agent specification in `.github/agents/generate-plugin.agent.md`
513+
- Best for experienced users who know their requirements
514+
- Can use either template or generator mode
364515

365516
## Post-Generation Workflow
366517

@@ -373,7 +524,7 @@ tree -L 2
373524

374525
Expected structure:
375526

376-
```
527+
```text
377528
tour-operator/
378529
├── tour-operator.php # Main plugin file (slug-based name)
379530
├── package.json # Node dependencies
@@ -386,7 +537,7 @@ tour-operator/
386537
│ └── scss/ # Stylesheets
387538
├── templates/ # Block templates
388539
├── patterns/ # Block patterns
389-
├── parts/ # Template parts
540+
├── template-parts/ # Template parts
390541
└── scf-json/ # SCF field groups
391542
```
392543

@@ -856,6 +1007,12 @@ For complete schema details, see:
8561007
- **[../.github/instructions/generate-plugin.instructions.md](../.github/instructions/generate-plugin.instructions.md)** - Mustache template rules
8571008
- **[../.github/instructions/schema-files.instructions.md](../.github/instructions/schema-files.instructions.md)** - Schema file standards
8581009
- **[../.github/instructions/scf-fields.instructions.md](../.github/instructions/scf-fields.instructions.md)** - SCF field types
1010+
- [Generator Instructions](.github/instructions/generate-plugin.instructions.md) - Rules for using mustache values
1011+
- [Plugin Generator Agent](.github/agents/generate-plugin.agent.md) - Agent specification
1012+
- [Generation Prompt](.github/prompts/generate-plugin.prompt.md) - Interactive prompt template
1013+
- [SCF Fields Reference](.github/instructions/scf-fields.instructions.md) - Field types and usage
1014+
- [Build Process](BUILD-PROCESS.md) - Detailed build documentation
1015+
- [API Reference](API-REFERENCE.md) - PHP and JavaScript APIs
8591016

8601017
## Support
8611018

inc/class-block-bindings.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace {{namespace|lowerCase}}\classes;
3+
24
/**
35
* Block Bindings Registration.
46
*
@@ -17,6 +19,13 @@
1719
*/
1820
class Block_Bindings {
1921

22+
/**
23+
* Binding source name.
24+
*
25+
* @var string
26+
*/
27+
const SOURCE = '{{namespace}}/fields';
28+
2029
/**
2130
* Constructor.
2231
*/

inc/class-block-templates.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace {{namespace|lowerCase}}\classes;
3+
24
/**
35
* Block Templates Registration.
46
*

0 commit comments

Comments
 (0)