@caweb/cli 1.2.0 → 1.3.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 (49) hide show
  1. package/README.md +1 -1
  2. package/bin/caweb +1 -1
  3. package/bin/wp-cli.phar +0 -0
  4. package/commands/a11y.js +74 -0
  5. package/{lib/commands → commands}/blocks/create-block.js +7 -8
  6. package/{lib/commands → commands}/blocks/update-block.js +3 -9
  7. package/commands/build.js +73 -0
  8. package/{lib/commands → commands/env}/destroy.js +15 -22
  9. package/{lib/commands → commands/env}/start.js +26 -27
  10. package/{lib/commands → commands/env}/stop.js +4 -10
  11. package/{lib/commands → commands}/index.js +51 -43
  12. package/commands/serve.js +78 -0
  13. package/commands/sync.js +498 -0
  14. package/{lib/commands → commands}/tasks/update-plugins.js +2 -2
  15. package/commands/test.js +100 -0
  16. package/configs/aceconfig.js +28 -0
  17. package/{lib/configs.js → configs/docker-compose.js} +30 -83
  18. package/configs/webpack.config.js +119 -0
  19. package/configs/wp-env.js +76 -0
  20. package/gen/parser.js +166 -0
  21. package/gen/site-generator.js +111 -0
  22. package/lib/admin.js +1 -1
  23. package/lib/cli.js +105 -63
  24. package/lib/helpers.js +109 -0
  25. package/lib/index.js +28 -0
  26. package/lib/spinner.js +10 -7
  27. package/lib/{caweb.js → wordpress/caweb.js} +1 -1
  28. package/lib/{divi.js → wordpress/divi.js} +1 -1
  29. package/lib/{download-sources.js → wordpress/download-sources.js} +74 -78
  30. package/lib/wordpress/index.js +16 -0
  31. package/lib/{wordpress.js → wordpress/wordpress.js} +4 -8
  32. package/package.json +41 -27
  33. package/lib/commands/test.js +0 -46
  34. package/lib/utils.js +0 -150
  35. /package/{lib/commands → commands/tasks}/shell.js +0 -0
  36. /package/lib/{options.js → wordpress/options.js} +0 -0
  37. /package/{lib/template → template}/assets/css/popover.css +0 -0
  38. /package/{lib/template → template}/assets/js/popover.js +0 -0
  39. /package/{lib/template → template}/block/edit.js.mustache +0 -0
  40. /package/{lib/template → template}/block/editor.scss.mustache +0 -0
  41. /package/{lib/template → template}/block/index.js.mustache +0 -0
  42. /package/{lib/template → template}/block/save.js.mustache +0 -0
  43. /package/{lib/template → template}/block/style.scss.mustache +0 -0
  44. /package/{lib/template → template}/index.cjs +0 -0
  45. /package/{lib/template → template}/plugin/$slug.php.mustache +0 -0
  46. /package/{lib/template → template}/plugin/core/cdec-api.php.mustache +0 -0
  47. /package/{lib/template → template}/plugin/core/filters.php.mustache +0 -0
  48. /package/{lib/template → template}/plugin/core/functions.php.mustache +0 -0
  49. /package/{lib/template → template}/plugin/inc/renderer.php.mustache +0 -0
package/README.md CHANGED
@@ -7,7 +7,7 @@ The following WordPress packages are used:
7
7
  [create-block](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/)
8
8
 
9
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.
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
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
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
13
  - git is installed.
package/bin/caweb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  import cli from '../lib/cli.js';
4
4
 
