@caweb/cli 1.0.5 → 1.2.0

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.
Files changed (38) hide show
  1. package/README.md +62 -27
  2. package/bin/caweb +3 -17
  3. package/lib/admin.js +40 -0
  4. package/lib/caweb.js +20 -17
  5. package/lib/cli.js +224 -142
  6. package/lib/commands/blocks/create-block.js +110 -0
  7. package/lib/commands/blocks/update-block.js +66 -0
  8. package/lib/commands/destroy.js +56 -0
  9. package/lib/commands/index.js +33 -9
  10. package/lib/commands/shell.js +2 -3
  11. package/lib/commands/start.js +57 -69
  12. package/lib/commands/stop.js +41 -0
  13. package/lib/commands/tasks/update-plugins.js +15 -8
  14. package/lib/commands/test.js +17 -70
  15. package/lib/configs.js +41 -21
  16. package/lib/divi.js +28 -26
  17. package/lib/download-sources.js +15 -15
  18. package/lib/env.js +3 -6
  19. package/lib/options.js +2 -2
  20. package/lib/spinner.js +70 -0
  21. package/lib/template/assets/css/popover.css +80 -0
  22. package/lib/template/assets/js/popover.js +30 -0
  23. package/lib/template/block/edit.js.mustache +48 -0
  24. package/lib/template/block/editor.scss.mustache +5 -0
  25. package/lib/template/block/index.js.mustache +40 -0
  26. package/lib/template/block/save.js.mustache +21 -0
  27. package/lib/template/block/style.scss.mustache +6 -0
  28. package/lib/template/index.cjs +48 -0
  29. package/lib/template/plugin/$slug.php.mustache +135 -0
  30. package/lib/template/plugin/core/cdec-api.php.mustache +44 -0
  31. package/lib/template/plugin/core/filters.php.mustache +111 -0
  32. package/lib/template/plugin/core/functions.php.mustache +25 -0
  33. package/lib/template/plugin/inc/renderer.php.mustache +25 -0
  34. package/lib/utils.js +150 -0
  35. package/lib/wordpress.js +45 -27
  36. package/package.json +10 -4
  37. package/lib/commands/tasks/index.js +0 -13
  38. package/lib/docker.js +0 -66
package/README.md CHANGED
@@ -1,45 +1,55 @@
1
1
  # caweb-cli
