@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.
- package/README.md +62 -27
- package/bin/caweb +3 -17
- package/lib/admin.js +40 -0
- package/lib/caweb.js +20 -17
- package/lib/cli.js +224 -142
- package/lib/commands/blocks/create-block.js +110 -0
- package/lib/commands/blocks/update-block.js +66 -0
- package/lib/commands/destroy.js +56 -0
- package/lib/commands/index.js +33 -9
- package/lib/commands/shell.js +2 -3
- package/lib/commands/start.js +57 -69
- package/lib/commands/stop.js +41 -0
- package/lib/commands/tasks/update-plugins.js +15 -8
- package/lib/commands/test.js +17 -70
- package/lib/configs.js +41 -21
- package/lib/divi.js +28 -26
- package/lib/download-sources.js +15 -15
- package/lib/env.js +3 -6
- package/lib/options.js +2 -2
- package/lib/spinner.js +70 -0
- package/lib/template/assets/css/popover.css +80 -0
- package/lib/template/assets/js/popover.js +30 -0
- package/lib/template/block/edit.js.mustache +48 -0
- package/lib/template/block/editor.scss.mustache +5 -0
- package/lib/template/block/index.js.mustache +40 -0
- package/lib/template/block/save.js.mustache +21 -0
- package/lib/template/block/style.scss.mustache +6 -0
- package/lib/template/index.cjs +48 -0
- package/lib/template/plugin/$slug.php.mustache +135 -0
- package/lib/template/plugin/core/cdec-api.php.mustache +44 -0
- package/lib/template/plugin/core/filters.php.mustache +111 -0
- package/lib/template/plugin/core/functions.php.mustache +25 -0
- package/lib/template/plugin/inc/renderer.php.mustache +25 -0
- package/lib/utils.js +150 -0
- package/lib/wordpress.js +45 -27
- package/package.json +10 -4
- package/lib/commands/tasks/index.js +0 -13
- package/lib/docker.js +0 -66
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers a new block provided a unique name and an object defining its behavior.
|
|
3
|
+
*
|
|
4
|
+
* @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block
|
|
5
|
+
*/
|
|
6
|
+
import { registerBlockType } from '@wordpress/blocks';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
|
|
10
|
+
* All files containing `style` keyword are bundled together. The code used
|
|
11
|
+
* gets applied both to the front of your site and to the editor. All other files
|
|
12
|
+
* get applied to the editor only.
|
|
13
|
+
*
|
|
14
|
+
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
|
|
15
|
+
*/
|
|
16
|
+
import './style.scss';
|
|
17
|
+
import './editor.scss';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
import Edit from './edit';
|
|
23
|
+
import save from './save';
|
|
24
|
+
import metadata from './block.json';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Every block starts by registering a new block type definition.
|
|
28
|
+
*
|
|
29
|
+
* @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block
|
|
30
|
+
*/
|
|
31
|
+
registerBlockType( metadata.name, {
|
|
32
|
+
/**
|
|
33
|
+
* @see ./edit.js
|
|
34
|
+
*/
|
|
35
|
+
edit: Edit,
|
|
36
|
+
/**
|
|
37
|
+
* @see ./save.js
|
|
38
|
+
*/
|
|
39
|
+
save,
|
|
40
|
+
} );
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hook that is used to mark the block wrapper element.
|
|
3
|
+
* It provides all the necessary props like the class name.
|
|
4
|
+
*
|
|
5
|
+
* @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps
|
|
6
|
+
*/
|
|
7
|
+
import { InnerBlocks } from '@wordpress/block-editor';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The save function defines the way in which the different attributes should
|
|
11
|
+
* be combined into the final markup, which is then serialized by the block
|
|
12
|
+
* editor into `post_content`.
|
|
13
|
+
*
|
|
14
|
+
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save
|
|
15
|
+
*
|
|
16
|
+
* @return {WPElement} Element to render.
|
|
17
|
+
*/
|
|
18
|
+
export default function save(props) {
|
|
19
|
+
return <InnerBlocks.Content />;
|
|
20
|
+
}
|
|
21
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
const { join } = require( 'path' );
|
|
5
|
+
const { capitalCase } = require( 'change-case' );
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
const blockSlug = process.argv[ 2 ];
|
|
11
|
+
const blockSlugTitle = capitalCase( blockSlug );
|
|
12
|
+
|
|
13
|
+
const customScripts = {};
|
|
14
|
+
|
|
15
|
+
const npmDependencies = [
|
|
16
|
+
'@wordpress/icons@9.22.0'
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const npmDevDependencies = [];
|
|
20
|
+
|
|
21
|
+
// assetsPath: join( __dirname, 'assets' ),
|
|
22
|
+
module.exports = {
|
|
23
|
+
pluginTemplatesPath: join( __dirname, 'plugin' ),
|
|
24
|
+
blockTemplatesPath: join( __dirname, 'block' ),
|
|
25
|
+
defaultValues: {
|
|
26
|
+
pluginURI: `https://github.com/CAWebPublishing/${ blockSlug }`,
|
|
27
|
+
plugin: true,
|
|
28
|
+
description: `${ blockSlugTitle } Gutenberg Block`,
|
|
29
|
+
version: '1.2.0',
|
|
30
|
+
author: 'CAWebPublishing',
|
|
31
|
+
license: 'GPL-2.0-or-later',
|
|
32
|
+
licenseURI: 'https://www.gnu.org/licenses/gpl-2.0.html',
|
|
33
|
+
namespace: 'caweb',
|
|
34
|
+
category: 'cagov-design-system',
|
|
35
|
+
textdomain: 'cagov-design-system',
|
|
36
|
+
dashicon: 'format-aside',
|
|
37
|
+
supports: {
|
|
38
|
+
html: true,
|
|
39
|
+
},
|
|
40
|
+
attributes: {},
|
|
41
|
+
example: {
|
|
42
|
+
attributes: {}
|
|
43
|
+
},
|
|
44
|
+
customScripts: customScripts,
|
|
45
|
+
npmDependencies: npmDependencies,
|
|
46
|
+
npmDevDependencies: npmDevDependencies,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
@@ -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
|
+
}
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
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
|
+
* Runs command directly.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} cmd Command to run.
|
|
69
|
+
* @param {string[]} args List of command arguments.
|
|
70
|
+
* @param {string[]} opts List of spawn options.
|
|
71
|
+
* @param {Object} spinner A CLI spinner which indicates progress.
|
|
72
|
+
* @param {boolean} debug True if debug mode is enabled.
|
|
73
|
+
*
|
|
74
|
+
* @returns {Promise}
|
|
75
|
+
*/
|
|
76
|
+
async function runCmd(cmd, args,spinner, opts = { stdio: 'pipe' }, debug = false){
|
|
77
|
+
// fix various commands.
|
|
78
|
+
switch (cmd) {
|
|
79
|
+
case 'npm':
|
|
80
|
+
case 'npx':
|
|
81
|
+
/**
|
|
82
|
+
* On Windows we run npm.cmd, on Linux we run npm
|
|
83
|
+
*/
|
|
84
|
+
cmd += /^win/.test(process.platform) ? '.cmd' : '';
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// save output for handling
|
|
89
|
+
let output = opts.stdio;
|
|
90
|
+
|
|
91
|
+
return await new Promise( (resolve, reject) => {
|
|
92
|
+
let result = [];
|
|
93
|
+
const childProc = spawn(
|
|
94
|
+
cmd,
|
|
95
|
+
args,
|
|
96
|
+
{
|
|
97
|
+
...opts,
|
|
98
|
+
stdio: 'pipe' // output is always piped and handled when stdout receives data.
|
|
99
|
+
},
|
|
100
|
+
spinner
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
childProc.stdout.on( 'data', (data) => {
|
|
104
|
+
// remove new lines from data
|
|
105
|
+
data = data.toString().replace('\n', '');
|
|
106
|
+
|
|
107
|
+
// push all data to results array if piping data
|
|
108
|
+
if( '\n' !== data && '' !== data && data.length ){
|
|
109
|
+
// output accordingly.
|
|
110
|
+
switch( output ){
|
|
111
|
+
case 'initial': // write output to spinner text
|
|
112
|
+
spinner.text = data;
|
|
113
|
+
case 'inherit': // write output to persistent spinner text
|
|
114
|
+
spinner.stopAndPersist({
|
|
115
|
+
text: data
|
|
116
|
+
});
|
|
117
|
+
break;
|
|
118
|
+
case 'pipe': // save output to result array and output on exit
|
|
119
|
+
default:
|
|
120
|
+
result.push( data );
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
childProc.on( 'error', reject );
|
|
127
|
+
childProc.on( 'exit', ( code ) => {
|
|
128
|
+
// resolved with no issues return result array
|
|
129
|
+
if ( code === 0 ) {
|
|
130
|
+
resolve(result.join('\n'));
|
|
131
|
+
// if there was an error
|
|
132
|
+
} else {
|
|
133
|
+
if( debug ){
|
|
134
|
+
// if debugging return exit code
|
|
135
|
+
reject( `Command failed with exit code ${ code }` );
|
|
136
|
+
}else{
|
|
137
|
+
// resolve as false.
|
|
138
|
+
resolve(false);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} );
|
|
142
|
+
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export {
|
|
148
|
+
runCLICmds,
|
|
149
|
+
runCmd
|
|
150
|
+
};
|