Binary file
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ import path from 'path';
7
+ import fs from 'fs';
8
+ import resolveBin from 'resolve-bin';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ // Our default A11y Checker Configuration
14
+ import defaultConfig from '../configs/aceconfig.js';
15
+
16
+ import {
17
+ runCmd,
18
+ } from '../lib/index.js';
19
+
20
+
21
+
22
+ /**
23
+ * Run accessibility checks
24
+ *
25
+ * @param {Object} options
26
+ * @param {Object} options.spinner A CLI spinner which indicates progress.
27
+ * @param {boolean} options.debug True if debug mode is enabled.
28
+ */
29
+ export default async function a11y({
30
+ spinner,
31
+ debug,
32
+ } ) {
33
+
34
+ // Spinner not needed at the moment
35
+ spinner.stop()
36
+ const {
37
+ ruleArchive,
38
+ policies,
39
+ failLevels,
40
+ reportLevels,
41
+ outputFolder,
42
+ outputFormat,
43
+ outputFilenameTimestamp
44
+ } = defaultConfig;
45
+
46
+
47
+ // pass any arguments from the cli
48
+ // overwriting our default config flags.
49
+ // users can overwrite any values by creating a .achecker.yml or aceconfig.js.
50
+ let acheckerArgs = [
51
+ '--ruleArchive',
52
+ ruleArchive,
53
+ '--policies',
54
+ Array.isArray(policies) ? policies.join(',') : policies,
55
+ '--failLevels',
56
+ Array.isArray(failLevels) ? failLevels.join(',') : failLevels,
57
+ '--reportLevels',
58
+ Array.isArray(reportLevels) ? reportLevels.join(',') : reportLevels,
59
+ '--outputFolder',
60
+ outputFolder,
61
+ '--outputFormat',
62
+ outputFormat,
63
+ '---outputFilenameTimestamp',
64
+ outputFilenameTimestamp,
65
+ process.argv.pop()
66
+ ];
67
+
68
+ // run webpack with our arguments.
69
+ await runCmd(
70
+ 'achecker',
71
+ acheckerArgs,
72
+ )
73
+
74
+ };
@@ -1,19 +1,18 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import path from 'node:path';
5
- import fs from 'fs-extra';
6
- import { spawn } from 'node:child_process';
4
+ import path from 'path';
5
+ import fs from 'fs';
7
6
  import inquirer from 'inquirer';
8
7
 
9
8
  /**
10
9
  * Internal dependencies
11
10
  */
12
- import {runCmd} from '../../utils.js';
11
+ import {runCmd, projectPath} from '../../lib/index.js';
13
12
  import updateBlock from './update-block.js';
14
13
 
15
- const localPath = path.resolve( path.join(process.cwd(), 'node_modules/@caweb/cli/package.json') )
16
- const pkg = JSON.parse( await fs.readFile(localPath) );
14
+ const localFile = path.join(projectPath, 'package.json');
15
+ const pkg = JSON.parse( fs.readFileSync(localFile) );
17
16
 
18
17
  /**
19
18
  * Get NPM Package Latest Version
@@ -74,7 +73,7 @@ export default async function createBlock({
74
73
  [
75
74
  `@wordpress/create-block`,
76
75
  slug,
77
- '--template=' + path.resolve( path.join(process.cwd(), 'node_modules/@caweb/cli/lib/template/index.cjs') )
76
+ '--template=' + path.join(projectPath, 'template', 'index.cjs')
78
77
  ],
79
78
  spinner,
80
79
  {
@@ -96,7 +95,7 @@ export default async function createBlock({
96
95
  ],
97
96
  spinner,
98
97
  {
99
- cwd: path.resolve( path.join(process.cwd(), slug ) ),
98
+ cwd: path.join(process.cwd(), slug ),
100
99
  stdio: 'inherit'
101
100
  }
102
101
  )
@@ -1,22 +1,16 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import path from 'node:path';
5
- import fs from 'fs-extra';
6
- import { spawn } from 'node:child_process';
4
+ import path from 'path';
5
+ import fs from 'fs';
7
6
 
8
7
  /**
9
8
  * Internal dependencies
10
9
  */
11
- import {runCmd} from '../../utils.js';
12
10
  import createBlock from './create-block.js';
13
11
 
