wp-blank-scripts 3.1.19 → 4.0.0-alpha.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/README.md CHANGED
@@ -1,130 +1,116 @@
1
1
  # WP Blank Scripts
2
2
 
3
- CLI and build tool for Wordpress projects.
3
+ CLI and build tool for WordPress projects at ViVO Digital.
4
4
 
5
- ## Upgrade to v3
5
+ ## Requirements
6
6
 
7
- Surprisingly there are no breaking changes.
8
-
9
- **v3 Warnings**
10
-
11
- #### Sass division outside of calc() deprecated
12
-
13
- Deprecation Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.
14
- Recommendation: math.div(-$grid-gutter, 2) or calc(-1 * $grid-gutter / 2). More info and automated migrator: https://sass-lang.com/d/slash-div
15
-
16
- Fix:
17
-
18
- ```
19
- npm install -g sass-migrator
20
- sass-migrator division **/*.scss
21
-
22
- ```
7
+ - Node `>=22`
8
+ - MAMP (optional — skipped automatically if not installed)
23
9
 
24
10
  ## Project Structure
25
11
 
12
+ ### New projects (v4+)
13
+
26
14
  ```
27
15
  /
28
- ├── config
16
+ ├── config/
29
17
  │ ├── .htaccess{-environment}
30
18
  │ ├── robots{-environment}.txt
31
19
  │ └── wp-config{-environment}.php
32
- ├── src
33
- │ ├── assets
34
- ├── admin
35
- ├── css
36
- ├── fonts
37
- │ ├── img
38
- │ │ └── js
39
- ├── functions.php
40
- │ ├── inc
41
- │ ├── screenshot.png
42
- │ ├── style.css
43
- │ └── templates
44
- ├── sql
45
- ├── tasks
20
+ ├── src/
21
+ │ ├── blocks/
22
+ │ ├── parts/
23
+ │ ├── index.js
24
+ │ ├── style.scss
25
+ └── ...theme files
26
+ ├── sql/
27
+ ├── tasks/
46
28
  │ └── overrides.js
47
- ├── vendor
48
- ├── wordpress
49
- └── wp-content
29
+ ├── vendor/
30
+ └── wp-content/
31
+ ```
32
+
33
+ ### Legacy projects (pre-v4)
34
+
35
+ ```
36
+ /
37
+ ├── src/
38
+ │ ├── assets/
39
+ │ │ ├── admin/
40
+ │ │ ├── css/
41
+ │ │ ├── fonts/
42
+ │ │ ├── images/
43
+ │ │ └── js/
44
+ │ └── ...theme files
45
+ └── ...
50
46
  ```
51
47
 
48
+ Both structures are auto-detected — no configuration required.
49
+
50
+ ---
51
+
52
52
  ## Usage
53
53
 
54
- Typically you'll use this in your npm scripts (or package scripts):
54
+ Add to your project's `package.json` scripts:
55
55
 
56
56
  ```json
57
57
  {
58
58
  "scripts": {
59
- "start": "wp-scripts dev",
60
- "build": "NODE_ENV=production wp-scripts build",
59
+ "dev": "wp-scripts dev",
60
+ "build": "wp-scripts build",
61
+ "build:staging": "wp-scripts build --environment=staging",
62
+ "build:production": "wp-scripts build --environment=production",
61
63
  "import": "wp-scripts import",
62
64
  "backup": "wp-scripts backup",
63
65
  "setup": "wp-scripts setup",
64
66
  "export": "wp-scripts export",
65
67
  "deploy": "wp-scripts deploy",
66
- "pull": "wp-scripts pull",
67
- "clone": "wp-scripts clone"
68
+ "pull": "wp-scripts pull"
68
69
  }
69
70
  }
70
71
  ```
71
72
 
72
- ### CLI
73
-
74
- #### `backup`
75
-
76
- Backup wp-content from dev project to local file system.
77
-
78
- #### `build`
79
-
80
- Build the project to the output directory
81
-
82
- **Env variables:**
83
-
84
- - `BUILD_ENV=local|staging|production` to set the build environment
85
-
86
- **Options:**
87
-
88
- **environment** `local|staging|production` (required)
73
+ ---
89
74
 
