@pugpigjs/create-wp-project 0.0.2-beta.0 → 0.0.2-beta.1
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 +6 -0
- package/README.md +25 -20
- package/package.json +1 -1
- package/src/cli.js +9 -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 +11 -5
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -127,48 +127,56 @@ This is useful when:
|
|
|
127
127
|
|
|
128
128
|
All commands (`init`, `add`, and `update`) require:
|
|
129
129
|
|
|
130
|
-
-
|
|
130
|
+
- `-g, --git-url <url>` - **(Required)** Git repository URL or local path to the template
|
|
131
131
|
- Example: `https://github.com/user/wp-template.git`
|
|
132
132
|
- Example: `/path/to/local/template`
|
|
133
133
|
- Example: `.` (current directory for local development)
|
|
134
134
|
|
|
135
|
-
-
|
|
135
|
+
- `-d, --directory <path>` - **(Required)** Target/project directory
|
|
136
136
|
- **Must end with `-server`** for safety (e.g., `my-project-server`)
|
|
137
137
|
- Example: `./my-project-server`
|
|
138
138
|
- Example: `/absolute/path/to/project-server`
|
|
139
139
|
|
|
140
140
|
Optional:
|
|
141
141
|
|
|
142
|
-
-
|
|
142
|
+
- `-t, --template-dir <path>` - Template source directory within the repository (defaults to `repo_template`)
|
|
143
|
+
- `-b, --branch <name>` - Git branch to clone from (defaults to `master`)
|
|
144
|
+
|
|
143
145
|
|
|
144
146
|
## Examples
|
|
145
147
|
|
|
146
148
|
### Initialise from a remote repository
|
|
147
149
|
```bash
|
|
148
150
|
npx @pugpigjs/create-wp-project init \
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
-g https://github.com/your-org/your-wp-template.git \
|
|
152
|
+
-d ./my-project-server
|
|
151
153
|
```
|
|
152
154
|
|
|
153
155
|
### Initialise from a local template (for development)
|
|
154
156
|
```bash
|
|
157
|
+
npx @pugpigjs/create-wp-project init -g . -d ./test-server
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Initialise from a specific branch
|
|
161
|
+
```bash
|
|
155
162
|
npx @pugpigjs/create-wp-project init \
|
|
156
|
-
|
|
157
|
-
|
|
163
|
+
-g https://github.com/your-org/your-wp-template.git \
|
|
164
|
+
-d ./my-project-server \
|
|
165
|
+
-b beta
|
|
158
166
|
```
|
|
159
167
|
|
|
160
168
|
### Add another template to existing project
|
|
161
169
|
```bash
|
|
162
170
|
npx @pugpigjs/create-wp-project add \
|
|
163
|
-
|
|
164
|
-
|
|
171
|
+
-g https://github.com/your-org/your-wp-template.git \
|
|
172
|
+
-d ./my-project-server
|
|
165
173
|
```
|
|
166
174
|
|
|
167
175
|
### Update configuration files
|
|
168
176
|
```bash
|
|
169
177
|
npx @pugpigjs/create-wp-project update \
|
|
170
|
-
|
|
171
|
-
|
|
178
|
+
-g https://github.com/your-org/your-wp-template.git \
|
|
179
|
+
-d ./my-project-server
|
|
172
180
|
```
|
|
173
181
|
|
|
174
182
|
## Safety Features
|
|
@@ -216,19 +224,16 @@ For local development and testing from within this repository:
|
|
|
216
224
|
|
|
217
225
|
```bash
|
|
218
226
|
# From the repository root
|
|
219
|
-
node packages/create-wp-project/src/cli.js init
|
|
220
|
-
--git-url . \
|
|
221
|
-
--directory ./test-server
|
|
227
|
+
node packages/create-wp-project/src/cli.js init -g . -d ./test-server
|
|
222
228
|
|
|
223
229
|
# Or test the add command
|
|
224
|
-
node packages/create-wp-project/src/cli.js add
|
|
225
|
-
--git-url . \
|
|
226
|
-
--directory ./test-server
|
|
230
|
+
node packages/create-wp-project/src/cli.js add -g . -d ./test-server
|
|
227
231
|
|
|
228
232
|
# Or test the update command
|
|
229
|
-
node packages/create-wp-project/src/cli.js update
|
|
230
|
-
|
|
231
|
-
|
|
233
|
+
node packages/create-wp-project/src/cli.js update -g . -d ./test-server
|
|
234
|
+
|
|
235
|
+
# Test with a specific branch
|
|
236
|
+
node packages/create-wp-project/src/cli.js init -g . -d ./test-server -b beta
|
|
232
237
|
```
|
|
233
238
|
|
|
234
239
|
## License
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -17,16 +17,18 @@ program
|
|
|
17
17
|
.command('init')
|
|
18
18
|
.description('Initialise a new WordPress project from the template')
|
|
19
19
|
.requiredOption('-d, --directory <path>', 'Target directory (must end with -server)')
|
|
20
|
-
.requiredOption('--git-url <url>', 'Git repository URL or local path to template')
|
|
21
|
-
.option('--template-dir <path>', 'Template source directory', 'repo_template')
|
|
20
|
+
.requiredOption('-g, --git-url <url>', 'Git repository URL or local path to template')
|
|
21
|
+
.option('-t, --template-dir <path>', 'Template source directory', 'repo_template')
|
|
22
|
+
.option('-b, --branch <name>', 'Git branch to clone from', 'master')
|
|
22
23
|
.action(initProject)
|
|
23
24
|
|
|
24
25
|
program
|
|
25
26
|
.command('add')
|
|
26
27
|
.description('Add another plugin or theme to an existing project')
|
|
27
28
|
.requiredOption('-d, --directory <path>', 'Project directory (must end with -server)')
|
|
28
|
-
.requiredOption('--git-url <url>', 'Git repository URL or local path to template')
|
|
29
|
-
.option('--template-dir <path>', 'Template source directory', 'repo_template')
|
|
29
|
+
.requiredOption('-g, --git-url <url>', 'Git repository URL or local path to template')
|
|
30
|
+
.option('-t, --template-dir <path>', 'Template source directory', 'repo_template')
|
|
31
|
+
.option('-b, --branch <name>', 'Git branch to clone from', 'master')
|
|
30
32
|
.action(addTemplate)
|
|
31
33
|
|
|
32
34
|
program
|
|
@@ -39,8 +41,9 @@ program
|
|
|
39
41
|
.command('update')
|
|
40
42
|
.description('Update root configuration files from the template')
|
|
41
43
|
.requiredOption('-d, --directory <path>', 'Project directory (must end with -server)')
|
|
42
|
-
.requiredOption('--git-url <url>', 'Git repository URL or local path to template')
|
|
43
|
-
.option('--template-dir <path>', 'Template source directory', 'repo_template')
|
|
44
|
+
.requiredOption('-g, --git-url <url>', 'Git repository URL or local path to template')
|
|
45
|
+
.option('-t, --template-dir <path>', 'Template source directory', 'repo_template')
|
|
46
|
+
.option('-b, --branch <name>', 'Git branch to clone from', 'master')
|
|
44
47
|
.action(updateProject)
|
|
45
48
|
|
|
46
49
|
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,9 @@ 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) {
|
|
121
122
|
// Check if it's a local path
|
|
122
123
|
const isLocalPath = !gitUrlOrPath.startsWith('http://') &&
|
|
123
124
|
!gitUrlOrPath.startsWith('https://') &&
|
|
@@ -136,11 +137,16 @@ export async function cloneRepo(gitUrlOrPath, tempDir) {
|
|
|
136
137
|
throw error
|
|
137
138
|
}
|
|
138
139
|
} else {
|
|
139
|
-
const
|
|
140
|
+
const branchMsg = branch ? ` (branch: ${branch})` : ''
|
|
141
|
+
const spinner = ora(`Cloning template repository${branchMsg}...`).start()
|
|
140
142
|
try {
|
|
141
143
|
const git = simpleGit()
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
const cloneOptions = ['--depth', '1']
|
|
145
|
+
if (branch) {
|
|
146
|
+
cloneOptions.push('--branch', branch)
|
|
147
|
+
}
|
|
148
|
+
await git.clone(gitUrlOrPath, tempDir, cloneOptions)
|
|
149
|
+
spinner.succeed(`Template repository cloned${branchMsg}`)
|
|
144
150
|
} catch (error) {
|
|
145
151
|
spinner.fail('Failed to clone repository')
|
|
146
152
|
throw error
|
|
@@ -328,7 +334,7 @@ export async function cleanup(tempDir) {
|
|
|
328
334
|
}
|
|
329
335
|
|
|
330
336
|
/**
|
|
331
|
-
* Display next steps after project
|
|
337
|
+
* Display next steps after project initialisation or template addition
|
|
332
338
|
* @param {string} targetDir - The target directory where files were created
|
|
333
339
|
* @param {string} projectName - The project name
|
|
334
340
|
* @param {string} templateType - The template type key
|