@sabbir1991/wpscaffold 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +326 -0
- package/bin/index.js +19 -0
- package/lib/generator.js +435 -0
- package/package.json +30 -0
- package/template/_editorconfig +19 -0
- package/template/_github/ISSUE_TEMPLATE/bug_report.yml +29 -0
- package/template/_github/ISSUE_TEMPLATE/config.yml +1 -0
- package/template/_github/ISSUE_TEMPLATE/feature_request.yml +18 -0
- package/template/_github/PULL_REQUEST_TEMPLATE.md +16 -0
- package/template/_github/workflows/lint.yml +31 -0
- package/template/_github/workflows/phpcs.yml +29 -0
- package/template/_github/workflows/phpunit.yml +34 -0
- package/template/_gitignore +34 -0
- package/template/_nvmrc +1 -0
- package/template/_stylelintignore +11 -0
- package/template/composer.json +35 -0
- package/template/eslint.config.js +8 -0
- package/template/includes/Admin/Menu.php +67 -0
- package/template/includes/Assets.php +140 -0
- package/template/includes/Blocks.php +53 -0
- package/template/includes/Plugin.php +59 -0
- package/template/includes/Traits/Singleton.php +46 -0
- package/template/languages/.gitkeep +0 -0
- package/template/lefthook.yml +13 -0
- package/template/phpcs.xml.dist +42 -0
- package/template/phpunit.xml.dist +19 -0
- package/template/plugin-skeleton.php +64 -0
- package/template/readme.txt +25 -0
- package/template/src/block/block.json +17 -0
- package/template/src/block/edit.js +17 -0
- package/template/src/block/index.js +13 -0
- package/template/src/block/render.php +13 -0
- package/template/src/block/style.scss +8 -0
- package/template/src/block/view.js +5 -0
- package/template/src/global/css/admin.scss +8 -0
- package/template/src/global/js/admin.js +5 -0
- package/template/tests/Unit/AbstractTestCase.php +25 -0
- package/template/tests/Unit/AssetsTest.php +58 -0
- package/template/tests/Unit/MenuTest.php +38 -0
- package/template/tests/bootstrap.php +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 wpRigel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 🧱 wpscaffold
|
|
4
|
+
|
|
5
|
+
**Instantly scaffold a production-ready WordPress plugin from the command line.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@sabbir1991/wpscaffold)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](https://nodejs.org)
|
|
10
|
+
[](https://wordpress.org)
|
|
11
|
+
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## ✨ What is wpscaffold?
|
|
17
|
+
|
|
18
|
+
`wpscaffold` is a zero-config CLI that generates a **fully wired WordPress plugin** in seconds — complete with PHP class structure, Gutenberg block support, admin UI, GitHub Actions CI, PHPUnit tests, ESLint, Stylelint, PHPCS, and more. Stop copy-pasting boilerplate. Start building.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 🚀 Quick Start
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Install globally
|
|
26
|
+
npm install -g @sabbir1991/wpscaffold
|
|
27
|
+
|
|
28
|
+
# Scaffold a plugin
|
|
29
|
+
wpscaffold create "My Awesome Plugin"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
That's it. Follow the prompts, and your plugin directory is ready.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 📦 Installation
|
|
37
|
+
|
|
38
|
+
### Global (recommended)
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install -g @sabbir1991/wpscaffold
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Local development / testing
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
git clone https://github.com/sabbir1991/wpscaffold.git
|
|
48
|
+
cd wpscaffold
|
|
49
|
+
npm link
|
|
50
|
+
|
|
51
|
+
# Now available anywhere on your machine:
|
|
52
|
+
wpscaffold create "My Plugin"
|
|
53
|
+
|
|
54
|
+
# Unlink after publishing:
|
|
55
|
+
npm unlink -g @sabbir1991/wpscaffold
|
|
56
|
+
npm install -g @sabbir1991/wpscaffold
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 🛠️ Usage
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Pass plugin name directly (recommended)
|
|
65
|
+
wpscaffold create "My Awesome Plugin"
|
|
66
|
+
|
|
67
|
+
# Or let the tool prompt you
|
|
68
|
+
wpscaffold create
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
After running, you'll see an interactive prompt session:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
╔══════════════════════════════╗
|
|
75
|
+
║ Create WordPress Scaffold ║
|
|
76
|
+
╚══════════════════════════════╝
|
|
77
|
+
|
|
78
|
+
Press Enter to accept default values in brackets.
|
|
79
|
+
|
|
80
|
+
Plugin Name [My Plugin]:
|
|
81
|
+
Slug / text-domain [my-plugin]:
|
|
82
|
+
Description [A WordPress plugin.]:
|
|
83
|
+
Author Name [Your Name]:
|
|
84
|
+
Author Email:
|
|
85
|
+
Author URI [https://yoursite.com]:
|
|
86
|
+
Plugin URI [https://yoursite.com/my-plugin]:
|
|
87
|
+
Namespace Vendor [Your]:
|
|
88
|
+
Namespace Package [MyPlugin]:
|
|
89
|
+
Plugin Type [admin / block / both]:
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 🎛️ Prompts Reference
|
|
95
|
+
|
|
96
|
+
| Prompt | Default | Description |
|
|
97
|
+
|--------|---------|-------------|
|
|
98
|
+
| **Plugin Name** | CLI argument or `My Plugin` | Human-readable plugin name |
|
|
99
|
+
| **Slug / text-domain** | kebab-case from name | Used for directories, function prefixes, text-domain |
|
|
100
|
+
| **Description** | `A WordPress plugin.` | Short plugin description |
|
|
101
|
+
| **Author Name** | `git config user.name` | Auto-detected from Git |
|
|
102
|
+
| **Author Email** | `git config user.email` | Auto-detected from Git |
|
|
103
|
+
| **Author URI** | `https://yoursite.com` | Your personal/company URL |
|
|
104
|
+
| **Plugin URI** | `{authorUri}/{slug}` | Plugin homepage URL |
|
|
105
|
+
| **Namespace Vendor** | First word of author (PascalCase) | PHP namespace vendor segment |
|
|
106
|
+
| **Namespace Package** | PascalCase of slug | PHP namespace package segment |
|
|
107
|
+
| **Constant Prefix** | UPPER_SNAKE from slug | PHP constant prefix (e.g. `MY_PLUGIN`) |
|
|
108
|
+
| **Plugin Type** | `both` | Controls what files are scaffolded |
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## 🧩 Plugin Types
|
|
113
|
+
|
|
114
|
+
Choose the type that matches what you're building:
|
|
115
|
+
|
|
116
|
+
| Type | 🏗️ Includes | 🗑️ Omits |
|
|
117
|
+
|------|------------|---------|
|
|
118
|
+
| `admin` | Admin menu, admin JS/CSS assets | Gutenberg block source |
|
|
119
|
+
| `block` | Gutenberg block(s), block editor packages | Admin menu, admin JS/CSS |
|
|
120
|
+
| `both` | Everything — admin UI + blocks | Nothing |
|
|
121
|
+
|
|
122
|
+
> **Tip:** Not sure? Pick `both`. You can always delete what you don't need.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 📁 Generated Structure
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
my-awesome-plugin/
|
|
130
|
+
│
|
|
131
|
+
├── 📄 my-awesome-plugin.php ← Plugin entry point
|
|
132
|
+
├── 📄 readme.txt ← WordPress.org readme
|
|
133
|
+
├── 📄 composer.json
|
|
134
|
+
├── 📄 phpcs.xml.dist
|
|
135
|
+
├── 📄 phpunit.xml.dist
|
|
136
|
+
├── 📄 eslint.config.js
|
|
137
|
+
├── 📄 lefthook.yml ← Git hooks (lint on commit)
|
|
138
|
+
│
|
|
139
|
+
├── 🔧 .editorconfig
|
|
140
|
+
├── 🔧 .gitignore
|
|
141
|
+
├── 🔧 .nvmrc
|
|
142
|
+
├── 🔧 .stylelintignore
|
|
143
|
+
│
|
|
144
|
+
├── 📂 .github/
|
|
145
|
+
│ ├── ISSUE_TEMPLATE/
|
|
146
|
+
│ │ ├── bug_report.yml
|
|
147
|
+
│ │ ├── config.yml
|
|
148
|
+
│ │ └── feature_request.yml
|
|
149
|
+
│ ├── PULL_REQUEST_TEMPLATE.md
|
|
150
|
+
│ └── workflows/
|
|
151
|
+
│ ├── lint.yml ← ESLint + Stylelint CI
|
|
152
|
+
│ ├── phpcs.yml ← PHP CodeSniffer CI
|
|
153
|
+
│ └── phpunit.yml ← PHPUnit CI (PHP 8.1–8.4 matrix)
|
|
154
|
+
│
|
|
155
|
+
├── 📂 includes/ ← PHP classes (PSR-4 autoloaded)
|
|
156
|
+
│ ├── Admin/
|
|
157
|
+
│ │ └── Menu.php ← Admin menu registration
|
|
158
|
+
│ ├── Traits/
|
|
159
|
+
│ │ └── Singleton.php
|
|
160
|
+
│ ├── Assets.php ← Enqueue scripts/styles
|
|
161
|
+
│ ├── Blocks.php ← Block registration (block/both)
|
|
162
|
+
│ └── Plugin.php ← Core bootstrap
|
|
163
|
+
│
|
|
164
|
+
├── 📂 src/
|
|
165
|
+
│ ├── block/ ← Gutenberg block (block/both)
|
|
166
|
+
│ │ ├── block.json
|
|
167
|
+
│ │ ├── edit.js
|
|
168
|
+
│ │ ├── index.js
|
|
169
|
+
│ │ ├── render.php
|
|
170
|
+
│ │ ├── view.js
|
|
171
|
+
│ │ └── style.scss
|
|
172
|
+
│ └── global/ ← Admin assets (admin/both)
|
|
173
|
+
│ ├── js/admin.js
|
|
174
|
+
│ └── css/admin.scss
|
|
175
|
+
│
|
|
176
|
+
├── 📂 tests/
|
|
177
|
+
│ ├── bootstrap.php
|
|
178
|
+
│ └── Unit/
|
|
179
|
+
│ ├── AbstractTestCase.php
|
|
180
|
+
│ ├── AssetsTest.php
|
|
181
|
+
│ └── MenuTest.php
|
|
182
|
+
│
|
|
183
|
+
└── 📂 languages/
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## ⚙️ Generated Plugin Commands
|
|
189
|
+
|
|
190
|
+
Once inside your scaffolded plugin directory:
|
|
191
|
+
|
|
192
|
+
### Setup
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
composer install # Install PHP dependencies (PHPCS, PHPUnit)
|
|
196
|
+
npm install # Install JS dependencies (@wordpress/scripts)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Development
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
npm run build # Production build
|
|
203
|
+
npm run start # Watch mode (blocks)
|
|
204
|
+
npm run start:custom # Watch mode (admin assets)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Linting & Formatting
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
npm run lint:js # ESLint
|
|
211
|
+
npm run lint:css # Stylelint
|
|
212
|
+
npm run lint:php # PHP CodeSniffer
|
|
213
|
+
npm run fix:js # Auto-fix JS
|
|
214
|
+
npm run fix:css # Auto-fix CSS
|
|
215
|
+
npm run fix:php # Auto-fix PHP
|
|
216
|
+
npm run format # wp-scripts format
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Testing
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
npm run test:php # Run PHPUnit tests
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Internationalization
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
npm run makepot # Generate .pot translation file
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Release
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
npm run zip # Build + create installable .zip with production Composer autoload
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## 🏗️ PHP Architecture
|
|
240
|
+
|
|
241
|
+
Generated plugins follow **PSR-4 autoloading** with a clean namespace structure:
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
YourVendor\YourPlugin\ → includes/
|
|
245
|
+
YourVendor\YourPlugin\Admin\ → includes/Admin/
|
|
246
|
+
YourVendor\YourPlugin\Traits\ → includes/Traits/
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Service classes use the **Singleton trait** for consistent instantiation:
|
|
250
|
+
|
|
251
|
+
```php
|
|
252
|
+
use YourVendor\YourPlugin\Traits\Singleton;
|
|
253
|
+
|
|
254
|
+
class Assets {
|
|
255
|
+
use Singleton;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Bootstrap helper in the main plugin file.
|
|
259
|
+
my_plugin()->run();
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## 🔄 CI / CD Out of the Box
|
|
265
|
+
|
|
266
|
+
Your plugin ships with **three GitHub Actions workflows**:
|
|
267
|
+
|
|
268
|
+
| Workflow | Trigger | What it checks |
|
|
269
|
+
|----------|---------|---------------|
|
|
270
|
+
| `lint.yml` | Push / PR | ESLint + Stylelint |
|
|
271
|
+
| `phpcs.yml` | Push / PR | PHP CodeSniffer (WordPress coding standards) |
|
|
272
|
+
| `phpunit.yml` | Push / PR | PHPUnit on PHP 8.1, 8.2, 8.3, 8.4 matrix |
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## 📋 Requirements
|
|
277
|
+
|
|
278
|
+
| Tool | Version | Purpose |
|
|
279
|
+
|------|---------|---------|
|
|
280
|
+
| **Node.js** | ≥ 20.0.0 | Run wpscaffold |
|
|
281
|
+
| **PHP** | ≥ 8.1 | Plugin development |
|
|
282
|
+
| **Composer** | ≥ 2.0 | PHP dependency management |
|
|
283
|
+
| **WordPress** | ≥ 6.4 | Target environment |
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## 🔑 How It Works
|
|
288
|
+
|
|
289
|
+
1. **Collects prompts** — plugin name, slug, namespace, type, author info
|
|
290
|
+
2. **Builds replacements** — maps placeholder strings (`plugin-skeleton`, `PluginSkeleton`, `sabbir1991`) to your values
|
|
291
|
+
3. **Copies template/** recursively — applies type markers and text replacements to every text file
|
|
292
|
+
4. **Removes unused code** — strips block or admin sections based on chosen type
|
|
293
|
+
5. **Renames entry file** — `plugin-skeleton.php` → `{your-slug}.php`
|
|
294
|
+
6. **Writes package.json** — dynamically built with the correct scripts and dependencies for your plugin type
|
|
295
|
+
|
|
296
|
+
### Type Markers
|
|
297
|
+
|
|
298
|
+
Template files use marker comments to gate type-specific code:
|
|
299
|
+
|
|
300
|
+
```php
|
|
301
|
+
/* @skeleton-admin */
|
|
302
|
+
// This code only appears in admin and both types
|
|
303
|
+
/* @skeleton-admin-end */
|
|
304
|
+
|
|
305
|
+
/* @skeleton-block */
|
|
306
|
+
// This code only appears in block and both types
|
|
307
|
+
/* @skeleton-block-end */
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## 🤝 Contributing
|
|
313
|
+
|
|
314
|
+
1. Fork the repo
|
|
315
|
+
2. Create your branch: `git checkout -b feature/my-feature`
|
|
316
|
+
3. Make changes in `lib/generator.js` or `template/`
|
|
317
|
+
4. Test locally: `npm link && wpscaffold create "Test Plugin"`
|
|
318
|
+
5. Submit a pull request
|
|
319
|
+
|
|
320
|
+
> When adding new PHP classes to `template/includes/`, mirror the pattern in `buildReplacements()`. The placeholder namespace is `PluginVendor\PluginSkeleton` and the slug placeholder is `plugin-skeleton`.
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## 📄 License
|
|
325
|
+
|
|
326
|
+
[MIT](LICENSE) © [sabbir1991](https://github.com/sabbir1991)
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const { generate } = require( '../lib/generator' );
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice( 2 );
|
|
8
|
+
const command = args[ 0 ];
|
|
9
|
+
const name = args.slice( 1 ).join( ' ' ).trim();
|
|
10
|
+
|
|
11
|
+
if ( command === 'create' ) {
|
|
12
|
+
generate( name ).catch( ( err ) => {
|
|
13
|
+
console.error( '\n Error:', err.message );
|
|
14
|
+
process.exit( 1 );
|
|
15
|
+
} );
|
|
16
|
+
} else {
|
|
17
|
+
console.error( '\n Usage: wpscaffold create "Plugin Name"\n' );
|
|
18
|
+
process.exit( 1 );
|
|
19
|
+
}
|