@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/lib/wordpress.js CHANGED
@@ -1,57 +1,71 @@
1
- 'use strict';
2
- const { writeFile } = require('fs-extra');
3
- const path = require( 'path' );
4
- const { execSync } = require( 'child_process' );
5
-
6
1
  /**
7
2
  * External dependencies
8
3
  */
4
+ import fs from 'fs-extra';
5
+ import path from 'node:path';
9
6
 
10
7
  /**
11
8
  * Internal dependencies
12
9
  */
13
- const {runDockerCmds} = require('./docker');
10
+ import {runCLICmds} from './utils.js';
11
+
12
+ /**
13
+ * Promisified dependencies
14
+ */
15
+ const { writeFile } = fs.promises;
14
16
 
15
17
  /**
16
18
  * Checks whether WordPress environment is a multisite installation.
17
19
  *
18
20
  * @param {string} environment Which environment to check for multisite installation.
19
21
  * @param {WPConfig} config The wp-env config object.
22
+ * @param {Object} spinner A CLI spinner which indicates progress.
20
23
  * @returns
21
24
  */
22
- async function isMultisite( environment, config ){
23
- return await runDockerCmds(
25
+ async function isMultisite( environment, config, spinner ){
26
+
27
+ const result = await runCLICmds(
24
28
  environment,
25
29
  [ 'wp config get MULTISITE' ],
26
- config
30
+ config,
31
+ spinner
27
32
  )
33
+
34
+ /**
35
+ * If the constant doesn't exist the wp cli returns an exit code of 1
36
+ * we have to return false, otherwise we can just return the cli result.
37
+ */
38
+ return typeof result === 'object' && result.exitCode ? false : result;
28
39
  }
29
40
 
30
41
  /**
31
42
  * Transforms an existing single-site installation into a multisite installation.
32
43
  *
33
- * @param {string} environment Which environment to convert into a multisite installation.
34
- * @param {WPConfig} config The wp-env config object.
35
- * @param {boolean} subdomain True if converting to multisite subdomain.
44
+ * @param {string} environment Which environment to convert into a multisite installation.
45
+ * @param {WPConfig} config The wp-env config object.
46
+ * @param {boolean} subdomain True if converting to multisite subdomain.
47
+ * @param {Object} spinner A CLI spinner which indicates progress.
36
48
  * @returns
37
49
  */
38
- async function convertToMultisite( environment, config, subdomain ){
50
+ async function convertToMultisite( environment, config, subdomain, spinner ){
39
51
  // before we can conver to multisite all plugins must be deactivated.
40
52
  // first lets get all plugins
41
- let activePlugins = await runDockerCmds(
53
+ let activePlugins = await runCLICmds(
42
54
  environment,
43
55
  ['wp option get active_plugins --format=json'],
44
- config
56
+ config,
57
+ spinner
45
58
  )
46
59
 
47
60
  activePlugins = Object.values(JSON.parse( activePlugins ));
48
61
 
49
62
  // deactivate all active plugins.
50
63
  if( activePlugins.length ){
51
- await runDockerCmds(
64
+ await runCLICmds(
52
65
  environment,
53
66
  ['wp plugin deactivate ' + activePlugins.join(' ')],
54
- config
67
+ config,
68
+ spinner
55
69
  )
56
70
  }
57
71
 
@@ -62,10 +76,11 @@ async function convertToMultisite( environment, config, subdomain ){
62
76
  command += ' --subdomains'
63
77
  }
64
78
 
65
- await runDockerCmds(
79
+ await runCLICmds(
66
80
  environment,
67
81
  [command],
68
- config
82
+ config,
83
+ spinner
69
84
  )
70
85
 
71
86
  // generate .htaccess
@@ -73,10 +88,11 @@ async function convertToMultisite( environment, config, subdomain ){
73
88
 
74
89
  // network activate all active plugins again.
75
90
  if( activePlugins.length ){
76
- await runDockerCmds(
91
+ await runCLICmds(
77
92
  environment,
78
93
  ['wp plugin activate ' + activePlugins.join(' ') + ' --network'],
79
- config
94
+ config,
95
+ spinner
80
96
  )
81
97
  }
82
98
 
@@ -85,8 +101,8 @@ async function convertToMultisite( environment, config, subdomain ){
85
101
  /**
86
102
  * Generates .htaccess file content.
87
103
  *
88
- * @param {string} environment Which environment to generate .htaccess for.
89
- * @param {boolean} subdomain True if converting to multisite subdomain.
104
+ * @param {string} environment Which environment to generate .htaccess for.
105
+ * @param {boolean} subdomain True if converting to multisite subdomain.
90
106
  */
91
107
  async function generateHTAccess(environment, workDirectoryPath, subdomain){
92
108
  let trailingSlash = subdomain ? '^wp-admin$ wp-admin/ [R=301,L]' : '^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/';
@@ -115,6 +131,7 @@ async function generateHTAccess(environment, workDirectoryPath, subdomain){
115
131
  await writeFile(path.join(workDirectoryPath, folder, '.htaccess'), htaccess);
116
132
 
117
133
  }
134
+
118
135
  /**
119
136
  * Configures WordPress for the given environment by installing WordPress,
120
137
  * activating all plugins, and activating the first theme. These steps are
@@ -137,20 +154,21 @@ async function configureWordPress(environment, config, spinner, multisite, subdo
137
154
  if( multisite ){
138
155
  spinner.text = 'Converting to multisite ' + ( subdomain ? 'subdomain' : 'subdirectory') + '...'
139
156
 
140
- await convertToMultisite( environment, config, subdomain )
157
+ await convertToMultisite( environment, config, subdomain, spinner )
141
158
  }
142
159
 
143
160
  // rewrite and flush permalink structure.
144
- await runDockerCmds(
161
+ await runCLICmds(
145
162
  environment,
146
163
  [
147
164
  `wp rewrite structure ${WP_PERMALINK} --hard`
148
165
  ],
149
- config
166
+ config,
167
+ spinner
150
168
  );
151
169
  }
152
170
 
153
- module.exports = {
171
+ export {
154
172
  configureWordPress,
155
173
  isMultisite,
156
174
  convertToMultisite,
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@caweb/cli",
3
- "version": "1.0.5",
3
+ "version": "1.2.0",
4
4
  "description": "CAWebPublishing Command Line Interface.",
5
- "main": "lib/env.js",
5
+ "exports": "./lib/env.js",
6
+ "type": "module",
7
+ "node": ">=16",
6
8
  "files": [
7
9
  "bin",
8
10
  "lib"
@@ -16,6 +18,7 @@
16
18
  },
17
19
  "scripts": {
18
20
  "caweb": "caweb",
21
+ "wp-env": "wp-env",
19
22
  "local": "npm pack && npm i caweb-cli-%npm_package_version%.tgz",
20
23
  "test": "echo \"Error: run tests from root\" && exit 0"
21
24
  },
@@ -37,15 +40,17 @@
37
40
  },
38
41
  "homepage": "https://github.com/CAWebPublishing/caweb-cli#readme",
39
42
  "dependencies": {
43
+ "@wordpress/create-block": "^4.32.0",
40
44
  "@wordpress/env": "^9.0.0",
41
45
  "chalk": "^4.0.0",
46
+ "commander": "^11.1.0",
42
47
  "fs-extra": "^11.1.1"
43
48
  },
44
49
  "config": {
45
50
  "WP_VER": "6.4.2",
46
51
  "PHP_VER": "8.1",
52
+ "CREATE_BLOCK_VER": "4.32.0",
47
53
  "DEFAULTS": {
48
- "WP_DEFAULT_THEME": "CAWeb",
49
54
  "FS_METHOD": "direct",
50
55
  "WP_DEBUG": true,
51
56
  "WP_DEBUG_LOG": true,
@@ -56,7 +61,8 @@
56
61
  "ADMIN_COOKIE_PATH": "/",
57
62
  "COOKIE_DOMAIN": "",
58
63
  "COOKIEPATH": "",
59
- "SITECOOKIEPATH": ""
64
+ "SITECOOKIEPATH": "",
65
+ "CONCATENATE_SCRIPTS": false
60
66
  }
61
67
  }
62
68
  }
@@ -1,13 +0,0 @@
1
- 'use strict';
2
- /**
3
- * External dependencies
4
- */
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- const updatePlugins = require('./update-plugins')
10
-
11
- module.exports = {
12
- updatePlugins,
13
- };
package/lib/docker.js DELETED
@@ -1,66 +0,0 @@
1
- 'use strict';
2
- /**
3
- * External dependencies
4
- */
5
- const dockerCompose = require( 'docker-compose' );
6
- const path = require( 'path' );
7
- const loadConfig = require( '@wordpress/env/lib/config/load-config' );
8
-
9
-
10
- /**
11
- * Internal dependencies
12
- */
13
-
14
- /**
15
- * Runs commands on the given WordPress environment.
16
- *
17
- * @param {string} environment Which environment to run docker command on.
18
- * @param {string[]} cmds Array of commands to run.
19
- * @param {WPConfig} config The wp-env config object.
20
- *
21
- * @returns {Object}
22
- */
23
- async function runDockerCmds(
24
- environment,
25
- cmds,
26
- config
27
- ) {
28
-
29
- try {
30
- // Execute all setup commands in a batch.
31
- return await dockerCompose.run(
32
- environment === 'development' ? 'cli' : 'tests-cli',
33
- [ 'bash', '-c', cmds.join( ' && ' ) ],
34
- {
35
- cwd: config.workDirectoryPath,
36
- commandOptions: [ '--rm' ],
37
- log: config.debug,
38
- }
39
- ).then(
40
- (output) => {
41
- // Remove the Container information and new lines.
42
- output.err = output.err.replace(/\s*Container .*Running\n|\n/g, '')
43
- output.out = output.out.replace(/\s*Container .*Running\n|\n/g, '')
44
-
45
- return '' !== output.out ? output.out : output.err;
46
- },
47
- (output) => {
48
- // Remove the Container information and new lines.
49
- output.err = output.err.replace(/\s*Container .*Running\n|\n/g, '')
50
-
51
- return false;
52
- }
53
- );
54
-
55
- } catch(error) {
56
- console.log(error)
57
-
58
- process.exit( 1 );
59
- }
60
-
61
- }
62
-
63
-
64
- module.exports = {
65
- runDockerCmds
66
- };