14
- const localPath = path.resolve( path.join(process.cwd(), 'node_modules/@caweb/cli/package.json') )
15
- const pkg = JSON.parse( await fs.readFile(localPath) );
16
-
17
-
18
12
  /**
19
- * Create Block
13
+ * Update Block
20
14
  *
21
15
  * @param {Object} options
22
16
  * @param {Object} options.spinner A CLI spinner which indicates progress.
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ import path from 'path';
7
+ import fs from 'fs';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import {
13
+ runCmd,
14
+ projectPath,
15
+ appPath
16
+ } from '../lib/index.js';
17
+
18
+
19
+ /**
20
+ * Build the current project
21
+ *
22
+ * @param {Object} options
23
+ * @param {Object} options.spinner A CLI spinner which indicates progress.
24
+ * @param {boolean} options.debug True if debug mode is enabled.
25
+ */
26
+ export default async function build({
27
+ spinner,
28
+ debug,
29
+ } ) {
30
+
31
+ // Spinner not needed at the moment
32
+ spinner.stop()
33
+
34
+ // Since we use @wordpress/scripts webpack config we can leverage
35
+ // the environment variables as well.
36
+ process.env.WP_COPY_PHP_FILES_TO_DIST = true;
37
+
38
+ // Our default Webpack Configuration
39
+ const defaultConfig = path.join( projectPath, 'configs', 'webpack.config.js' );
40
+
41
+ // pass any arguments from the cli
42
+ // add our default config as an extension.
43
+ // users can overwrite any values by creating a webconfig of their own.
44
+ let webPackArgs = [
45
+ '--mode=none',
46
+ '--progress',
47
+ '--config',
48
+ defaultConfig
49
+ ];
50
+
51
+ // CommonJS
52
+ if( fs.existsSync( path.join(appPath, 'webpack.config.cjs' ))){
53
+ webPackArgs.push(
54
+ '--config',
55
+ path.join(appPath, 'webpack.config.cjs' ),
56
+ '--merge'
57
+ )
58
+ // ESM
59
+ }else if( fs.existsSync(path.join(appPath, 'webpack.config.js' )) ){
60
+ webPackArgs.push(
61
+ '--config',
62
+ path.join(appPath, 'webpack.config.js' ),
63
+ '--merge'
64
+ )
65
+ }
66
+
67
+ // run webpack with our arguments.
68
+ await runCmd(
69
+ 'webpack',
70
+ webPackArgs,
71
+ )
72
+
73
+ };
@@ -2,9 +2,13 @@
2
2
  /**
3
3
  * External dependencies
4
4
  */
5
- import { spawn } from 'node:child_process';
6
5
  import { default as wpEnvDestroy } from '@wordpress/env/lib/commands/destroy.js';
7
6
 
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import { runCmd } from '../../lib/index.js';
11
+
8
12
  /**
9
13
  * Destroys the development server.
10
14
  *
@@ -28,27 +32,16 @@ export default async function destroy({
28
32
 
29
33
  // Stop phpMyAdmin as well
30
34
  // wp-env doesn't destroy the phpmyadmin image so we have to do it ourselves.
31
- await new Promise( (resolve, reject) => {
32
- const childProc = spawn(
33
- 'docker',
34
- [
35
- 'image',
36
- 'rm',
37
- 'phpmyadmin'
38
- ],
39
- { stdio: 'ignore' },
40
- spinner
41
- );
42
-
43
- childProc.on( 'error', reject );
44
- childProc.on( 'exit', ( code ) => {
45
- if ( code === 0 ) {
46
- resolve();
47
- } else {
48
- reject( `Command failed with exit code ${ code }` );
49
- }
50
- } );
51
- });
35
+ await runCmd(
36
+ 'docker',
37
+ [
38
+ 'image',
39
+ 'rm',
40
+ 'phpmyadmin'
41
+ ],
42
+ { stdio: 'ignore' }
43
+ )
44
+
52
45
  spinner.text = "Removed WordPress environment.'";
53
46
 
54
47
  }
@@ -1,36 +1,34 @@
1
- import path from 'node:path';
2
- import util from 'node:util';
3
- import fs from 'fs-extra';
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import path from 'path';
5
+ import fs from 'fs';
6
+ import { v2 as dockerCompose } from 'docker-compose';
4
7
  import yaml from 'js-yaml';
5
- import dockerCompose from 'docker-compose';
6
8
 
9
+ /**
10
+ * WordPress dependencies
11
+ */
7
12
  import { default as wpEnvStart} from '@wordpress/env/lib/commands/start.js';
8
- import {
9
- checkDatabaseConnection,
10
- canAccessWPORG
11
- } from '@wordpress/env/lib/wordpress.js';
12
-
13
+ import loadConfig from '@wordpress/env/lib/config/load-config.js';
13
14
  import retry from '@wordpress/env/lib/retry.js';