90
- The environment to deploy to, defaults to `process.env.BUILD_ENV`
75
+ ## CLI Commands
91
76
 
92
- #### `dev`
77
+ ### `dev`
93
78
 
94
- Run the project in dev mode with live reload server.
79
+ Run the project in dev mode with live reload.
95
80
 
96
81
  **Env variables:**
97
82
 
98
- - `PORT=3001` to change dev server port to 3001
99
- - `HTTPS=1` to enable https for the dev server
83
+ - `PORT=3001` change dev server port
84
+ - `HTTPS=1` enable HTTPS for the dev server
85
+ - `BYPASS_REACT=true` — force non-React mode even if `react` is in dependencies
100
86
 
101
- #### `deploy`
87
+ ---
102
88
 
103
- Build and deploy the project via SSH, with optional SQL.
89
+ ### `build`
104
90
 
105
- All environment information should be in `project/config/settings.json`.
91
+ Build the project to the output directory.
106
92
 
107
93
  **Options:**
108
94
 
109
- **environment** `staging|production` (required)
110
-
111
- The environment to deploy to.
112
-
113
- **mode** `Site|wp-content|Theme|Plugins|SQL only` (required)
95
+ - `--environment` `local|staging|production` — build environment (required)
114
96
 
115
- What should be deployed, `Site` is the entired build directory.
97
+ When building for `staging` or `production`, output goes to `dist-{environment}` so it doesn't overwrite your local dev build. The deploy command handles cleanup automatically.
116
98
 
117
- **sql** `boolean`
99
+ ---
118
100
 
119
- Should SQL be deployed, this is assumed true if mode is `SQL only`.
101
+ ### `deploy`
120
102
 
121
- **serverPassword** `string`
103
+ Build and deploy the project via rsync over SSH, with optional SQL deployment.
122
104
 
123
- The password for the configured user on the server. This is only required if `sql` is true and no `serverPrivateKey` is provided.
105
+ All environment info must be in `config/settings.json`.
124
106
 
125
- **serverPrivateKey** `string`
107
+ **Options:**
126
108
 
127
- Path to the private key for the configured user on the server. This is only required if `sql` is true and no `serverPassword` is provided.
109
+ - `--environment` `staging|production` (required)
110
+ - `--mode` `Site|wp-content|Theme|Plugins|SQL only` (required)
111
+ - `--sql` `boolean` — deploy SQL (assumed true if mode is `SQL only`)
112
+ - `--serverPassword` `string` — SSH password (if not using key)
113
+ - `--serverPrivateKey` `string` — path to SSH private key (defaults to `~/.ssh/id_rsa`)
128
114
 
129
115
  **Example:**
130
116
 
@@ -132,15 +118,15 @@ Path to the private key for the configured user on the server. This is only requ
132
118
  wp-scripts deploy --mode="wp-content" --environment="staging"
133
119
  ```
134
120
 
135
- #### `export`
121
+ ---
136
122
 
137
- Export the local SQL database to the `project/sql` directory.
123
+ ### `export`
138
124
 
139
- **Options:**
125
+ Export the local SQL database to the `sql/` directory.
140
126
 
141
- **environment** `local|staging|production` (required)
127
+ **Options:**
142
128
 
143
- The environment you are exporting for. If not `local` urls will be replaced to those found in the config file for that environment.
129
+ - `--environment` `local|staging|production` (required) if not `local`, URLs are replaced with those from the config for that environment
144
130
 
145
131
  **Example:**
146
132
 
@@ -148,59 +134,38 @@ The environment you are exporting for. If not `local` urls will be replaced to t
148
134
  wp-scripts export --environment="staging"
149
135
  ```
150
136
 
151
- #### `import`
137
+ ---
152
138
 
153
- Import a local SQl file to the local database.
139
+ ### `import`
154
140
 
155
- Will automatically create the database if it does not exist.
141
+ Import a SQL file into the local database. Creates the database if it doesn't exist.
156
142
 
157
143
  **Options:**
158
144
 
