@caweb/cli 1.1.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 (51) hide show
  1. package/README.md +62 -27
  2. package/bin/caweb +1 -1
  3. package/bin/wp-cli.phar +0 -0
  4. package/commands/a11y.js +74 -0
  5. package/commands/blocks/create-block.js +109 -0
  6. package/commands/blocks/update-block.js +60 -0
  7. package/commands/build.js +73 -0
  8. package/commands/env/destroy.js +49 -0
  9. package/{lib/commands → commands/env}/start.js +30 -27
  10. package/{lib/commands → commands/env}/stop.js +4 -10
  11. package/{lib/commands → commands}/index.js +51 -39
  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} +32 -55
  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 +40 -0
  23. package/lib/cli.js +129 -63
  24. package/lib/env.js +3 -11
  25. package/lib/helpers.js +109 -0
  26. package/lib/index.js +28 -0
  27. package/lib/spinner.js +10 -7
  28. package/lib/{caweb.js → wordpress/caweb.js} +1 -1
  29. package/lib/{divi.js → wordpress/divi.js} +1 -1
  30. package/lib/{download-sources.js → wordpress/download-sources.js} +75 -79
  31. package/lib/wordpress/index.js +16 -0
  32. package/lib/{options.js → wordpress/options.js} +1 -1
  33. package/lib/{wordpress.js → wordpress/wordpress.js} +4 -8
  34. package/package.json +42 -27
  35. package/template/assets/css/popover.css +80 -0
  36. package/template/assets/js/popover.js +30 -0
  37. package/template/block/edit.js.mustache +48 -0
  38. package/template/block/editor.scss.mustache +5 -0
  39. package/template/block/index.js.mustache +40 -0
  40. package/template/block/save.js.mustache +21 -0
  41. package/template/block/style.scss.mustache +6 -0
  42. package/template/index.cjs +48 -0
  43. package/template/plugin/$slug.php.mustache +135 -0
  44. package/template/plugin/core/cdec-api.php.mustache +44 -0
  45. package/template/plugin/core/filters.php.mustache +111 -0
  46. package/template/plugin/core/functions.php.mustache +25 -0
  47. package/template/plugin/inc/renderer.php.mustache +25 -0
  48. package/lib/commands/destroy.js +0 -66
  49. package/lib/commands/test.js +0 -46
  50. package/lib/docker.js +0 -68
  51. /package/{lib/commands → commands/tasks}/shell.js +0 -0