15
+ import { didCacheChange, getCache } from '@wordpress/env/lib/cache.js';
16
+ import { canAccessWPORG } from '@wordpress/env/lib/wordpress.js';
14
17
 
15
18
  const CONFIG_CACHE_KEY = 'config_checksum';
16
19
 
17
- import loadConfig from '@wordpress/env/lib/config/load-config.js';
18
- import { didCacheChange, getCache } from '@wordpress/env/lib/cache.js';
19
-
20
20
  /**
21
21
  * Internal dependencies
22
22
  */
23
+ import { appPath } from '../../lib/helpers.js';
24
+ import wpEnvConfig from '../../configs/wp-env.js';
25
+ import dockerConfig from '../../configs/docker-compose.js';
23
26
 
24
- import { configureCAWeb } from '../caweb.js';
25
- import {downloadSources } from '../download-sources.js';
26
- import { configureWordPress } from '../wordpress.js';
27
- import { buildWPEnvConfig, buildDockerComposeConfig } from '../configs.js';
28
-
29
- /**
30
- * Promisified dependencies
31
- */
32
- const sleep = util.promisify( setTimeout );
33
- const { writeFile } = fs.promises;
27
+ import {
28
+ configureCAWeb,
29
+ downloadSources,
30
+ configureWordPress
31
+ } from '../../lib/wordpress/index.js';
34
32
 
