@pugpigjs/create-wp-project 0.0.2-beta.0 → 0.0.2-beta.2
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/CHANGELOG.md +12 -0
- package/README.md +75 -64
- package/package.json +1 -1
- package/src/cli.js +12 -6
- package/src/commands/add.js +1 -1
- package/src/commands/init.js +1 -1
- package/src/commands/update.js +1 -1
- package/src/utils/shared.js +18 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @pugpigjs/create-wp-project
|
|
2
2
|
|
|
3
|
+
## 0.0.2-beta.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3809018: Add environment variable support (PUGPIG_WORDPRESS_TEMPLATE_REPO_URL) and shorthand CLI flags (-g, -d, -t, -b) for improved developer experience.
|
|
8
|
+
|
|
9
|
+
## 0.0.2-beta.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 13f211a: Add --branch option and shorthand flags (-g, -d, -t, -b) to CLI for easier command usage.
|
|
14
|
+
|
|
3
15
|
## 0.0.2-beta.0
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ CLI tool to scaffold WordPress plugins and themes from a template repo.
|
|
|
7
7
|
The easiest way to scaffold a new WordPress project:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
|
|
10
|
+
npm create @pugpigjs/wp-project -- init --git-url <repository-url> --directory <target-directory>
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
**Note:** Both `--git-url` and `--directory` are required for all commands.
|
|
@@ -24,20 +24,25 @@ This CLI tool uses a **placeholder-based templating system** to scaffold WordPre
|
|
|
24
24
|
|
|
25
25
|
### Template Placeholders
|
|
26
26
|
|
|
27
|
-
The template uses **case-insensitive** placeholder markers throughout all files. You can use either uppercase (`TPL_*`) or lowercase (`tpl_*`) variants
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
The template uses **case-insensitive** placeholder markers throughout all files. You can use either uppercase (`TPL_*`) or lowercase (`tpl_*`) variants. For JSON files or schemas that require lowercase keys, simply use the lowercase form.
|
|
28
|
+
|
|
29
|
+
| Placeholder | Example Value | Description |
|
|
30
|
+
|----------------------------------|-------------------------------|--------------------------------------------------------------------|
|
|
31
|
+
| `TPL_NAMESPACE` | `Pugpig` | Namespace in PascalCase |
|
|
32
|
+
| `TPL_NAMESPACE_LOWER` | `pugpig` | Lowercase namespace |
|
|
33
|
+
| `TPL_PROJECT_NAME` | `my_plugin` | Project name in snake_case |
|
|
34
|
+
| `TPL_PROJECT_NAME_PASCAL` | `MyPlugin` | Project name in PascalCase |
|
|
35
|
+
| `TPL_PROJECT_NAME_SLUG` | `my-plugin` | Project name in kebab-case (for NPM/URLs) |
|
|
36
|
+
| `TPL_PROJECT_NAME_FLAT` | `myplugin` | Project name with no separators |
|
|
37
|
+
| `TPL_FULL_PROJECT_NAME` | `pugpig_my_plugin` | Full project name with namespace (snake_case) |
|
|
38
|
+
| `TPL_FULL_PROJECT_NAME_SLUG` | `pugpig-my-plugin` | Full project name in kebab-case |
|
|
39
|
+
| `TPL_FULL_PROJECT_NAME_TITLE` | `Pugpig My Plugin` | Full project name in Title Case |
|
|
40
|
+
| `TPL_FULL_PROJECT_NAME_UPPER` | `PUGPIG MY PLUGIN` | Full project name in UPPERCASE |
|
|
41
|
+
| `TPL_DESCRIPTION` | `A human-readable description`| Human-readable description |
|
|
42
|
+
| `pkg_*` (wildcard) | `pkg_example_theme` → `pugpig-my-theme` | Any package name starting with `pkg_` gets replaced with the full project name slug |
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
_Use lowercase keys for compatibility with JSON schemas or config files that require them._
|
|
41
46
|
|
|
42
47
|
**Usage Examples:**
|
|
43
48
|
```php
|
|
@@ -58,7 +63,7 @@ The CLI automatically computes all these variations from your namespace and proj
|
|
|
58
63
|
### `init` - Initialise a New Project
|
|
59
64
|
|
|
60
65
|
```bash
|
|
61
|
-
|
|
66
|
+
npm create @pugpigjs/wp-project -- init --git-url <repository-url> --directory <target-directory>
|
|
62
67
|
```
|
|
63
68
|
|
|
64
69
|
This interactive CLI will:
|
|
@@ -75,7 +80,7 @@ This interactive CLI will:
|
|
|
75
80
|
If you've already initialised a project and want to add another plugin or theme:
|
|
76
81
|
|
|
77
82
|
```bash
|
|
78
|
-
|
|
83
|
+
npm create @pugpigjs/wp-project -- add --git-url <repository-url> --directory <target-directory>
|
|
79
84
|
```
|
|
80
85
|
|
|
81
86
|
This will:
|
|
@@ -91,7 +96,7 @@ This will:
|
|
|
91
96
|
To remove a plugin or theme from your project:
|
|
92
97
|
|
|
93
98
|
```bash
|
|
94
|
-
|
|
99
|
+
npm create @pugpigjs/wp-project -- remove --directory <target-directory>
|
|
95
100
|
```
|
|
96
101
|
|
|
97
102
|
This will:
|
|
@@ -107,7 +112,7 @@ This will:
|
|
|
107
112
|
To refresh configuration files (like bitbucket-pipelines.yml, renovate.json, etc.) from the latest template:
|
|
108
113
|
|
|
109
114
|
```bash
|
|
110
|
-
|
|
115
|
+
npm create @pugpigjs/wp-project -- update --git-url <repository-url> --directory <target-directory>
|
|
111
116
|
```
|
|
112
117
|
|
|
113
118
|
This will:
|
|
@@ -127,48 +132,72 @@ This is useful when:
|
|
|
127
132
|
|
|
128
133
|
All commands (`init`, `add`, and `update`) require:
|
|
129
134
|
|
|
130
|
-
-
|
|
135
|
+
- `-g, --git-url <url>` - Git repository URL or local path to the template
|
|
136
|
+
- **Can be set via environment variable** `PUGPIG_WORDPRESS_TEMPLATE_REPO_URL` to avoid passing it every time
|
|
131
137
|
- Example: `https://github.com/user/wp-template.git`
|
|
132
138
|
- Example: `/path/to/local/template`
|
|
133
139
|
- Example: `.` (current directory for local development)
|
|
134
140
|
|
|
135
|
-
-
|
|
141
|
+
- `-d, --directory <path>` - **(Required)** Target/project directory
|
|
136
142
|
- **Must end with `-server`** for safety (e.g., `my-project-server`)
|
|
137
143
|
- Example: `./my-project-server`
|
|
138
144
|
- Example: `/absolute/path/to/project-server`
|
|
139
145
|
|
|
140
146
|
Optional:
|
|
141
147
|
|
|
142
|
-
-
|
|
148
|
+
- `-t, --template-dir <path>` - Template source directory within the repository (defaults to `repo_template`)
|
|
149
|
+
- `-b, --branch <name>` - Git branch to clone from (defaults to `master`)
|
|
150
|
+
|
|
151
|
+
### Environment Variables
|
|
152
|
+
|
|
153
|
+
You can set the following environment variable to simplify usage:
|
|
154
|
+
|
|
155
|
+
- `PUGPIG_WORDPRESS_TEMPLATE_REPO_URL` - Default git repository URL
|
|
156
|
+
- When set, the `-g, --git-url` flag becomes optional
|
|
157
|
+
- Add to your shell config (`~/.zshrc` or `~/.bashrc`):
|
|
158
|
+
```bash
|
|
159
|
+
export PUGPIG_WORDPRESS_TEMPLATE_REPO_URL=https://github.com/your-org/your-wp-template.git
|
|
160
|
+
```
|
|
161
|
+
- After setting, you can omit the `-g` flag:
|
|
162
|
+
```bash
|
|
163
|
+
npm create @pugpigjs/wp-project -- init -d ./my-project-server
|
|
164
|
+
```
|
|
165
|
+
|
|
143
166
|
|
|
144
167
|
## Examples
|
|
145
168
|
|
|
146
169
|
### Initialise from a remote repository
|
|
147
170
|
```bash
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
171
|
+
npm create @pugpigjs/wp-project -- init \
|
|
172
|
+
-g https://github.com/your-org/your-wp-template.git \
|
|
173
|
+
-d ./my-project-server
|
|
151
174
|
```
|
|
152
175
|
|
|
153
176
|
### Initialise from a local template (for development)
|
|
154
177
|
```bash
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
178
|
+
npm create @pugpigjs/wp-project -- init -g . -d ./test-server
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Initialise from a specific branch
|
|
182
|
+
```bash
|
|
183
|
+
npm create @pugpigjs/wp-project -- init \
|
|
184
|
+
-g https://github.com/your-org/your-wp-template.git \
|
|
185
|
+
-d ./my-project-server \
|
|
186
|
+
-b beta
|
|
158
187
|
```
|
|
159
188
|
|
|
160
189
|
### Add another template to existing project
|
|
161
190
|
```bash
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
191
|
+
npm create @pugpigjs/wp-project -- add \
|
|
192
|
+
-g https://github.com/your-org/your-wp-template.git \
|
|
193
|
+
-d ./my-project-server
|
|
165
194
|
```
|
|
166
195
|
|
|
167
196
|
### Update configuration files
|
|
168
197
|
```bash
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
198
|
+
npm create @pugpigjs/wp-project -- update \
|
|
199
|
+
-g https://github.com/your-org/your-wp-template.git \
|
|
200
|
+
-d ./my-project-server
|
|
172
201
|
```
|
|
173
202
|
|
|
174
203
|
## Safety Features
|
|
@@ -184,31 +213,16 @@ This CLI tool includes multiple safety checks to prevent accidental data loss:
|
|
|
184
213
|
|
|
185
214
|
## Requirements
|
|
186
215
|
|
|
187
|
-
- Node.js
|
|
216
|
+
- Node.js 24 or higher
|
|
188
217
|
- A directory ending with `-server` (e.g., `my-project-server`)
|
|
189
218
|
|
|
190
219
|
## Template Types
|
|
191
220
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
-
|
|
197
|
-
- Composer dependencies with PHP-Scoper
|
|
198
|
-
- WordPress integration utilities
|
|
199
|
-
|
|
200
|
-
### Simple Plugin
|
|
201
|
-
Lightweight plugin with basic JavaScript and CSS. Includes:
|
|
202
|
-
- Simple Vite build setup
|
|
203
|
-
- Vanilla JavaScript
|
|
204
|
-
- Basic CSS
|
|
205
|
-
- Minimal dependencies
|
|
206
|
-
|
|
207
|
-
### Theme
|
|
208
|
-
WordPress theme with modern build tooling. Includes:
|
|
209
|
-
- Vite build system
|
|
210
|
-
- Modern CSS/JS compilation
|
|
211
|
-
- Theme template structure
|
|
221
|
+
* `Rich Plugin`: A full-featured plugin template with Vue.js, SCSS, and an advanced build setup. Includes Vite build system with hot module replacement (HMR), Vue.js component support, SCSS preprocessing, Composer dependencies managed with PHP-Scoper, and utilities for seamless WordPress integration.
|
|
222
|
+
|
|
223
|
+
* `Simple Plugin`: A lightweight plugin template with a simple Vite build setup, vanilla JavaScript, basic CSS, and minimal dependencies.
|
|
224
|
+
|
|
225
|
+
* `Theme`: A WordPress theme template with a modern Vite-based build system, supporting modern CSS/JS compilation and a standard theme template structure.
|
|
212
226
|
|
|
213
227
|
## Development
|
|
214
228
|
|
|
@@ -216,19 +230,16 @@ For local development and testing from within this repository:
|
|
|
216
230
|
|
|
217
231
|
```bash
|
|
218
232
|
# From the repository root
|
|
219
|
-
node packages/create-wp-project/src/cli.js init
|
|
220
|
-
--git-url . \
|
|
221
|
-
--directory ./test-server
|
|
233
|
+
node packages/create-wp-project/src/cli.js init -g . -d ./test-server
|
|
222
234
|
|
|
223
235
|
# Or test the add command
|
|
224
|
-
node packages/create-wp-project/src/cli.js add
|
|
225
|
-
--git-url . \
|
|
226
|
-
--directory ./test-server
|
|
236
|
+
node packages/create-wp-project/src/cli.js add -g . -d ./test-server
|
|
227
237
|
|
|
228
238
|
# Or test the update command
|
|
229
|
-
node packages/create-wp-project/src/cli.js update
|
|
230
|
-
|
|
231
|
-
|
|
239
|
+
node packages/create-wp-project/src/cli.js update -g . -d ./test-server
|
|
240
|
+
|
|
241
|
+
# Test with a specific branch
|
|
242
|
+
node packages/create-wp-project/src/cli.js init -g . -d ./test-server -b beta
|
|
232
243
|
```
|
|
233
244
|
|
|
234
245
|
## License
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -8,6 +8,9 @@ import { updateProject } from './commands/update.js'
|
|
|
8
8
|
|
|
9
9
|
const program = new Command()
|
|
10
10
|
|
|
11
|
+
// Get default git URL from environment variable if set
|
|
12
|
+
const defaultGitUrl = process.env.PUGPIG_WORDPRESS_TEMPLATE_REPO_URL
|
|
13
|
+
|
|
11
14
|
program
|
|
12
15
|
.name('create-wp-project')
|
|
13
16
|
.description('CLI tool to scaffold WordPress plugins and themes from a template repo.')
|
|
@@ -17,16 +20,18 @@ program
|
|
|
17
20
|
.command('init')
|
|
18
21
|
.description('Initialise a new WordPress project from the template')
|
|
19
22
|
.requiredOption('-d, --directory <path>', 'Target directory (must end with -server)')
|
|
20
|
-
.
|
|
21
|
-
.option('--template-dir <path>', 'Template source directory', 'repo_template')
|
|
23
|
+
.option('-g, --git-url <url>', 'Git repository URL or local path to template', defaultGitUrl)
|
|
24
|
+
.option('-t, --template-dir <path>', 'Template source directory', 'repo_template')
|
|
25
|
+
.option('-b, --branch <name>', 'Git branch to clone from', 'master')
|
|
22
26
|
.action(initProject)
|
|
23
27
|
|
|
24
28
|
program
|
|
25
29
|
.command('add')
|
|
26
30
|
.description('Add another plugin or theme to an existing project')
|
|
27
31
|
.requiredOption('-d, --directory <path>', 'Project directory (must end with -server)')
|
|
28
|
-
.
|
|
29
|
-
.option('--template-dir <path>', 'Template source directory', 'repo_template')
|
|
32
|
+
.option('-g, --git-url <url>', 'Git repository URL or local path to template', defaultGitUrl)
|
|
33
|
+
.option('-t, --template-dir <path>', 'Template source directory', 'repo_template')
|
|
34
|
+
.option('-b, --branch <name>', 'Git branch to clone from', 'master')
|
|
30
35
|
.action(addTemplate)
|
|
31
36
|
|
|
32
37
|
program
|
|
@@ -39,8 +44,9 @@ program
|
|
|
39
44
|
.command('update')
|
|
40
45
|
.description('Update root configuration files from the template')
|
|
41
46
|
.requiredOption('-d, --directory <path>', 'Project directory (must end with -server)')
|
|
42
|
-
.
|
|
43
|
-
.option('--template-dir <path>', 'Template source directory', 'repo_template')
|
|
47
|
+
.option('-g, --git-url <url>', 'Git repository URL or local path to template', defaultGitUrl)
|
|
48
|
+
.option('-t, --template-dir <path>', 'Template source directory', 'repo_template')
|
|
49
|
+
.option('-b, --branch <name>', 'Git branch to clone from', 'master')
|
|
44
50
|
.action(updateProject)
|
|
45
51
|
|
|
46
52
|
program.parse()
|
package/src/commands/add.js
CHANGED
|
@@ -108,7 +108,7 @@ export async function addTemplate(options) {
|
|
|
108
108
|
|
|
109
109
|
try {
|
|
110
110
|
// Step 1: Clone repository
|
|
111
|
-
await cloneRepo(options.gitUrl, tempDir)
|
|
111
|
+
await cloneRepo(options.gitUrl, tempDir, options.branch)
|
|
112
112
|
|
|
113
113
|
// Step 2: Copy selected template
|
|
114
114
|
const spinner = ora(`Copying ${TEMPLATES[template].name} template...`).start()
|
package/src/commands/init.js
CHANGED
|
@@ -136,7 +136,7 @@ export async function initProject(options) {
|
|
|
136
136
|
|
|
137
137
|
try {
|
|
138
138
|
// Step 1: Clone repository
|
|
139
|
-
await cloneRepo(options.gitUrl, tempDir)
|
|
139
|
+
await cloneRepo(options.gitUrl, tempDir, options.branch)
|
|
140
140
|
|
|
141
141
|
// Step 2: Copy root files from repo_template directory
|
|
142
142
|
const templateRoot = path.join(tempDir, options.templateDir)
|
package/src/commands/update.js
CHANGED
|
@@ -146,7 +146,7 @@ export async function updateProject(options) {
|
|
|
146
146
|
|
|
147
147
|
try {
|
|
148
148
|
// Clone repository to get latest templates
|
|
149
|
-
await cloneRepo(options.gitUrl, tempDir)
|
|
149
|
+
await cloneRepo(options.gitUrl, tempDir, options.branch)
|
|
150
150
|
|
|
151
151
|
const templateRoot = path.join(tempDir, options.templateDir)
|
|
152
152
|
|
package/src/utils/shared.js
CHANGED
|
@@ -116,8 +116,16 @@ export const prompts = {
|
|
|
116
116
|
* Clone the git repository to a temporary directory, or copy from local path
|
|
117
117
|
* @param {string} gitUrlOrPath - Git URL or local filesystem path
|
|
118
118
|
* @param {string} tempDir - Temporary directory to clone/copy into
|
|
119
|
+
* @param {string} branch - Git branch to clone (optional, defaults to remote's default branch)
|
|
119
120
|
*/
|
|
120
|
-
export async function cloneRepo(gitUrlOrPath, tempDir) {
|
|
121
|
+
export async function cloneRepo(gitUrlOrPath, tempDir, branch = null) {
|
|
122
|
+
// Validate git URL is provided
|
|
123
|
+
if (!gitUrlOrPath) {
|
|
124
|
+
console.error(chalk.red('\n❌ Error: --git-url is required'))
|
|
125
|
+
console.error(chalk.yellow('Set PUGPIG_WORDPRESS_TEMPLATE_REPO_URL environment variable or provide --git-url flag'))
|
|
126
|
+
process.exit(1)
|
|
127
|
+
}
|
|
128
|
+
|
|
121
129
|
// Check if it's a local path
|
|
122
130
|
const isLocalPath = !gitUrlOrPath.startsWith('http://') &&
|
|
123
131
|
!gitUrlOrPath.startsWith('https://') &&
|
|
@@ -136,11 +144,16 @@ export async function cloneRepo(gitUrlOrPath, tempDir) {
|
|
|
136
144
|
throw error
|
|
137
145
|
}
|
|
138
146
|
} else {
|
|
139
|
-
const
|
|
147
|
+
const branchMsg = branch ? ` (branch: ${branch})` : ''
|
|
148
|
+
const spinner = ora(`Cloning template repository${branchMsg}...`).start()
|
|
140
149
|
try {
|
|
141
150
|
const git = simpleGit()
|
|
142
|
-
|
|
143
|
-
|
|
151
|
+
const cloneOptions = ['--depth', '1']
|
|
152
|
+
if (branch) {
|
|
153
|
+
cloneOptions.push('--branch', branch)
|
|
154
|
+
}
|
|
155
|
+
await git.clone(gitUrlOrPath, tempDir, cloneOptions)
|
|
156
|
+
spinner.succeed(`Template repository cloned${branchMsg}`)
|
|
144
157
|
} catch (error) {
|
|
145
158
|
spinner.fail('Failed to clone repository')
|
|
146
159
|
throw error
|
|
@@ -328,7 +341,7 @@ export async function cleanup(tempDir) {
|
|
|
328
341
|
}
|
|
329
342
|
|
|
330
343
|
/**
|
|
331
|
-
* Display next steps after project
|
|
344
|
+
* Display next steps after project initialisation or template addition
|
|
332
345
|
* @param {string} targetDir - The target directory where files were created
|
|
333
346
|
* @param {string} projectName - The project name
|
|
334
347
|
* @param {string} templateType - The template type key
|