159
- **file** `path/to/file` (required)
160
-
161
- The path to the file to import.
162
-
163
- Pass `latest` instead of a file path to automatically import the most recent SQL file from the `./sql` directory.
145
+ - `--file` `path/to/file` (required) — pass `latest` to use the most recent file in `./sql`
146
+ - `--replace` `boolean` — replace URLs before importing (does not mutate the original file)
147
+ - `--environment` `local|dev|staging|production` environment to replace URLs **from**
148
+ - `--currentEnvironment` `local|dev|staging|production` — environment to replace URLs **to**
164
149
 
165
- **replace** `boolean`
166
-
167
- Should urls be replaced in the SQL before importing. This will not mutate the original file.
168
-
169
- **environment** `local|dev|staging|production`
170
-
171
- The environment you are replacing the urls **from**. This is only required if `replace` is true.
172
-
173
- **currentEnvironment** `local|dev|staging|production`
174
-
175
- The environment you are replacing the urls **to**. This is only required if `replace` is true.
176
-
177
- **Example:**
150
+ **Examples:**
178
151
 
179
152
  ```bash
180
153
  wp-scripts import --file="./sql/database.sql"
181
- # Import file and replace urls from staging to dev
182
- wp-scripts import --file="./sql/database.sql" --replace="true" --environment="staging" --currentEnvironment="dev"
183
- # Use the latest file
184
154
  wp-scripts import --file="latest"
155
+ wp-scripts import --file="./sql/database.sql" --replace="true" --environment="staging" --currentEnvironment="local"
185
156
  ```
186
157
 
187
- #### `pull`
188
-
189
- Pull from an _environment_ database to the `project/sql` directory.
190
-
191
- **Options:**
192
-
193
- **environment** `staging|production` (required)
158
+ ---
194
159
 
195
- The environment you are pulling for. This will not replace urls in the file.
160
+ ### `pull`
196
161
 
197
- **serverPassword** `string`
162
+ Pull a remote database to the `sql/` directory.
198
163
 
199
- The password for the configured user on the server. This is only required if no `serverPrivateKey` is provided.
200
-
201
- **serverPrivateKey** `string`
164
+ **Options:**
202
165
 
203
- Path to the private key for the configured user on the server. This is only required if no `serverPassword` is provided.
166
+ - `--environment` `staging|production` (required)
167
+ - `--serverPassword` `string`
168
+ - `--serverPrivateKey` `string`
204
169
 
205
170
  **Example:**
206
171
 
@@ -208,187 +173,149 @@ Path to the private key for the configured user on the server. This is only requ
208
173
  wp-scripts pull --environment="staging" --serverPrivateKey="~/.ssh/id_rsa"