2
- `caweb-cli` utilizes [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/) in the background; to rapidly set up a local WordPress environment, fully configured for the [CAWebPublishing Service](https://caweb.cdt.ca.gov/). The cli will automatically generate the necessary [.wp-env.json](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/#wp-env-json) file, to override or add additional configuration options use the [.wp-env.override.json](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/#wp-env-override-json) file.
2
+ `caweb-cli` is a tool which rapidly sets up a local WordPress environment fully configured for the [CAWebPublishing Service](https://caweb.cdt.ca.gov/), allows for the creation of Gutenberg blocks with the CAWebPublishing template configurations, and much more. The cli will automatically generate the necessary [.wp-env.json](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/#wp-env-json) file, to override or add additional configuration options use the [.wp-env.override.json](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/#wp-env-override-json) file.
3
3
 
4
- ## Additional Features
5
- - Downloads and configures the [CAWeb Theme](https://github.com/CA-cODE-Works/CAWeb)
6
- - Downloads and configures the [Divi Theme](https://www.elegantthemes.com/gallery/divi/) (*requires valid ElegantThemes Username and API Key*)
7
- - Adds phpMyAdmin Service for both WordPress environments. (Username: <strong>bold</strong> , Password: <strong>password</strong>)
8
- -- phpMyAdmin development site starts at http://localhost:8080
9
- -- phpMyAdmin test site started at http://localhost:9090
4
+ *`caweb-cli` is largely inspired by WordPress Packages major thanks to the whole WordPress team and community!*
5
+ The following WordPress packages are used:
6
+ [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/)
7
+ [create-block](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/)
8
+
9
+ ## Prerequisites
10
+ - Latest version of [Docker Desktop](https://www.docker.com/products/docker-desktop), which includes [Compose v2}(https://docs.docker.com/compose/migrate/), is installed.
11
+ - <strong>For Debian-Based Linux distributions:</strong> <code>docker-compose</code> may need to be installed with: <code>sudo apt-get install docker-compose</code>.
12
+ - <strong>For Windows users:</strong> [WSL should be set to version 2 for Windows Docker Desktop compatibility](https://docs.docker.com/desktop/windows/wsl/).
13
+ - git is installed.
10
14
 
15
+ ## Additional Features
16
+ - Downloads and configures the [CAWeb Theme](https://github.com/CAWebPublishing/CAWeb)
17
+ - Downloads approved plugins utilized by the CAWebPublishing Service
18
+ - Downloads and configures the [Divi Theme](https://www.elegantthemes.com/gallery/divi/) and [Divi Builder Plugin](https://www.elegantthemes.com/gallery/divi/) (*requires valid ElegantThemes Username and API Key*)
19
+ - Adds phpMyAdmin Service for both WordPress environments. (Username: <strong>root</strong> , Password: <strong>password</strong>)
20
+ - phpMyAdmin development site starts at http://localhost:8080
21
+ - phpMyAdmin test site started at http://localhost:9090
22
+ - Uses CAWebPublishing [External Project Template Configuration](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/packages-create-block-external-template/) when creating Gutenberg Blocks, see configurations [here](https://github.com/CAWebPublishing/cli/lib/template)
11
23
  - Adds config.yml to both cli containers
12
24
  <pre>
13
25
  path: /var/www/html
14
26
  apache_modules:
15
27
  - mod_rewrite
16
28
  </pre>
29
+ .
30
+
17
31
  ## Command Reference
18
32
  ### `caweb start`
19
33
  Generates the required wp-env.json, starts the WordPress environment, downloads any CAWebPublishing sources and approved plugins.
20
34
  <pre>
21
- caweb start
35
+ caweb start [options]
36
+
37
+ Starts two CAWebPublishing WordPress instances
38
+ development on port 8888 (​http://localhost:8888​) (override with WP_ENV_PORT)
39
+ tests on port 8889 (​http://localhost:8889​) (override with WP_ENV_TESTS_PORT).
40
+ After first install, use the '--update' flag to download updates to mapped sources and to re-apply CAWeb configuration options.
22
41
 
23
42
  Options:
24
- --debug Enable debug output. [boolean] [default: false]
25
- --update Download source updates and apply WordPress configuration.
26
- [boolean] [default: false]
27
- --xdebug Enables Xdebug. If not passed, Xdebug is turned off. If no
28
- modes are set, uses "debug". You may set multiple Xdebug
29
- modes by passing them in a comma-separated list:
30
- `--xdebug=develop,coverage`. See
31
- https://xdebug.org/docs/all_settings#mode for information
32
- about Xdebug modes. [string]
33
- --scripts Execute any configured lifecycle scripts.
34
- [boolean] [default: true]
35
- --bare True if excluding any downloads from CAWeb, use this if you
36
- want to use a local version of the CAWeb Theme,
37
- Configurations will still be applied.
38
- [boolean] [default: false]
39
- -m, --multisite True if converting to multisite. [boolean] [default: false]
40
- --subdomain If passed, the network will use subdomains, instead of
41
- subdirectories. Doesn't work with 'localhost', make sure to
42
- set Port to 80. [boolean] [default: false]
43
+ --bare True if excluding any downloads from CAWeb, use this if you want to use a local version of the CAWeb Theme, Configurations will still be applied. (default: false)
44
+ -h, --help display help for command
45
+ -m, --multisite True if converting to multisite. (default: false)
46
+ -p, --plugin True if root directory is a plugin. (default: false)
47
+ --scripts Execute any configured lifecycle scripts. (default: true)
48
+ --subdomain If passed, the network will use subdomains, instead of subdirectories. Doesn't work with 'localhost', make sure to set Port to 80. (default: false)
49
+ -t, --theme True if root directory is a theme. (default: false)
50
+ --update Download source updates and apply WordPress configuration. (default: false)
51
+ --xdebug <mode> Enables Xdebug. If not passed, Xdebug is turned off. If no modes are set, uses "debug". You may set multiple Xdebug modes by passing them in a comma-separated list:
52
+ `--xdebug=develop,coverage`. See https://xdebug.org/docs/all_settings#mode for information about Xdebug modes.
43
53
  </pre>
44
54
  ### `caweb stop`
45
55
  <pre>
@@ -148,3 +158,28 @@ Positionals:
148
158
  Options:
149
159
  --debug Enable debug output. [boolean] [default: false]
150
160
  </pre>
161
+
162
+ ### `caweb create-block [options] <slug>`
163
+ <pre>
164
+ caweb create-block [options] <slug>
165
+
166
+ Scaffold for WordPress plugin to register CA.gov Design System Block.
167
+
168
+ Arguments:
169
+ slug Plugin slug to use.
170
+
171
+ Options:
172
+ -h, --help display help for command
173
+ </pre>
174
+ ### `caweb update-block [options] <slug>`
175
+ <pre>
176
+ caweb update-block [options] <slug>
177
+
178
+ Updates a CA.gov Design System Block.
179
+
180
+ Arguments:
181
+ slug Plugin slug to update.
182
+
183
+ Options:
184
+ -h, --help display help for command
185
+ </pre>
package/bin/caweb CHANGED
@@ -1,20 +1,6 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
2
 
4
- // Remove 'node' and the name of the script from the arguments.
5
- let command = process.argv.slice( 2 );
6
- // Default to help text when they aren't running any commands.
7
- if ( ! command.length ) {
8
- command = [ '--help' ];
9
- }
10
-
11
- // Rather than just executing the current CLI we will attempt to find a local version
12
- // and execute that one instead. This prevents users from accidentally using the
13
- // global CLI when a potentially different local version is expected.
14
- const localPath = require.resolve( '@caweb/cli/lib/cli.js', {
15
- paths: [ process.cwd(), __dirname ],
16
- } );
17
- const cli = require( localPath )();
3
+ import cli from '../lib/cli.js';
18
4
 
19
- // Now we can execute the CLI with the given command.
20
- cli.parse( command );
5
+ // Default to help text when they aren't running any commands.
6
+ cli().parse( ! process.argv.length ? [ '--help' ] : process.argv );
package/lib/admin.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import path from 'node:path';
5
+ import fs from 'fs-extra';
6
+
7
+ import { CAWEB_OPTIONS, DIVI_OPTIONS } from './options.js';
8
+
9
+ /**
10
+ * Generates the OVERRIDES.MD
11
+ *
12
+ */
13
+ export default async function generateOverridesMD() {
14
+
15
+ let output = [
16
+ '## [.wp-env.override.json](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/#wp-env-override-json)',
17
+ 'Any fields here will take precedence over .wp-env.json.',
18
+ '## <ins>Special Config Values</ins>',
19
+ ];
20
+
21
+ // Generate CAWeb Options overrides.
22
+ output.push('### <ins>CAWeb Options</ins>');
23
+ for (const [key, option] of Object.entries(CAWEB_OPTIONS)) {
24
+ output.push(`\`${key}\` - Updates CAWeb ${option.label} `);
25
+ }
26
+
27
+ // Generate Divi Options overrides.
28
+ output.push('### <ins>Divi Options</ins>');
29
+ for (const [group, options] of Object.entries(DIVI_OPTIONS)) {
30
+ for (const [key, option] of Object.entries(options)) {
31
+ output.push(`\`${key}\` - Updates CAWeb ${option.label} `);
32
+ }
33
+ }
34
+
35
+ await fs.writeFileSync(
36
+ path.join(process.cwd(), 'docs', 'OVERRIDES.MD'),
37
+ output.join('\n')
38
+ );
39
+
40
+ };
package/lib/caweb.js CHANGED
@@ -1,29 +1,30 @@
1
- 'use strict';
2
1
  /**
3
2
  * External dependencies
4
3
  */
5
- const retry = require( '@wordpress/env/lib/retry' );
4
+ import retry from '@wordpress/env/lib/retry.js';
6
5
 
7
6
  /**
8
7
  * Internal dependencies
9
8
  */
10
- const { CAWEB_OPTIONS } = require('./options');
11
- const { runDockerCmds } = require('./docker');
12
- const { isMultisite } = require('./wordpress');
13
- const { configureDivi } = require('./divi');
9
+ import { CAWEB_OPTIONS } from'./options.js';
10
+ import { runCLICmds } from'./utils.js';
11
+ import { isMultisite } from'./wordpress.js';
12
+ import { configureDivi } from'./divi.js';
14
13
 
15
14
  /**
16
15
  * Activates the CAWeb Theme for the WordPress Environment if it's installed.
17
16
  *
18
17
  * @param {string} environment Which environment to activate the theme on.
19
18
  * @param {WPConfig} config The wp-env config object.
19
+ * @param {Object} spinner A CLI spinner which indicates progress.
20
20
  */
21
21
  async function activateCAWeb(
22
22
  environment,
23
- config
23
+ config,
24
+ spinner
24
25
  ){
25
26
 
26
- const isMulti = await isMultisite( environment, config );
27
+ const isMulti = await isMultisite( environment, config , spinner);
27
28
 
28
29
  let cmds = ['wp theme is-installed CAWeb'];
29
30
 
@@ -33,10 +34,11 @@ async function activateCAWeb(
33
34
  cmds.push( 'wp theme activate CAWeb' );
34
35
  }
35
36
 
36
- return await runDockerCmds(
37
+ return await runCLICmds(
37
38
  environment,
38
39
  cmds,
39
- config
40
+ config,
41
+ spinner
40
42
  );
41
43
 
42
44
  }
@@ -56,8 +58,7 @@ async function configureCAWeb( environment, config, spinner ) {
56
58
  const isThemeActivated = await activateCAWeb( environment, config );
57
59
 
58
60
  const {
59
- DESIGN_SYSTEM_ENABLED,
60
- WP_PERMALINK
61
+ DESIGN_SYSTEM_ENABLED
61
62
  } = config.env[ environment ].config
62
63
 
63
64
  // if our theme is active.
@@ -87,10 +88,11 @@ async function configureCAWeb( environment, config, spinner ) {
87
88
  }
88
89
 
89
90
  // Execute theme option commands.
90
- await runDockerCmds(
91
+ await runCLICmds(
91
92
  environment,
92
93
  themeOptions,
93
- config
94
+ config,
95
+ spinner
94
96
  );
95
97
 
96
98
  // Make Divi WordPress Configurations.
@@ -106,20 +108,21 @@ async function configureCAWeb( environment, config, spinner ) {
106
108
 
107
109
  // Activate Design System plugin
108
110
  if( undefined !== DESIGN_SYSTEM_ENABLED && DESIGN_SYSTEM_ENABLED ){
109
- await runDockerCmds(
111
+ await runCLICmds(
110
112
  environment,
111
113
  [
112
114
  'wp plugin is-installed design-system-wordpress',
113
115
  'wp plugin activate design-system-wordpress'
114
116
  ],
115
- config
117
+ config,
118
+ spinner
116
119
  )
117
120
  }
118
121
 
119
122
 
120
123
  }
121
124
 
122
- module.exports = {
125
+ export {
123
126
  activateCAWeb,
124
127
  configureCAWeb,
125
128
  };
package/lib/cli.js CHANGED
@@ -1,153 +1,235 @@
1
- 'use strict';
2
1
  /**
3
2
  * External dependencies
4
3
  */
5
- const wpenv_cli = require('@wordpress/env/lib/cli');
4
+ //const wpenv_cli = require('@wordpress/env/lib/cli');
6
5
 
7
- const chalk = require( 'chalk' );
8
- const ora = require( 'ora' );
9
- let yargs = require( 'yargs' );
10
- const terminalLink = require( 'terminal-link' );
11
- const { execSync } = require( 'child_process' );
6
+ import path from 'node:path';
7
+ import chalk from 'chalk';
8
+ import parseXdebugMode from '@wordpress/env/lib/parse-xdebug-mode.js';
9
+ import fs from 'fs-extra';
10
+ import terminalLink from 'terminal-link';
11
+ import { Command, Argument, Option } from 'commander';
12
12
 
13
13
  /**
14
14
  * Internal dependencies
15
15
  */
16
- const pkg = require( '../package.json' );
17
- const env = require( './commands' );
18
- const parseXdebugMode = require( '@wordpress/env/lib/parse-xdebug-mode' );
19
-
20
- // Colors.
21
- const boldWhite = chalk.bold.white;
22
- const wpPrimary = boldWhite.bgHex( '#00669b' );
23
- const wpGreen = boldWhite.bgHex( '#4ab866' );
24
- const wpRed = boldWhite.bgHex( '#d94f4f' );
25
- const wpYellow = boldWhite.bgHex( '#f0b849' );
26
-
27
- // Spinner.
28
- const withSpinner =
29
- ( command ) =>
30
- ( ...args ) => {
31
- const spinner = ora().start();
32
- args[ 0 ].spinner = spinner;
33
- let time = process.hrtime();
34
- return command( ...args ).then(
35
- ( message ) => {
36
- time = process.hrtime( time );
37
- spinner.succeed(
38
- `${ message || spinner.text } (in ${ time[ 0 ] }s ${ (
39
- time[ 1 ] / 1e6
40
- ).toFixed( 0 ) }ms)`
41
- );
42
- process.exit( 0 );
43
- },
44
- ( error ) => {
45
- if( error ){
46
- // Error is an unknown error. That means there was a bug in our code.
47
- spinner.fail(
48
- typeof error === 'string' ? error : error.message
49
- );
50
- // Disable reason: Using console.error() means we get a stack trace.
51
- console.error( error );
52
- process.exit( 1 );
53
- }else{
54
- spinner.fail( 'An unknown error occurred.' );
55
- process.exit( 1 );
56
- }
57
- }
58
- );
59
- };
60
-
61
- module.exports = function cli() {
62
- yargs = wpenv_cli();
63
-
64
- // we are overwriting the default wp-env start command with our own.
65
- yargs.command(
66
- 'start',
67
- false,
68
- ( args ) => {
69
- args.option( 'update', {
70
- type: 'boolean',
71
- describe:
72
- 'Download source updates and apply WordPress configuration.',
73
- default: false,
74
- } );
75
- args.option( 'xdebug', {
76
- describe:
77
- 'Enables Xdebug. If not passed, Xdebug is turned off. If no modes are set, uses "debug". You may set multiple Xdebug modes by passing them in a comma-separated list: `--xdebug=develop,coverage`. See https://xdebug.org/docs/all_settings#mode for information about Xdebug modes.',
78
- coerce: parseXdebugMode,
79
- type: 'string',
80
- } );
81
- args.option( 'scripts', {
82
- type: 'boolean',
83
- describe: 'Execute any configured lifecycle scripts.',
84
- default: true,
85
- } );
86
- args.option( 'bare', {
87
- type: 'boolean',
88
- describe: 'True if excluding any downloads from CAWeb, use this if you want to use a local version of the CAWeb Theme, Configurations will still be applied.',
89
- default: false,
90
- } );
91
- args.option( 'multisite', {
92
- alias: 'm',
93
- type: 'boolean',
94
- describe: 'True if converting to multisite.',
95
- default: false,
96
- } );
97
- args.option( 'subdomain', {
98
- type: 'boolean',
99
- describe: "If passed, the network will use subdomains, instead of subdirectories. Doesn't work with 'localhost', make sure to set Port to 80.",
100
- default: false,
101
- } );
102
- },
103
- withSpinner( env.start )
104
- );
105
-
106
- // Shell Terminal Command.
107
- yargs.command(
108
- 'shell [environment]',
109
- 'Open shell terminal in WordPress environment.',
110
- (args) => {
111
- args.positional( 'environment', {
112
- type: 'string',
113
- describe: "Which environment to open terminal in.",
114
- choices: [ 'development', 'tests' ],
115
- default: 'development',
116
- } );
117
- },
118
- withSpinner( env.shell )
119
- )
120
-
121
- // Update Plugin Command.
122
- yargs.command(
123
- 'update-plugins [environment]',
124
- 'Updates all plugins in the WordPress environment.',
125
- (args) => {
126
- args.positional( 'environment', {
127
- type: 'string',
128
- describe: "Which environment to update.",
129
- choices: [ 'development', 'tests' ],
130
- default: 'development',
131
- } );
132
- },
133
- withSpinner( env.updatePlugins )
134
- )
16
+ import * as env from './commands/index.js';
17
+ import {
18
+ wpPrimary,
19
+ wpGreen,
20
+ wpYellow,
21
+ wpRed,
22
+ withSpinner
23
+ } from './spinner.js';
135
24
 
136
- // Test Command.
137
- /*yargs.command(
138
- 'test [environment]',
139
- 'Test commands on a WordPress environment',
140
- (args) => {
141
- args.positional( 'environment', {
142
- type: 'string',
143
- describe: "Which environment to test in.",
144
- choices: [ 'development', 'tests' ],
145
- default: 'development',
146
- } );
147
-
148
- },
149
- withSpinner( env.test )
150
- )*/
25
+ const localPath = path.resolve( path.join(process.cwd(), 'node_modules/@caweb/cli/package.json') )
26
+ const pkg = JSON.parse( await fs.readFile(localPath) );
27
+ const program = new Command();
28
+
29
+ export default function cli() {
30
+ const envArg = new Argument('[environment]', 'Which environment to use.')
31
+ .choices([
32
+ 'development',
33
+ 'tests',
34
+ 'all'
35
+ ])
36
+ .default('development');
37
+
38
+ const containerArg = new Argument('<container>', 'The underlying Docker service to run the command on.')
39
+ .choices([
40
+ 'mysql',
41
+ 'tests-mysql',
42
+ 'wordpress',
43
+ 'tests-wordpress',
44
+ 'cli',
45
+ 'tests-cli',
46
+ ])
47
+ .default('development');
48
+
49
+ program
50
+ .name(wpPrimary( 'caweb'))
51
+ .usage( wpYellow( '<command>' ) )
52
+ .description('Command Line Interface utilized by CAWebPublishing to accomplish several tasks.')
53
+ .version( pkg.version )
54
+ .option(
55
+ '--debug',
56
+ 'Enable debug output.',
57
+ false
58
+ )
59
+ .allowUnknownOption(true)
60
+ .configureHelp({
61
+ sortSubcommands: true,
62
+ sortOptions: true,
63
+ showGlobalOptions: true,
64
+ })
65
+ .addHelpCommand(false)
66
+
67
+ // Start command.
68
+ program.command('start')
69
+ .description(
70
+ wpGreen(
71
+ chalk`Starts two CAWebPublishing WordPress instances\ndevelopment on port ${ terminalLink( '8888', 'http://localhost:8888' ) } (override with WP_ENV_PORT)\ntests on port {bold.underline ${ terminalLink( '8889', 'http://localhost:8889' ) }} (override with WP_ENV_TESTS_PORT).\nAfter first install, use the '--update' flag to download updates to mapped sources and to re-apply CAWeb configuration options.`
72
+ )
73
+ )
74
+ .option(
75
+ '--update',
76
+ 'Download source updates and apply WordPress configuration.',
77
+ false
78
+ )
79
+ .option(
80
+ '--xdebug <mode>',
81
+ 'Enables Xdebug. If not passed, Xdebug is turned off. If no modes are set, uses "debug". You may set multiple Xdebug modes by passing them in a comma-separated list: `--xdebug=develop,coverage`. See https://xdebug.org/docs/all_settings#mode for information about Xdebug modes.',
82
+ )
83
+ .option(
84
+ '--scripts',
85
+ 'Execute any configured lifecycle scripts.',
86
+ true
87
+ )
88
+ .option(
89
+ '--bare',
90
+ 'True if excluding any downloads from CAWeb, use this if you want to use a local version of the CAWeb Theme, Configurations will still be applied.',
91
+ false
92
+ )
93
+ .option(
94
+ '-p, --plugin',
95
+ 'True if root directory is a plugin.',
96
+ false
97
+ )
98
+ .option(
99
+ '-t, --theme',
100
+ 'True if root directory is a theme.',
101
+ false
102
+ )
103
+ .option(
104
+ '-m, --multisite',
105
+ 'True if converting to multisite.',
106
+ false
107
+ )
108
+ .option(
109
+ '--subdomain',
110
+ "If passed, the network will use subdomains, instead of subdirectories. Doesn't work with 'localhost', make sure to set Port to 80.",
111
+ false
112
+ )
113
+ .allowUnknownOption(true)
114
+ .action( withSpinner(env.start) )
115
+
116
+ // Destroy Command.
117
+ program.command('destroy')
118
+ .description(
119
+ wpRed(
120
+ 'Deletes docker containers, volumes, and networks associated with the CAWebPublishing instances and removes local files.'
121
+ )
122
+ )
123
+ .option(
124
+ '--scripts',
125
+ 'Execute any configured lifecycle scripts.',
126
+ true
127
+ )
128
+ .allowUnknownOption(true)
129
+ .action( withSpinner(env.destroy) )
130
+
131
+ // Shell Command.
132
+ program.command('shell')
133
+ .description('Open shell terminal in WordPress environment.')
134
+ .addArgument(envArg)
135
+ .allowUnknownOption(true)
136
+ .action( withSpinner(env.shell) )
137
+
138
+ // Stop Command.
139
+ program.command('stop')
140
+ .description(
141
+ wpRed(
142
+ 'Stops running WordPress for development and tests and frees the ports.'
143
+ )
144
+ )
145
+ .allowUnknownOption(true)
146
+ .action( withSpinner(env.stop) )
147
+
148
+ // Clean Command.
149
+ program.command('clean')
150
+ .description(
151
+ wpYellow( 'Cleans the WordPress databases.' )
152
+ )
153
+ .addArgument(envArg)
154
+ .option(
155
+ '--scripts',
156
+ 'Execute any configured lifecycle scripts.',
157
+ true
158
+ )
159
+ .allowUnknownOption(true)
160
+ .action( withSpinner(env.clean) )
151
161
 
152
- return yargs;
162
+ // Logs Command.
163
+ program.command('logs')
164
+ .description(
165
+ 'Displays PHP and Docker logs for given WordPress environment.'
166
+ )
167
+ .addArgument(envArg)
168
+ .option(
169
+ '--no-watch',
170
+ 'Stops watching for logs in realtime.',
171
+ true
172
+ )
173
+ .allowUnknownOption(true)
174
+ .action( withSpinner(env.logs) )
175
+
176
+
177
+ // Run Command.
178
+ program.command('run')
179
+ .description(
180
+ 'Runs an arbitrary command in one of the underlying Docker containers. A double dash can be used to pass arguments to the container without parsing them. This is necessary if you are using an option that is defined below. You can use `bash` to open a shell session and both `composer` and `phpunit` are available in all WordPress and CLI containers. WP-CLI is also available in the CLI containers.'
181
+ )
182
+ .addArgument(containerArg)
183
+ .argument('[command...]', 'The command to run.')
184
+ .option(
185
+ '--env-cwd',
186
+ "The command's working directory inside of the container. Paths without a leading slash are relative to the WordPress root.",
187
+ '.'
188
+ )
189
+ .allowUnknownOption(true)
190
+ .action( withSpinner(env.run) )
191
+
192
+
193
+ // Install Path Command.
194
+ program.command('install-path')
195
+ .description('Get the path where all of the environment files are stored. This includes the Docker files, WordPress, PHPUnit files, and any sources that were downloaded.')
196
+ .allowUnknownOption(true)
197
+ .action( withSpinner(env.installPath) )
198
+
199
+ // Update Plugins Command.
200
+ program.command('update-plugins')
201
+ .description('Updates all plugins in the WordPress environment.')
202
+ .argument('[slug]', 'Plugin slug to update.', 'all')
203
+ .addOption(new Option('--environment <env>', 'Which environment to use.').choices(['development', 'tests']).default('development'))
204
+ .allowUnknownOption(true)
205
+ .action( withSpinner(env.updatePlugins) )
206
+
207
+ // Create a Design System Block Command.
208
+ program.command('create-block')
209
+ .description('Scaffold for WordPress plugin to register CA.gov Design System Block.')
210
+ .argument('<slug>', 'Plugin slug to use.')
211
+ .allowUnknownOption(true)
212
+ .action( withSpinner(env.createBlock) )
213
+
214
+ // Update a Design System Block Command.
215
+ program.command('update-block')
216
+ .description('Updates a CA.gov Design System Block.')
217
+ .argument('<slug>', 'Plugin slug to update.')
218
+ .allowUnknownOption(true)
219
+ .action( withSpinner(env.updateBlock) )
220
+
221
+ // Test Command.
222
+ // Ensure this is commented out.
223
+ program.command('test')
224
+ .description('Test commands on a WordPress environment')
225
+ .addArgument(envArg)
226
+ .option(
227
+ '--scripts',
228
+ 'Execute any configured lifecycle scripts.',
229
+ true
230
+ )
231
+ .allowUnknownOption(true)
232
+ .action(withSpinner(env.test))
233
+
234
+ return program;
153
235
  };