@caweb/cli 1.11.0 → 1.11.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/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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/cli",
3
- "version": "1.11.0",
3
+ "version": "1.11.1",
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",
@@ -48,6 +50,7 @@
48
50
  "WP_MEMORY_LIMIT": "256M",
49
51
  "WP_MAX_MEMORY_LIMIT": "512M",
50
52
  "WP_PERMALINK": "/%year%/%monthnum%/%postname%/",
53
+ "WP_POST_REVISIONS": true,
51
54
  "ADMIN_COOKIE_PATH": "/",
52
55
  "COOKIE_DOMAIN": "",
53
56
  "COOKIEPATH": "",
@@ -56,18 +59,24 @@
56
59
  }
57
60
  },
58
61
  "dependencies": {
59
- "@caweb/webpack": "^1.3.44",
60
- "@inquirer/prompts": "^7.5.0",
62
+ "@caweb/a11y-webpack-plugin": "^1.0.9",
63
+ "@caweb/css-audit-webpack-plugin": "^1.0.12",
64
+ "@caweb/jshint-webpack-plugin": "^2.0.1",
65
+ "@caweb/webpack": "^1.4.0-beta.3",
66
+ "@inquirer/prompts": "^7.5.1",
61
67
  "@wordpress/create-block": "^4.66.0",
62
68
  "@wordpress/env": "^10.23.0",
63
69
  "axios": "^1.9.0",
64
70
  "axios-retry": "^4.5.0",
65
71
  "chalk": "^5.4.1",
66
- "commander": "^13.1.0",
72
+ "commander": "^14.0.0",
67
73
  "cross-spawn": "^7.0.6",
68
74
  "docker-compose": "^1.2.0",
69
75
  "fs-extra": "^11.3.0",
76
+ "html-to-json-parser": "^2.0.1",
70
77
  "inquirer-select-pro": "^1.0.0-alpha.9",
78
+ "jsdom": "^26.1.0",
79
+ "node-html-parser": "^7.0.1",
71
80
  "ora": "^8.2.0",
72
81
  "resolve-bin": "^1.0.1",
73
82
  "rimraf": "^6.0.1",