209
174
  ```
210
175
 
211
- #### `setup`
176
+ ---
177
+
178
+ ### `setup`
212
179
 
213
- Setup a new _blank_ project.
180
+ Set up a new blank project by replacing template placeholders.
214
181
 
215
182
  **Options:**
216
183
 
217
- **projectLocation** `string` (required)
184
+ - `--projectLocation` `string` — path relative to MAMP document root
185
+ - `--project` `string` — project name
186
+ - `--productionDomain` `string` — production domain (e.g. `example.com`)
187
+ - `--tablePrefix` `string` — WordPress table prefix
218
188
 
219
- _Default:_ `process.cwd`
189
+ Running without options launches an interactive prompt.
220
190
 
221
- The location of the project relative to your MAMP server directory.
191
+ ---
222
192
 
223
- **project** `string` (required)
193
+ ### `backup`
224
194
 
225
- The project name
195
+ Backup `wp-content` from the dev project to the local file system.
226
196
 
227
- **productionDomain** `string` (required)
197
+ ---
228
198
 
229
- The production domain name
199
+ ### `hooks`
230
200
 
231
- **agency** `string` (required)
201
+ Run a git hook action.
232
202
 
233
- The name of the agency
203
+ **Options:**
234
204
 
235
- **agencySlug** `string` (required)
205
+ - `--type` `string` — hook type (e.g. `post-merge`)
236
206
 
237
- The slug version of the agency name
207
+ ---
238
208
 
239
- **agencyWebsite** `string` (required)
209
+ ### `config`
240
210
 
241
- The agency website url
211
+ Add deployment config for an environment.
242
212
 
243
- **tablePrefix** `string` (required)
213
+ **Options:**
244
214
 
245
- The table prefix for wordpress tables
215
+ - `--environment` `staging|production`
246
216
 
247
- **Example:**
217
+ ---
248
218
 
249
- ```bash
250
- wp-scripts setup --project="Hello" --productionDomain="example.com" --agency="Mitch" --agencySlug="mitch" --agencyWebsite="mitch.app" --tablePrefix="mh_"
251
- ```
219
+ ### `migrate-sass`
252
220
 
253
- #### `hooks`
221
+ Migrate legacy SCSS to Dart Sass 3.0 compatible syntax using the official `sass-migrator`.
254
222
 
255
- Run a git hook
223
+ Dart Sass 3.0 removes `@import`, deprecated color functions (`darken`, `lighten`), `/` for division, and global built-in functions (`map-get`, `nth`). This command runs the official migrations in a safe order.
256
224
 
257
225
  **Options:**
258
226
 
259
- **type** `string` (required)
227
+ - `--migration` `division|color|module` — run a single specific migration (omit to run all three in order)
228
+ - `--glob` `string` — SCSS file glob (default: `src/**/*.scss`)
229
+ - `--dry-run` — preview changes without writing files
260
230
 
261
- The type of git hook to run.
231
+ **Migrations (run in this order):**
262
232
 
263
- **Example:**
233
+ | Migration | What it does | Risk |
234
+ |-----------|-------------|------|
235
+ | `division` | Replaces `/` division with `math.div()`, adds `@use 'sass:math'` | Low |
236
+ | `color` | Replaces `darken()`/`lighten()` etc. with `color.adjust()`/`color.scale()`, adds `@use 'sass:color'` | Low |
237
+ | `module` | Converts `@import` → `@use`/`@forward`, namespaces variables/mixins/functions | High — review carefully |
264
238
 
265
- ```bash
266
- wp-scripts hooks --type="pre-commit"
267
- ```
239
+ **Recommended workflow:**
268
240
 
269
- ### Upgrading from v0.3
241
+ Node modules are resolved automatically (`--load-path=.` is passed to sass-migrator), so imports like `@import 'node_modules/swiper/css/swiper.min'` are handled correctly.
270
242
 
271
- There are multiple breaking changes since v0.3, including a new build system.
243
+ ```bash
244
+ # 1. Preview what will change
245
+ wp-scripts migrate-sass --dry-run
272
246
 
273
- Run the upgrade script in the project:
247
+ # 2. Run the safe migrations first
248
+ wp-scripts migrate-sass --migration=division
249
+ wp-scripts migrate-sass --migration=color
274
250
 
275
- ```bash
276
- node_modules/.bin/wp-scripts upgrade
277
- ```
251
+ # 3. Verify your build still works, then commit
252
+ yarn build
278
253
 
279
- _Note: Make sure you have committed everything before upgrading._
254
+ # 4. Run the module migration separately requires manual review
255
+ # Variables will be namespaced (e.g. $var → variables.$var)
256
+ wp-scripts migrate-sass --migration=module
257
+ ```
280
258
 
281
- ### Overrides
259
+ The `module` migration is complex and almost always requires manual cleanup — especially if partials are imported in multiple places. Run it last and review every changed file before committing.
282
260
 
283
- You can export custom functions to override the default build behaviour.
261
+ ---
284
262
 
285
- Just create an `tasks/overrides.js` file in the project.
263
+ ## Overrides
286
264
 
287
- #### `copyFiles`
265
+ Create a `tasks/overrides.js` file in your project to customise the build.
288
266
 
289
- Add extra files to the build copy task.
267
+ ### `copyFiles`
290
268
 
291
- See [copy-webpack-plugin](https://github.com/webpack-contrib/copy-webpack-plugin) for more details.
269
+ Add extra files to the webpack copy task.
292
270
 
293
- ```
271
+ ```js
294
272
  exports.copyFiles = (paths) => {
295
- // The paths object contains source, theme and build paths.
296
- const {
297
- sourceDir, // Relative
298
- themeDir, // Relative
299
- sourcePath, // Absolute
300
- buildPath, // Absolute
301
- themePath, // Absolute
302
- } = paths;
273
+ const { sourceDir, themeDir, sourcePath, buildPath, themePath } = paths;
303
274
 
304
275
  return [
305
276
  {
306
- // Copy an entire directory to the theme
307
- from: path.join(sourceDir, 'new-directory'),
308
- to: path.join(themePath, 'new-directory'),
277
+ from: path.join(sourceDir, 'my-directory'),
278
+ to: path.join(themePath, 'my-directory'),
309
279
  },
310
- {
311
- // Copy files inside a directory the the theme
312
- from: path.join(sourceDir, 'new-directory'),
313
- to: themePath,
314
- },
315
- {
316
- // Copy file from a directory to the root directory
317
- from: path.join(sourceDir, 'directory-file-was-in', 'file.txt'),
318
- to: '',
319
- },
320
- {
321
- // Copy all files from vendor (except vivo-digital & johnpbloch) to the theme/inc/vendor
322
- from: path.join(__dirname, "..", "vendor"),
323
- to: path.join(themePath, "inc", "vendor"),
324
- globOptions: {
325
- ignore: [
326
- path.join("@(vivo-digital|johnpbloch)", '**')
327
- ],
328
- }
329
- }
330
280
  ];
331
- }
281
+ };
332
282
  ```