@@ -0,0 +1,135 @@
1
+ <?php
2
+ /**
3
+ * Plugin Name: {{title}}
4
+ {{#pluginURI}}
5
+ * Plugin URI: {{{pluginURI}}}
6
+ {{/pluginURI}}
7
+ {{#description}}
8
+ * Description: {{description}}
9
+ {{/description}}
10
+ * Version: {{version}}
11
+ * Requires at least: 6.2
12
+ * Requires PHP: 8.1
13
+ {{#author}}
14
+ * Author: {{author}}
15
+ {{/author}}
16
+ {{#license}}
17
+ * License: {{license}}
18
+ {{/license}}
19
+ {{#licenseURI}}
20
+ * License URI: {{{licenseURI}}}
21
+ {{/licenseURI}}
22
+ * Text Domain: {{textdomain}}
23
+ {{#domainPath}}
24
+ * Domain Path: {{{domainPath}}}
25
+ {{/domainPath}}
26
+ {{#updateURI}}
27
+ * Update URI: {{{updateURI}}}
28
+ {{/updateURI}}
29
+ *
30
+ * @package cagov-design-system
31
+ */
32
+
33
+ if ( ! defined('{{slugPascalCase}}_URI') ){
34
+ $cagov_design_system_{{slugSnakeCase}}_doc_root = isset( $_SERVER['DOCUMENT_ROOT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) ) : '';
35
+ define( '{{slugPascalCase}}_URI', esc_url( str_replace( $cagov_design_system_{{slugSnakeCase}}_doc_root, '', __DIR__ ) ) );
36
+ }
37
+
38
+ if ( ! defined( 'CAGOV_DESIGN_SYSTEM_DEBUG' ) ) {
39
+ define( 'CAGOV_DESIGN_SYSTEM_DEBUG', false );
40
+ }
41
+
42
+ // Include {{title}} Core Functionality.
43
+ foreach ( glob( __DIR__ . '/core/*.php' ) as $file ) {
44
+ require_once $file;
45
+ }
46
+
47
+ // Include {{title}} Functionality.
48
+ foreach ( glob( __DIR__ . '/inc/*.php' ) as $file ) {
49
+ require_once $file;
50
+ }
51
+
52
+ /**
53
+ * Plugin API/Action Reference
54
+ * Actions Run During a Typical Request
55
+ *
56
+ * @link https://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_a_Typical_Request
57
+ */
58
+ add_action( 'init', 'cagov_design_system_{{slugSnakeCase}}_init' );
59
+ add_action( 'wp_enqueue_scripts', 'cagov_design_system_{{slugSnakeCase}}_wp_enqueue_scripts' );
60
+
61
+ if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_init' ) ) {
62
+ /**
63
+ * {{title}} Initialization
64
+ *
65
+ * Fires after WordPress has finished loading but before any headers are sent.
66
+ * Include Gutenberg Block assets by getting the index file of each block build file.
67
+ *
68
+ * @link https://developer.wordpress.org/reference/hooks/init/
69
+ * @return void
70
+ */
71
+ function cagov_design_system_{{slugSnakeCase}}_init() {
72
+ global $pagenow;
73
+
74
+ if ( ! function_exists( 'get_plugin_data' ) ) {
75
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
76
+ }
77
+
78
+ $version = get_plugin_data( __FILE__ )['Version'];
79
+
80
+ /**
81
+ * Enqueues the default ThickBox js and css. (if not on the login page or customizer page)
82
+ *
83
+ * @link https://developer.wordpress.org/reference/functions/add_thickbox/
84
+ */
85
+ if ( ! in_array( $pagenow, array( 'wp-login.php', 'customize.php' ), true ) ) {
86
+ add_thickbox();
87
+ }
88
+
89
+ // if editing a page/post register compiled Gutenberg Block bundles.
90
+ if ( in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
91
+
92
+ wp_enqueue_style( 'cagov-design-system-{{slug}}', cagov_design_system_{{slugSnakeCase}}_get_min_file( '/css/{{slug}}.css' ), array(), $version );
93
+ }
94
+
95
+ $block_args = array(
96
+ 'render_callback' => 'cagov_design_system_{{slugSnakeCase}}_block_renderer',
97
+ );
98
+
99
+ /**
100
+ * Registers the block using the metadata loaded from the `block.json` file.
101
+ * Behind the scenes, it registers also all assets so they can be enqueued
102
+ * through the block editor in the corresponding context.
103
+ *
104
+ * @see https://developer.wordpress.org/reference/functions/register_block_type/
105
+ */
106
+ register_block_type( __DIR__ . '/build', $block_args );
107
+ }
108
+ }
109
+
110
+ if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_wp_enqueue_scripts' ) ) {
111
+ /**
112
+ * Register {{title}} scripts/styles
113
+ *
114
+ * Fires when scripts and styles are enqueued.
115
+ *
116
+ * @category add_action( 'wp_enqueue_scripts', 'cagov_design_system_{{slugSnakeCase}}_wp_enqueue_scripts' );
117
+ * @link https://developer.wordpress.org/reference/hooks/wp_enqueue_scripts/
118
+ *
119
+ * @return void
120
+ */
121
+ function cagov_design_system_{{slugSnakeCase}}_wp_enqueue_scripts() {
122
+
123
+ if ( ! function_exists( 'get_plugin_data' ) ) {
124
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
125
+ }
126
+
127
+ $version = get_plugin_data( __FILE__ )['Version'];
128
+
129
+ // Register compiled Gutenberg Block bundles.
130
+ wp_enqueue_script( 'cagov-design-system-{{slug}}', cagov_design_system_{{slugSnakeCase}}_get_min_file( '/js/{{slug}}.js', 'js' ), array(), $version, true );
131
+
132
+ wp_enqueue_style( 'cagov-design-system-{{slug}}', cagov_design_system_{{slugSnakeCase}}_get_min_file( '/css/{{slug}}.css' ), array(), $version );
133
+
134
+ }
135
+ }
@@ -0,0 +1,44 @@
1
+ <?php
2
+ /**
3
+ * {{title}} CDEC REST API
4
+ *
5
+ * @see https://cdec.water.ca.gov/resapp/
6
+ *
7
+ * @package cagov-design-system
8
+ */
9
+
10
+ if ( ! function_exists( 'cagov_design_system_cdec_reservoir_conditions_api' ) ) {
11
+ /**
12
+ * Retrieve data from the CDEC Reservoir API
13
+ *
14
+ * @see https://cdec.water.ca.gov/resapp/service/res/conditions
15
+ * @param string $station_id Major reservoirs station that were recommended by CDEC.
16
+ * @return string
17
+ */
18
+ function cagov_design_system_cdec_reservoir_conditions_api( $station_id = '' ) {
19
+ $result = 'No Results';
20
+
21
+ if ( empty( $station_id ) ) {
22
+ return $result;
23
+ }
24
+
25
+ $date = gmdate( 'Y-m-d' );
26
+
27
+ $url = "https://cdec.water.ca.gov/resapp/service/res/conditions?date=$date&stationIds=$station_id";
28
+
29
+ $args = array(
30
+ 'headers' => array(
31
+ 'Content-Type' => 'application/json',
32
+ ),
33
+ );
34
+
35
+ $response = wp_remote_get( $url, $args );
36
+
37
+ if ( 200 === wp_remote_retrieve_response_code( $response ) ) {
38
+ $result = wp_remote_retrieve_body( $response );
39
+
40
+ return json_decode( $result, true )[0];
41
+ }
42
+
43
+ }
44
+ }
@@ -0,0 +1,111 @@
1
+ <?php
2
+ /**
3
+ * {{title}} Filters
4
+ *
5
+ * @package cagov-design-system
6
+ */
7
+
8
+ global $wp_version;
9
+
10
+ $cagov_design_system_is_under_5_8 = version_compare( $wp_version, '5.8', '<' ) ? '' : '_all';
11
+
12
+ add_filter( "block_categories$cagov_design_system_is_under_5_8", 'cagov_design_system_block_categories', 10, 2 );
13
+ add_filter( 'script_loader_tag', 'cagov_design_system_{{slugSnakeCase}}_script_loader_tag', 10, 3 );
14
+ add_filter( "allowed_block_types$cagov_design_system_is_under_5_8", 'cagov_design_system_allowed_block_types' );
15
+
16
+ if ( ! function_exists( 'cagov_design_system_block_categories' ) ) {
17
+ /**
18
+ * Register {{title}} Gutenberg Block categories to the Block editor
19
+ *
20
+ * @link https://developer.wordpress.org/reference/hooks/block_categories_all/
21
+ *
22
+ * @param array $categories Array of categories for block types.
23
+ * @param WP_Block_Editor_Context $post The current block editor context.
24
+ * @return array
25
+ */
26
+ function cagov_design_system_block_categories( $categories, $post ) {
27
+ return array_merge(
28
+ array(
29
+ array(
30
+ 'slug' => 'cagov-design-system',
31
+ 'title' => 'CA Design System',
32
+ ),
33
+ ),
34
+ array(
35
+ array(
36
+ 'slug' => 'cagov-data-viz',
37
+ 'title' => 'CA Data Visualization',
38
+ ),
39
+ ),
40
+ $categories
41
+ );
42
+ }
43
+ }
44
+
45
+ if ( ! function_exists( 'cagov_design_system_allowed_block_types' ) ) {
46
+ /**
47
+ * {{title}} Allowed Block Types
48
+ *
49
+ * Removes all blocks or patterns from Gutenberg and returns {{title}} Blocks.
50
+ *
51
+ * @link https://developer.wordpress.org/reference/hooks/allowed_block_types_all/
52
+ *
53
+ * @param bool|array $allowed_blocks Array of block type slugs, or boolean to enable/disable all. Default true (all registered block types supported).
54
+ * @return array
55
+ */
56
+ function cagov_design_system_allowed_block_types( $allowed_blocks ) {
57
+
58
+ // if not debugging, return all blocks.
59
+ if ( ! CAGOV_DESIGN_SYSTEM_DEBUG ) {
60
+ return $allowed_blocks;
61
+ }
62
+
63
+ remove_theme_support( 'core-block-patterns' );
64
+
65
+ // Core Components.
66
+ $core = array(
67
+ 'core/image',
68
+ 'core/paragraph',
69
+ 'core/button',
70
+ 'core/table',
71
+ 'core/heading',
72
+ 'core/list',
73
+ 'core/custom-html',
74
+ 'core/classic',
75
+ );
76
+
77
+ // Dynamically get a list of the cagov-design-system blocks.
78
+ $cagov_blocks = array();
79
+ /*
80
+ array_map(
81
+ function( $b ) {
82
+ return 'cagov-design-system/' . basename( $b );
83
+ },
84
+ glob( '/blocks/*' )
85
+ );
86
+ */
87
+
88
+ // Return the desired components.
89
+ return array_merge( $core, $cagov_blocks );
90
+ }
91
+ }
92
+
93
+ if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_script_loader_tag' ) ) {
94
+ /**
95
+ * Filters the HTML script tag of an enqueued script.
96
+ *
97
+ * @param mixed $tag The <script> tag for the enqueued script.
98
+ * @param mixed $handle The script's registered handle.
99
+ * @param mixed $src The script's source URL.
100
+ * @return string
101
+ */
102
+ function cagov_design_system_{{slugSnakeCase}}_script_loader_tag( $tag, $handle, $src ) {
103
+ // Register script as module.
104
+ if ( 'cagov-design-system-{{slug}}' === $handle ) {
105
+ $tag = sprintf( '<script type="module" id="cagov-design-system-{{slug}}-js" src="%1$s"></script>', $src );
106
+ }
107
+
108
+ return $tag;
109
+ }
110
+ }
111
+
@@ -0,0 +1,25 @@
1
+ <?php
2
+ /**
3
+ * {{title}} Helper Functions
4
+ *
5
+ * @package cagov-design-system
6
+ */
7
+
8
+ if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_get_min_file' ) ) {
9
+ /**
10
+ * Load Minified Version of a file
11
+ *
12
+ * @param string $f File to load.
13
+ * @param string $ext Extension of file, default css.
14
+ *
15
+ * @return string
16
+ */
17
+ function cagov_design_system_{{slugSnakeCase}}_get_min_file( $f, $ext = 'css' ) {
18
+ // if not debugging and a minified version exists load it.
19
+ if ( ! CAGOV_DESIGN_SYSTEM_DEBUG && file_exists( __DIR__ . str_replace( ".$ext", ".min.$ext", $f ) ) ) {
20
+ return {{slugPascalCase}}_URI . str_replace( ".$ext", ".min.$ext", $f );
21
+ } else {
22
+ return {{slugPascalCase}}_URI . $f;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,25 @@
1
+ <?php
2
+ /**
3
+ * {{title}} Dynamic Renderer Functions
4
+ *
5
+ * @package {{namespace}}
6
+ */
7
+
8
+ if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_block_renderer' ) ) {
9
+ /**
10
+ * Dynamic Renderer for {{title}} Block
11
+ *
12
+ * @see https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/creating-dynamic-blocks/
13
+ *
14
+ * @param array $attributes Block attributes.
15
+ * @param string $content Block content.
16
+ * @param WP_Block_Type $block Current Block Type.
17
+ * @return string Rendered block type output.
18
+ */
19
+ function cagov_design_system_{{slugSnakeCase}}_block_renderer( $attributes, $content, $block ) {
20
+
21
+ $output = sprintf( '<p>Render Block Output</p>' );
22
+
23
+ return $output;
24
+ }
25
+ }
@@ -1,66 +0,0 @@
1
- import path from 'node:path';
2
- import loadConfig from '@wordpress/env/lib/config/load-config.js';
3
- import { spawn } from 'node:child_process';
4
- import { v2 as dockerCompose } from 'docker-compose';
5
-
6
- import { default as wpEnvDestroy } from '@wordpress/env/lib/commands/destroy.js';
7
-
8
- /**
9
- * Internal dependencies
10
- */
11
-
12
- /**
13
- * Promisified dependencies
14
- */
15
-
16
- /**
17
- * Starts the development server.
18
- *
19
- * @param {Object} options
20
- * @param {Object} options.spinner A CLI spinner which indicates progress.
21
- * @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
22
- * @param {boolean} options.debug True if debug mode is enabled.
23
- *
24
- */
25
- export default async function destroy({
26
- spinner,
27
- scripts,
28
- debug,
29
- }) {
30
-
31
- await wpEnvDestroy({spinner, scripts, debug });
32
-
33
- // wp-env destroy completed successfully if spinner.text reads.
34
- if( 'Removed WordPress environment.' === spinner.text ){
35
- spinner.text = "Cleaning up...";
36
-
37
- // Stop phpMyAdmin as well
38
- // wp-env doesn't destroy the phpmyadmin image so we have to do it ourselves.
39
- await new Promise( (resolve, reject) => {
40
- const childProc = spawn(
41
- 'docker',
42
- [
43
- 'image',
44
- 'rm',
45
- 'phpmyadmin'
46
- ],
47
- { stdio: 'ignore' },
48
- spinner
49
- );
50
-
51
- childProc.on( 'error', reject );
52
- childProc.on( 'exit', ( code ) => {
53
- // Code 130 is set if the user tries to exit with ctrl-c before using
54
- // ctrl-d (so it is not an error which should fail the script.)
55
- if ( code === 0 || code === 130 ) {
56
- resolve();
57
- } else {
58
- reject( `Command failed with exit code ${ code }` );
59
- }
60
- } );
61
- });
62
- spinner.text = "Removed WordPress environment.'";
63
-
64
- }
65
-
66
- }
@@ -1,46 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import path from 'node:path';
5
- import loadConfig from '@wordpress/env/lib/config/load-config.js';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import { runCLICmds } from '../docker.js';
11
- import { activateCAWeb } from '../caweb.js';
12
-
13
- /**
14
- * Promisified dependencies
15
- */
16
-
17
- /**
18
- * Test code.
19
- *
20
- * @param {Object} options
21
- * @param {Object} options.spinner A CLI spinner which indicates progress.
22
- * @param {boolean} options.environment Which environment to test in.
23
- * @param {boolean} options.debug True if debug mode is enabled.
24
- */
25
- export default async function test({
26
- spinner,
27
- debug,
28
- environment
29
- } ) {
30
-
31
- spinner.text = "Testing Code Functionality";
32
- const config = await loadConfig(path.resolve('.'));
33
-
34
- let result = await runCLICmds(
35
- 'development',
36
- ['wp --version'],
37
- config,
38
- spinner
39
- )
40
-
41
-
42
- console.log( result );
43
-
44
- spinner.text = "Done!";
45
-
46
- };
package/lib/docker.js DELETED
@@ -1,68 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { spawn } from 'node:child_process';
5
- import dockerCompose from 'docker-compose';
6
- import path from 'node:path';
7
- import loadConfig from '@wordpress/env/lib/config/load-config.js';
8
- import getHostUser from '@wordpress/env/lib/get-host-user.js';
9
- import { env } from 'node:process';
10
-
11
-
12
- /**
13
- * Internal dependencies
14
- */
15
-
16
- /**
17
- * Runs commands on the given WordPress environment.
18
- *
19
- * @param {string} environment Which environment to run docker command on.
20
- * @param {string[]} cmds Array of commands to run.
21
- * @param {WPConfig} config The wp-env config object.
22
- * @param {Object} spinner A CLI spinner which indicates progress.
23
- *
24
- * @returns {Promise}
25
- */
26
- async function runCLICmds(
27
- environment,
28
- cmds,
29
- config,
30
- spinner
31
- ) {
32
-
33
- // We return the promise whether there is an output or an error.
34
- return await dockerCompose.run(
35
- environment === 'development' ? 'cli' : 'tests-cli',
36
- [ 'bash', '-c', cmds.join( ' && ' ) ],
37
- {
38
- cwd: config.workDirectoryPath,
39
- commandOptions: [],
40
- log: config.debug,
41
- callback: (buffer, result) => {
42
- if( config.debug ){
43
- spinner.text = buffer.toString();
44
- }
45
- }
46
- }
47
- ).then(
48
- (output) => {
49
- // Remove the Container information and new lines.
50
- output.err = output.err.replace(/\s*Container .*Running\n|\n/g, '')
51
- output.out = output.out.replace(/\s*Container .*Running\n|\n/g, '')
52
-
53
- return '' !== output.out ? output.out : output.err;
54
- },
55
- (error) => {
56
- // Remove the Container information and new lines.
57
- error.err = error.err.replace(/\s*Container .*Running\n|\n/g, '')
58
-
59
- return error;
60
- }
61
- );
62
-
63
- }
64
-
65
-
66
- export {
67
- runCLICmds
68
- };
File without changes