@caweb/cli 1.11.0 → 1.11.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.
@@ -8,8 +8,6 @@ import fs from 'fs';
8
8
  * Internal dependencies
9
9
  */
10
10
  import {
11
- appPath,
12
- projectPath,
13
11
  runCmd
14
12
  } from '../../lib/index.js';
15
13
 
@@ -31,8 +29,8 @@ export default async function webpack({
31
29
  } ) {
32
30
  const webpackCommand = 'build' === process.argv[2] ? 'build' : 'serve' ;
33
31
 
34
- // we use our default config from the @caweb/html-webpack-plugin
35
- const defaultConfigPath = path.resolve('node_modules', '@caweb', 'html-webpack-plugin', 'webpack.config.js' );
32
+ // we use our default config from the @caweb/webpack
33
+ const defaultConfigPath = path.resolve('node_modules', '@caweb', 'webpack', 'webpack.config.js' );
36
34
 
37
35
  // Since we use @wordpress/scripts webpack config we can leverage
38
36
  // the environment variables as well.
package/lib/cli.js CHANGED
@@ -12,6 +12,7 @@ import { Command, Argument, Option } from 'commander';
12
12
  import * as env from '../commands/index.js';
13
13
 
14
14
  import {
15
+ appPath,
15
16
  projectPath,
16
17
  withSpinner
17
18
  } from './index.js';
@@ -55,7 +56,7 @@ function addWebpackCmds(){
55
56
 
56
57
  // Serve Command.
57
58
  program.command('serve')
58
- .description('Serve the current project')
59
+ .description('Serves the current project using CAWebPublishing templates.')
59
60
  .addOption(new Option('--template <template>', 'Serves the project using templating.').choices(['default', 'blank']).default('default'))
60
61
  .addOption(new Option('--scheme <scheme>', 'Serves the project using template colorscheme.').choices([
61
62
  'delta',
@@ -287,6 +288,118 @@ function addWPEnvCommands(){
287
288
 
288
289
  }
289
290
 
291
+ /**
292
+ * Adds commands for wp instances
293
+ */
294
+ function addWPInstanceCommands(){
295
+ // Update Plugins Command.
296
+ program.command('update-plugins')
297
+ .description('Updates all plugins in the WordPress environment.')
298
+ .argument('[slug]', 'Plugin slug to update.', 'all')
299
+ .addOption(new Option('--environment <env>', 'Which environment to use.').choices(['development', 'tests']).default('development'))
300
+ .allowUnknownOption(true)
301
+ .allowExcessArguments(true)
302
+ .action( withSpinner(env.updatePlugins) )
303
+
304
+ // Sync changes from one WordPress instance to another.
305
+ program.command('sync')
306
+ .description('Sync changes from one WordPress instance to another.')
307
+ .argument('[target]', 'Target Site URL, this is the site containing the latest changes.')
308
+ .argument('[dest]', 'Destination Site URL, this is the site where the latest changes should go.')
309
+ .addOption(new Option(
310
+ '--interactive',
311
+ 'Runs the sync process with prompts'
312
+ ))
313
+ .addOption(
314
+ new Option(
315
+ '-t,--tax <tax...>',
316
+ 'Taxonomy that should be synced. Default is full site sync.'
317
+ )
318
+ .choices(['media', 'menus', 'pages', 'posts', 'settings'])
319
+ .default(['media', 'menus', 'pages', 'posts', 'settings'])
320
+ )
321
+ .addOption(new Option(
322
+ '--media-ids <ids...>',
323
+ 'Sync specific Media IDs.'
324
+ ))
325
+ .addOption(new Option(
326
+ '--menu-ids <ids...>',
327
+ 'Sync specific Menu IDs.'
328
+ ))
329
+ .addOption(new Option(
330
+ '--page-ids <ids...>',
331
+ 'Sync specific Page IDs.'
332
+ ))
333
+ .addOption(new Option(
334
+ '--post-ids <ids...>',
335
+ 'Sync specific Post IDs.'
336
+ ))
337
+ .option(
338
+ '--debug',
339
+ 'Enable debug output.',
340
+ false
341
+ )
342
+ .allowUnknownOption(true)
343
+ .allowExcessArguments(true)
344
+ .action( withSpinner(env.sync) )
345
+ }
346
+
347
+ /**
348
+ * Adds commands for blocks
349
+ */
350
+ function addBlockCommands(){
351
+ // Create a Gutenberg Block Command.
352
+ program.command('create-block')
353
+ .description('Scaffold for WordPress plugin to register Gutenberg Blocks.')
354
+ .argument('<slug>', 'Plugin slug to use.')
355
+ .allowUnknownOption(true)
356
+ .allowExcessArguments(true)
357
+ .action( withSpinner(env.createBlock) )
358
+
359
+ // Update a Gutenberg Block Command.
360
+ program.command('update-block')
361
+ .description('Updates a Gutenberg Block.')
362
+ .argument('<slug>', 'Plugin slug to update.')
363
+ .allowUnknownOption(true)
364
+ .allowExcessArguments(true)
365
+ .action( withSpinner(env.updateBlock) )
366
+ }
367
+
368
+ /**
369
+ * Adds commands for sites
370
+ */
371
+ function addSiteCommands(){
372
+ // Create a site command.
373
+ program.command('create-site')
374
+ .description('Creates a new CAWebPublishing Site Configuration file.')
375
+ .allowUnknownOption(true)
376
+ .allowExcessArguments(true)
377
+ .addOption(new Option(
378
+ '--site-title [title]',
379
+ 'Site Title'
380
+ ).default(path.basename( appPath ))
381
+ )
382
+ .addOption(new Option(
383
+ '--silent,-s',
384
+ 'Runs the site creation process without prompts, this is useful for CI/CD pipelines.'
385
+ ).default(false)
386
+ )
387
+ .action( withSpinner(env.createSite) )
388
+
389
+
390
+ // Convert a site command.
391
+ program.command('convert-site')
392
+ .description('Attempts to convert a site.')
393
+ .allowUnknownOption(true)
394
+ .allowExcessArguments(true)
395
+ .addOption(new Option(
396
+ '--builder [builder]',
397
+ 'Editor style to use for the pages.'
398
+ ).choices(['plain', 'divi', 'gutenberg']).default('wp')
399
+ )
400
+ .action( withSpinner(env.convertSite) )
401
+ }
402
+
290
403
  export default function cli() {
291
404
 
292
405
  program
@@ -309,73 +422,15 @@ export default function cli() {
309
422
  // Add wp-env specific commands.
310
423
  addWPEnvCommands();
311
424
 
312
- // Update Plugins Command.
313
- program.command('update-plugins')
314
- .description('Updates all plugins in the WordPress environment.')
315
- .argument('[slug]', 'Plugin slug to update.', 'all')
316
- .addOption(new Option('--environment <env>', 'Which environment to use.').choices(['development', 'tests']).default('development'))
317
- .allowUnknownOption(true)
318
- .allowExcessArguments(true)
319
- .action( withSpinner(env.updatePlugins) )
320
-
321
- // Create a Design System Block Command.
322
- program.command('create-block')
323
- .description('Scaffold for WordPress plugin to register CA.gov Design System Block.')
324
- .argument('<slug>', 'Plugin slug to use.')
325
- .allowUnknownOption(true)
326
- .allowExcessArguments(true)
327
- .action( withSpinner(env.createBlock) )
425
+ // Add wp-env specific commands.
426
+ addWPInstanceCommands()
328
427
 
329
- // Update a Design System Block Command.
330
- program.command('update-block')
331
- .description('Updates a CA.gov Design System Block.')
332
- .argument('<slug>', 'Plugin slug to update.')
333
- .allowUnknownOption(true)
334
- .allowExcessArguments(true)
335
- .action( withSpinner(env.updateBlock) )
428
+ // Add block specific commands.
429
+ addBlockCommands()
336
430
 
337
-
338
- // Update a Design System Block Command.
339
- program.command('sync')
340
- .description('Sync changes from one WordPress instance to another.')
341
- .argument('[target]', 'Target Site URL, this is the site containing the latest changes.')
342
- .argument('[dest]', 'Destination Site URL, this is the site where the latest changes should go.')
343
- .addOption(new Option(
344
- '--interactive',
345
- 'Runs the sync process with prompts'
346
- ))
347
- .addOption(
348
- new Option(
349
- '-t,--tax <tax...>',
350
- 'Taxonomy that should be synced. Default is full site sync.'
351
- )
352
- .choices(['media', 'menus', 'pages', 'posts', 'settings'])
353
- .default(['media', 'menus', 'pages', 'posts', 'settings'])
354
- )
355
- .addOption(new Option(
356
- '--media-ids <ids...>',
357
- 'Sync specific Media IDs.'
358
- ))
359
- .addOption(new Option(
360
- '--menu-ids <ids...>',
361
- 'Sync specific Menu IDs.'
362
- ))
363
- .addOption(new Option(
364
- '--page-ids <ids...>',
365
- 'Sync specific Page IDs.'
366
- ))
367
- .addOption(new Option(
368
- '--post-ids <ids...>',
369
- 'Sync specific Post IDs.'
370
- ))
371
- .option(
372
- '--debug',
373
- 'Enable debug output.',
374
- false
375
- )
376
- .allowUnknownOption(true)
377
- .allowExcessArguments(true)
378
- .action( withSpinner(env.sync) )
431
+ // Add site specific commands.
432
+ addSiteCommands()
433
+
379
434
 
380
435
  // Test Command.
381
436
  // Ensure this is commented out.
package/lib/helpers.js CHANGED
@@ -2,6 +2,7 @@
2
2
  * External dependencies
3
3
  */
4
4
  import path from 'path';
5
+ import chalk from 'chalk';
5
6
  import spawn from 'cross-spawn';
6
7
  import { fileURLToPath } from 'url';
7
8
  import { sync as resolveBin } from 'resolve-bin';
@@ -12,14 +13,22 @@ import * as dockerCompose from 'docker-compose';
12
13
  */
13
14
 
14
15
  /**
15
- * Path Directory Locations
16
- * - currentPath - Current Directory
17
- * - projectPath - Current Project Path
18
- * - appPath - Current Application Path
16
+ * Path Directory Definitions
17
+ * - currentPath - This files current location in the current project.
19
18
  */
20
19
  const currentPath = path.dirname(fileURLToPath(import.meta.url));
20
+
21
+ /**
22
+ * Path Directory Definitions
23
+ * - projectPath - The cli project path in the current project.
24
+ */
21
25
  const projectPath = path.resolve( currentPath, '..' );
22
- const appPath = path.resolve( projectPath, '../../../' );
26
+
27
+ /**
28
+ * Path Directory Definitions
29
+ * - appPath - Current Project Working Directory
30
+ */
31
+ const appPath = process.cwd();
23
32
 
24
33
  /**
25
34
  * Runs command directly.
@@ -103,10 +112,91 @@ async function runCLICmds(
103
112
  );
104
113
  }
105
114
 
115
+
116
+ /**
117
+ * Write a line to the console.
118
+ *
119
+ * @param {string} text Text to write.
120
+ * @param {string} opts.color Color of the text.
121
+ * @param {string} opts.prefix Prefix of the text.
122
+ * @param {string} opts.bold Bold text.
123
+ * @param {string} opts.char Character to use for the border.
124
+ * @param {string} opts.borderColor Character border color.
125
+ */
126
+ function writeLine(text, options = {}) {
127
+ let defaults = {
128
+ color: 'white',
129
+ prefix: '',
130
+ bold: false,
131
+ char: '',
132
+ borderColor: 'white'
133
+ }
134
+
135
+ // combine the defaults with the opts
136
+ let opts = {
137
+ ...defaults,
138
+ ...options
139
+ }
140
+
141
+ let {
142
+ color, prefix, bold,char, borderColor
143
+ } = opts;
144
+
145
+ // set border options first
146
+ if( char ) {
147
+ // set border color
148
+ char = chalk[borderColor]( char );
149
+
150
+ // set bold
151
+ char = bold ? chalk.bold(char) : char;
152
+
153
+ // border repetition
154
+ char = char.repeat(text.length) + '\n';
155
+ }
156
+
157
+ // Add a prefix to the text if it is not empty.
158
+ text = prefix ? prefix + ' ' + text : text;
159
+
160
+ // Add a bold to the text if it is not empty.
161
+ text = bold ? chalk.bold(text) : text;
162
+
163
+ // Add a color to the text if it is not empty.
164
+ text = chalk[color](text);
165
+
166
+ // add a border to the top of the text if it is not empty.
167
+ // add a border to the bottom of the text if it is not empty.
168
+
169
+ process.stdout.write(char + text + '\n' + char);
170
+ }
171
+
172
+ /**
173
+ * Write an error to the console.
174
+ *
175
+ * @param {string} text
176
+ */
177
+ function writeError(text) {
178
+ process.stderr.write(text + '\n');
179
+ }
180
+
181
+ /**
182
+ * Clear lines from the console
183
+ * @param {int} count Number of lines to clear.
184
+ */
185
+ function clearLine(count = 1) {
186
+ do {
187
+ // process.stdout.write("\r\x1b[K");
188
+ process.stdout.moveCursor(0, -1) // up one line
189
+ process.stdout.clearLine(1) // from cursor to end
190
+ } while (--count);
191
+ }
192
+
106
193
  export {
107
194
  currentPath,
108
195
  projectPath,
109
196
  appPath,
110
197
  runCmd,
111
- runCLICmds
198
+ runCLICmds,
199
+ writeLine,
200
+ writeError,
201
+ clearLine,
112
202
  };
package/lib/index.js CHANGED
@@ -3,7 +3,10 @@ import {
3
3
  currentPath,
4
4
  projectPath,
5
5
  runCmd,
6
- runCLICmds
6
+ runCLICmds,
7
+ writeLine,
8
+ writeError,
9
+ clearLine,
7
10
  } from './helpers.js';
8
11
 
9
12
  // Spinner
@@ -32,6 +35,9 @@ export {
32
35
  appPath,
33
36
  currentPath,
34
37
  projectPath,
38
+ writeLine,
39
+ writeError,
40
+ clearLine,
35
41
  runCmd,
36
42
  withSpinner,
37
43
  runCLICmds,
@@ -60,6 +60,8 @@ function processUrlParam( param ){
60
60
  * @returns {unknown}
61
61
  */
62
62
  async function getTaxonomies( request, tax = 'pages', debug = false ){
63
+ let collection = [];
64
+
63
65
  const fields = request.fields ? request.fields : [
64
66
  'id',
65
67
  'type',
@@ -132,9 +134,8 @@ async function getTaxonomies( request, tax = 'pages', debug = false ){
132
134
  request.per_page = request.per_page && request.per_page <= 100 ? request.per_page : 100;
133
135
  urlParams.push( 'per_page=' + request.per_page );
134
136
 
135
- let collection = [];
136
137
  let results = false;
137
-
138
+
138
139
  /**
139
140
  * Results are capped to 100 max per page
140
141
  * in order to return all results, we make the same requests and pass the page parameter.
@@ -177,7 +178,6 @@ async function getTaxonomies( request, tax = 'pages', debug = false ){
177
178
 
178
179
  page++;
179
180
  }while( results )
180
-
181
181
 
182
182
  return collection;
183
183
  }
@@ -354,6 +354,7 @@ async function createTaxonomies( taxData, request, tax = 'pages', spinner ){
354
354
 
355
355
  }
356
356
 
357
+ return collection;
357
358
 
358
359
  }
359
360
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/cli",
3
- "version": "1.11.0",
3
+ "version": "1.11.2",
4
4
  "description": "CAWebPublishing Command Line Interface.",
5
5
  "exports": "./lib/env.js",
6
6
  "type": "module",
@@ -19,7 +19,9 @@
19
19
  "template"
20
20
  ],
21
21
  "scripts": {
22
+ "caweb": "node bin/caweb.js",
22
23
  "doc": "node ./docs/tool/index.js",
24
+ "testa": "node ./test.js",
23
25
  "test": "echo \"Error: run tests from root\" && exit 0"
24
26
  },
25
27
  "homepage": "https://github.com/CAWebPublishing/cli#readme",
@@ -40,6 +42,7 @@
40
42
  "config": {
41
43
  "WP_VER": "6.8.1",
42
44
  "PHP_VER": "8.2",
45
+ "DIVI_VER": "4.27.4",
43
46
  "DEFAULTS": {
44
47
  "FS_METHOD": "direct",
45
48
  "WP_DEBUG": true,
@@ -48,6 +51,7 @@
48
51
  "WP_MEMORY_LIMIT": "256M",
49
52
  "WP_MAX_MEMORY_LIMIT": "512M",
50
53
  "WP_PERMALINK": "/%year%/%monthnum%/%postname%/",
54
+ "WP_POST_REVISIONS": true,
51
55
  "ADMIN_COOKIE_PATH": "/",
52
56
  "COOKIE_DOMAIN": "",
53
57
  "COOKIEPATH": "",
@@ -56,18 +60,24 @@
56
60
  }
57
61
  },
58
62
  "dependencies": {
59
- "@caweb/webpack": "^1.3.44",
60
- "@inquirer/prompts": "^7.5.0",
61
- "@wordpress/create-block": "^4.66.0",
62
- "@wordpress/env": "^10.23.0",
63
+ "@caweb/a11y-webpack-plugin": "^1.0.9",
64
+ "@caweb/css-audit-webpack-plugin": "^1.0.12",
65
+ "@caweb/jshint-webpack-plugin": "^2.0.1",
66
+ "@caweb/webpack": "^1.4.4",
67
+ "@inquirer/prompts": "^7.5.3",
68
+ "@wordpress/create-block": "^4.67.0",
69
+ "@wordpress/env": "^10.24.0",
63
70
  "axios": "^1.9.0",
64
71
  "axios-retry": "^4.5.0",
65
72
  "chalk": "^5.4.1",
66
- "commander": "^13.1.0",
73
+ "commander": "^14.0.0",
67
74
  "cross-spawn": "^7.0.6",
68
75
  "docker-compose": "^1.2.0",
69
76
  "fs-extra": "^11.3.0",
77
+ "html-to-json-parser": "^2.0.1",
70
78
  "inquirer-select-pro": "^1.0.0-alpha.9",
79
+ "jsdom": "^26.1.0",
80
+ "node-html-parser": "^7.0.1",
71
81
  "ora": "^8.2.0",
72
82
  "resolve-bin": "^1.0.1",
73
83
  "rimraf": "^6.0.1",