333
283
 
334
- #### `webpackConfig`
284
+ ### `webpackConfig`
335
285
 
336
- Overide the default webpack config.
286
+ Override the default webpack config (merged via webpack-merge).
337
287
 
338
- ```
288
+ ```js
339
289
  exports.webpackConfig = () => {
340
290
  return {
341
- // Disable sourcemaps completely
342
291
  devtool: false,
343
- }
344
- }
292
+ };
293
+ };
345
294
  ```
346
295
 
347
- #### `loaderOptions`
296
+ ### `loaderOptions`
348
297
 
349
- Overide default loader options. This is useful in cases where you want to alter an existing loader and cannot use a custom `webpackConfig`.
298
+ Override default loader options. Available loaders: `css`, `js`, `images`, `fonts`.
350
299
 
351
- Available loaders: `css`, `js`, `images`, `fonts`
352
-
353
- ```
300
+ ```js
354
301
  exports.loaderOptions = () => {
355
302
  return {
356
303
  js: {
357
- // Don't run js files from node_modules OR vendor directories through the JS (babel) loader
358
304
  exclude: /(node_modules|vendor)/,
359
- }
305
+ },
360
306
  };
361
307
  };
362
308
  ```
363
309
 
364
- #### `copyFx`
365
-
366
- You can change the path of `fx` packages (classes or modules) installed via composer. This is useful for local development.
367
-
368
- This function should return an object with the package name as the key and local path as the value.
369
-
370
- ```
371
- exports.copyFx = () => {
372
- return {
373
- 'package-name': 'path/to/local/repository',
374
- };
375
- }
376
- ```
377
-
378
- #### `checkProjectDependencies`
310
+ ### `checkProjectDependencies`
379
311
 
380
312
  Run a custom dependency check before the project builds.
381
313
 
382
- ```
383
- exports.checkProjectDependencies = () => {
384
- const pck = JSON.parse(fs.readFileSync(projectPackage, 'utf8'));
385
- const { dependencies } = pck;
386
-
387
- if (!dependencies['some-required-package']) {
388
- console.log('Missing this package!');
314
+ ```js
315
+ exports.checkProjectDependencies = async () => {
316
+ const pck = JSON.parse(fs.readFileSync('package.json', 'utf8'));
317
+ if (!pck.dependencies['some-required-package']) {
318
+ console.warn('Missing some-required-package!');
389
319
  }
390
320
  };