35
33
  /**
36
34
  * Starts the development server.
@@ -64,9 +62,9 @@ export default async function start({
64
62
  spinner.text = 'Writing configuration file...';
65
63
 
66
64
  // Write CAWeb .wp-env.json file.
67
- await writeFile(
68
- path.join(process.cwd(), '.wp-env.json'),
69
- JSON.stringify( buildWPEnvConfig(bare, multisite, plugin, theme), null, 4 )
65
+ fs.writeFileSync(
66
+ path.join(appPath, '.wp-env.json'),
67
+ JSON.stringify( wpEnvConfig(bare, multisite, plugin, theme), null, 4 )
70
68
  );
71
69
 
72
70
  // Get current wp-env cache key
@@ -107,9 +105,9 @@ export default async function start({
107
105
  }
108
106
 
109
107
  // Write docker-compose.override.yml file to workDirectoryPath.
110
- await writeFile(
108
+ fs.writeFileSync(
111
109
  path.join(workDirectoryPath, 'docker-compose.override.yml'),
112
- yaml.dump( buildDockerComposeConfig(workDirectoryPath) )
110
+ yaml.dump( dockerConfig(workDirectoryPath) )
113
111
  );
114
112
 
115
113
  // Only run configurations when config has changed.
@@ -164,6 +162,7 @@ export default async function start({
164
162
  spinner.prefixText = preText +
165
163
  `phpMyAdmin site started at http://localhost:8080\n\n`;
166
164
 
165
+
167
166
  spinner.text = 'Done!';
168
167
 
169
168
  };
@@ -1,18 +1,12 @@
1
- import path from 'node:path';
2
- import { spawn } from 'node:child_process';
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import path from 'path';
3
5
  import loadConfig from '@wordpress/env/lib/config/load-config.js';
4
6
  import { v2 as dockerCompose } from 'docker-compose';
5
7
 
6
8
  import { default as wpEnvStop } from '@wordpress/env/lib/commands/stop.js';
7
9
 
8
- /**
9
- * Internal dependencies
10
- */
11
-
12
- /**
13
- * Promisified dependencies
14
- */
15
-
16
10
  /**
17
11
  * Starts the development server.
18
12
  *
@@ -1,44 +1,52 @@
1
- /**
2
- * External dependencies
3
- */
4
-
5
- /**
6
- * These are default wp-env commands. No need to overwrite these commands
7
- */
8
- import clean from '@wordpress/env/lib/commands/clean.js';
9
- import logs from '@wordpress/env/lib/commands/logs.js';
10
- import run from '@wordpress/env/lib/commands/run.js';
11
- import installPath from '@wordpress/env/lib/commands/install-path.js';
12
-
13
- /**
14
- * Internal dependencies
15
- */
16
- import shell from './shell.js';
17
- import updatePlugins from './tasks/update-plugins.js'
18
- import createBlock from './blocks/create-block.js'
19
- import updateBlock from './blocks/update-block.js'
20
-
21
- import test from './test.js';
22
-
23
- /**
24
- * These are default wp-env commands, we overwrite these commands so we can run additional steps.
25
- */
26
- import start from './start.js';
27
- import destroy from './destroy.js';
28
- import stop from './stop.js';
29
-
30
-
31
- export {
32
- clean,
33
- logs,
34
- run,
35
- installPath,
36
- start,
37
- stop,
38
- destroy,
39
- test,
40
- shell,
41
- updatePlugins,
42
- createBlock,
43
- updateBlock
1
+ /**
2
+ * External dependencies
3
+ */
4
+ /**
5
+ * These are default wp-env commands. No need to overwrite these commands
6
+ */
7
+ import clean from '@wordpress/env/lib/commands/clean.js';
8
+ import logs from '@wordpress/env/lib/commands/logs.js';
9
+ import run from '@wordpress/env/lib/commands/run.js';
10
+ import installPath from '@wordpress/env/lib/commands/install-path.js';
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ import build from './build.js';
16
+ import serve from './serve.js';
17
+ import a11y from './a11y.js';
18
+ import shell from './tasks/shell.js';
19
+
20
+ import sync from './sync.js';
21
+
22
+ import updatePlugins from './tasks/update-plugins.js'
23
+ import createBlock from './blocks/create-block.js'
24
+ import updateBlock from './blocks/update-block.js'
25
+
26
+ import test from './test.js';
27
+
28
+ /**
29
+ * These are default wp-env commands, we overwrite these commands so we can run additional steps.
30
+ */
31
+ import start from './env/start.js';
32
+ import destroy from './env/destroy.js';
33
+ import stop from './env/stop.js';
34
+
35
+ export {
36
+ clean,
37
+ logs,
38
+ run,
39
+ installPath,
40
+ start,
41
+ stop,
42
+ destroy,
43
+ build,
44
+ serve,
45
+ a11y,
46
+ sync,
47
+ updatePlugins,
48
+ shell,
49
+ createBlock,
50
+ updateBlock,
51
+ test
44
52
  }
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ import path from 'path';
7
+ import fs from 'fs';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import {
13
+ projectPath,
14
+ appPath,
15
+ runCmd
16
+ } from '../lib/index.js';
17
+
18
+ /**
19
+ * Serves the current project
20
+ *
21
+ * @param {Object} options
22
+ * @param {Object} options.spinner A CLI spinner which indicates progress.
23
+ * @param {boolean} options.debug True if debug mode is enabled.
24
+ * @param {boolean} options.template Disables inclusion of the template page header & footer, starting off with a plain html page.
25
+ */
26
+ export default async function serve({
27
+ spinner,
28
+ debug,
29
+ template,
30
+ } ) {
31
+ spinner.stop();
32
+
33
+ // Since we use @wordpress/scripts webpack config we can leverage
34
+ // the environment variables as well.
35
+ process.env.WP_COPY_PHP_FILES_TO_DIST = true;
36
+
37
+
38
+ // This lets the parser know to include the template
39
+ // Otherwise we load a blank html page
40
+ process.env.CDT_TEMPLATE = template;
41
+
42
+
43
+ // Our default Webpack Configuration
44
+ const defaultConfig = path.join( projectPath, 'configs', 'webpack.config.js' );
45
+
46
+ let webPackArgs = [
47
+ 'serve',
48
+ '--open',
49
+ '--mode=development',
50
+ '--config',
51
+ defaultConfig
52
+ ];
53
+
54
+ // merge user configurations
55
+ // CommonJS
56
+ if( fs.existsSync(path.join( appPath, 'webpack.config.cjs' ))){
57
+ webPackArgs.push(
58
+ '--config',
59
+ path.join( appPath, 'webpack.config.cjs' ),
60
+ '--merge'
61
+ )
62
+ // ESM
63
+ }else if( fs.existsSync(path.join( appPath, 'webpack.config.js' )) ){
64
+ webPackArgs.push(
65
+ '--config',
66
+ path.join( appPath, 'webpack.config.js' ),
67
+ '--merge'
68
+ )
69
+ }
70
+
71
+ // run webpack with our configuration.
72
+ await runCmd(
73
+ 'webpack',
74
+ webPackArgs
75
+ )
76
+
77
+
78
+ };