391
321
  ```
392
-
393
- ## Node Version
394
- Currently supports `18.8.0` for all projects running `wp-blank-scripts@3.0.0`
package/cli/config.js CHANGED
@@ -63,12 +63,12 @@ module.exports = async () => {
63
63
  },
64
64
  {
65
65
  name: 'urlProduction',
66
- message: 'What is the production URL?',
66
+ message: 'What is the production URL? (https://...)',
67
67
  when: (answers) => answers.environment === 'production',
68
68
  },
69
69
  {
70
70
  name: 'hostProduction',
71
- message: 'What is the production server host?',
71
+ message: 'What is the production server host? (example.com)',
72
72
  when: (answers) => answers.environment === 'production',
73
73
  },
74
74
  {
@@ -102,20 +102,20 @@ module.exports = async () => {
102
102
  },
103
103
  {
104
104
  name: 'urlStaging',
105
- message: 'What is the staging URL?',
105
+ message: 'What is the staging URL? (https://...)',
106
106
  when: (answers) => answers.environment === 'staging',
107
107
  },
108
108
  {
109
109
  name: 'hostStaging',
110
- message: 'What is the staging server host?',
110
+ message: 'What is the staging server host? (example.com)',
111
111
  when: (answers) => answers.environment === 'staging',
112
- default: 'staging.vivo.digital',
112
+ default: 'preview.vivo.digital',
113
113
  },
114
114
  {
115
115
  name: 'userStaging',
116
116
  message: 'What is the staging server user?',
117
117
  when: (answers) => answers.environment === 'staging',
118
- default: 'stagingvivo',
118
+ default: 'previewv',
119
119
  },
120
120
  {
121
121
  name: 'destinationStaging',
package/cli/deploy.js CHANGED
@@ -43,11 +43,11 @@ async function selectOptions() {
43
43
  message: chalk.cyan('Do you want to deploy sql?'),
44
44
  type: 'confirm',
45
45
  default: false,
46
- when: answers => answers.mode !== DEPLOY_MODES.SQL_ONLY,
46
+ when: (answers) => answers.mode !== DEPLOY_MODES.SQL_ONLY,
47
47
  },
48
48
  {
49
49
  name: 'serverPassword',
50
- message: answers => {
50
+ message: (answers) => {
51
51
  const user = settings.server[answers.environment].user;
52
52
  const host = settings.server[answers.environment].host;
53
53
  return chalk.cyan(
@@ -55,18 +55,18 @@ async function selectOptions() {
55
55
  );
56
56
  },
57
57
  type: 'password',
58
- when: answers => answers.sql || answers.mode === DEPLOY_MODES.SQL_ONLY,
58
+ when: (answers) => answers.sql || answers.mode === DEPLOY_MODES.SQL_ONLY,
59
59
  },
60
60
  {
61
61
  name: 'serverPrivateKey',
62
- message: answers => {
62
+ message: (answers) => {
63
63
  const user = settings.server[answers.environment].user;
64
64
  const host = settings.server[answers.environment].host;
65
65
  return chalk.cyan(`Enter the path to your private key for user ${user} on host ${host}`);
66
66
  },
67
67
  default: '~/.ssh/id_rsa',
68
68
  type: 'input',
69
- when: answers => !answers.serverPassword,
69
+ when: (answers) => !answers.serverPassword,
70
70
  },
71
71
  ]);
72
72
 
@@ -84,7 +84,7 @@ async function selectOptions() {
84
84
  }
85
85
 
86
86
  async function confirmOptions(selectedOptions) {
87
- const deploymentOptinos = [
87
+ const deploymentOptions = [
88
88
  ['Environment', selectedOptions.environment],
89
89
  ['Mode', selectedOptions.mode],
90
90
  ['SQL', selectedOptions.sql || selectedOptions.mode === DEPLOY_MODES.SQL_ONLY],
@@ -93,7 +93,7 @@ async function confirmOptions(selectedOptions) {
93
93
  const { confirm } = await inquirer.prompt([
94
94
  {
95
95
  name: 'confirm',
96
- message: `Please confirm your project settings:\n${deploymentOptinos
96
+ message: `Please confirm your project settings:\n${deploymentOptions
97
97
  .map(([title, value]) => `${chalk.yellow(title)}: ${value}`)
98
98
  .join('\n')}`,
99
99
  type: 'confirm',
@@ -126,7 +126,7 @@ async function promptForCommit(options, unstagedFiles) {
126
126
  name: 'message',
127
127
  message: chalk.cyan('Commit message'),
128
128
  default: `Deploying to ${options.environment}`,
129
- when: answers => answers.commit,
129
+ when: (answers) => answers.commit,
130
130
  },
131
131
  ]);
132
132