@caweb/cli 1.3.12 → 1.3.14

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.
@@ -11,9 +11,6 @@ import inquirer from 'inquirer';
11
11
  import {runCmd, projectPath} from '../../lib/index.js';
12
12
  import updateBlock from './update-block.js';
13
13
 
14
- const localFile = path.join(projectPath, 'package.json');
15
- const pkg = JSON.parse( fs.readFileSync(localFile) );
16
-
17
14
  /**
18
15
  * Get NPM Package Latest Version
19
16
  * @param {string} options.slug Block slug.
@@ -26,9 +23,10 @@ async function getNPMPackageVersion(pkg, spinner){
26
23
  'view',
27
24
  `${pkg}`,
28
25
  'version'
29
- ],
30
- spinner
31
- )
26
+ ]
27
+ ).then(({stdout, stderr}) => {
28
+ return ! stdout.toString() ? false : stdout.toString();
29
+ })
32
30
 
33
31
  }
34
32
 
@@ -45,6 +43,8 @@ export default async function createBlock({
45
43
  debug,
46
44
  slug
47
45
  } ) {
46
+ spinner.stop();
47
+
48
48
  // if block directory already exists.
49
49
  if( fs.existsSync(path.resolve(process.cwd(), slug)) ){
50
50
  spinner.info(`${slug} already exists.`)
@@ -75,7 +75,6 @@ export default async function createBlock({
75
75
  slug,
76
76
  '--template=' + path.join(projectPath, 'template', 'index.cjs')
77
77
  ],
78
- spinner,
79
78
  {
80
79
  stdio: 'inherit'
81
80
  }
@@ -93,7 +92,6 @@ export default async function createBlock({
93
92
  'install',
94
93
  `@cagov/${slug}@${version}`,
95
94
  ],
96
- spinner,
97
95
  {
98
96
  cwd: path.join(process.cwd(), slug ),
99
97
  stdio: 'inherit'
@@ -2,13 +2,27 @@
2
2
  * External dependencies
3
3
  */
4
4
  import path from 'path';
5
- import fs from 'fs';
5
+ import fs from 'fs-extra';
6
6
 
7
7
  /**
8
8
  * Internal dependencies
9
9
  */
10
+ import {runCmd} from '../../lib/index.js';
10
11
  import createBlock from './create-block.js';
11
12
 
13
+ /**
14
+ * Returns the WordPress Plugin Header.
15
+ *
16
+ * @param {String} content Content to search for plugin header.
17
+ * @returns String
18
+ */
19
+ function getPluginHeader( content ){
20
+ return content.substring(
21
+ content.indexOf('<?php') + '<?php'.length,
22
+ content.indexOf('*/') + '*/'.length
23
+ )
24
+ }
25
+
12
26
  /**
13
27
  * Update Block
14
28
  *
@@ -22,36 +36,120 @@ export default async function updateBlock({
22
36
  debug,
23
37
  slug
24
38
  } ) {
25
-
26
39
  // if block directory exists.
27
40
  if( fs.existsSync(path.resolve(process.cwd(), slug)) ){
28
- spinner.text = `Updating ${slug} block plugin.`;
41
+ console.log( `Updating ${slug} block plugin.` );
42
+ //spinner.text = `Updating ${slug} block plugin.`;
29
43
 
30
44
  // make tmp directory
31
45
  fs.ensureDir( `${slug}.tmp`);
32
46
 
33
- // move inc directory to tmp directory
34
- fs.copySync(`${slug}/inc/`, `${slug}.tmp/inc/`);
35
-
36
47
  // move src directory to tmp directory
37
48
  fs.copySync(`${slug}/src/`, `${slug}.tmp/src/`);
38
49
 
50
+ // move package.json to tmp directory
51
+ fs.copySync(`${slug}/package.json`, `${slug}.tmp/package.json`);
52
+
53
+ // move plugin main entry file to tmp directory
54
+ fs.copySync(`${slug}/${slug}.php`, `${slug}.tmp/${slug}.php`);
55
+
39
56
  // delete old block.
40
57
  fs.removeSync( `${slug}` );
41
58
 
42
59
  // Recreate the block.
43
60
  await createBlock({spinner, debug, slug});
44
61
 
45
- // move inc directory back to block directory
46
- fs.copySync(`${slug}.tmp/inc/`, `${slug}/inc/` );
47
-
48
62
  // move src directory back to block directory
49
63
  fs.copySync(`${slug}.tmp/src/`, `${slug}/src/`);
50
64
 
65
+ // we get new and old package.json files
66
+ let oldPkg = JSON.parse( fs.readFileSync(path.join(`${slug}.tmp`, 'package.json')) )
67
+ let newPkg = JSON.parse( fs.readFileSync(path.join(slug, 'package.json')) )
68
+
69
+ /**
70
+ * package.json changes
71
+ * @since 1.3.0 Gulp is no longer used.
72
+ */
73
+ if( oldPkg.version < '1.3.0' ){
74
+
75
+ // remove the old postbuild script.
76
+ if( oldPkg.scripts.postbuild && 'gulp build' === oldPkg.scripts.postbuild ){
77
+ delete oldPkg.scripts.postbuild;
78
+ }
79
+
80
+ // remove old gulp related packages
81
+ for(const i in oldPkg.devDependencies ){
82
+ if( [
83
+ 'del', 'fancy-log', 'gulp', 'gulp-cli', 'gulp-concat', 'gulp-file', 'gulp-line-ending-corrector',
84
+ 'gulp-sass', 'gulp-tap', 'gulp-uglify-es', 'sass'
85
+ ].includes( i ) ){
86
+ delete oldPkg.devDependencies[i]
87
+ }
88
+ }
89
+ }
90
+
91
+ // we only need the dependencies and devDependencies updated.
92
+ fs.writeFileSync(
93
+ path.join(slug, 'package.json'),
94
+ JSON.stringify( {
95
+ ...oldPkg,
96
+ dependencies: {
97
+ ...oldPkg.dependencies,
98
+ ...newPkg.dependencies,
99
+ },
100
+ devDependencies: {
101
+ ...oldPkg.devDependencies,
102
+ ...newPkg.devDependencies,
103
+ }
104
+ }, null, 4 )
105
+ );
106
+
107
+ let oldEntry = fs.readFileSync(path.join(`${slug}.tmp`, `${slug}.php`)).toString()
108
+ let oldHeader = getPluginHeader(oldEntry);
109
+ let newEntry = fs.readFileSync(path.join(slug, `${slug}.php`)).toString();
110
+ let newHeader = getPluginHeader(newEntry);
111
+
112
+ // we dont want to update the header case changes we made.
113
+ // we only update the plugin headers require fields.
114
+ let correctedHeader = oldHeader
115
+ .replace(/Requires at .*/, newHeader.match(/Requires at .*/) )
116
+ .replace(/Requires PHP.*/, newHeader.match(/Requires PHP.*/) )
117
+
118
+ // replace the header in the new entry with the corrected header and write the file back
119
+ fs.writeFileSync(
120
+ path.join(slug, `${slug}.php`),
121
+ newEntry.replace(newHeader, correctedHeader)
122
+ );
123
+
51
124
  // delete tmp directory.
52
125
  fs.removeSync( `${slug}.tmp` );
53
126
 
54
- spinner.succeed(`${slug} has been updated!`);
127
+ // install block npm packages
128
+ await runCmd(
129
+ 'npm',
130
+ [
131
+ 'install',
132
+ ],
133
+ {
134
+ cwd: path.join(process.cwd(), slug ),
135
+ stdio: 'inherit'
136
+ }
137
+ )
138
+
139
+ // build block
140
+ await runCmd(
141
+ 'npm',
142
+ [
143
+ 'run',
144
+ 'build',
145
+ ],
146
+ {
147
+ cwd: path.join(process.cwd(), slug ),
148
+ stdio: 'inherit'
149
+ }
150
+ )
151
+
152
+ spinner.text = `${slug} has been updated!`;
55
153
 
56
154
  }else{
57
155
  spinner.fail(`${slug} plugin directory not found.`)
package/commands/build.js CHANGED
@@ -68,6 +68,13 @@ export default async function build({
68
68
  await runCmd(
69
69
  'webpack',
70
70
  webPackArgs,
71
- )
71
+ ).then(({stdout, stderr}) => {
72
+ // if an error was thrown, and no output
73
+ if( stderr && ! stdout.toString() ){
74
+ console.log( stderr.toString() )
75
+ }else{
76
+ spinner.text = 'Done'
77
+ }
78
+ });
72
79
 
73
80
  };
@@ -86,7 +86,7 @@ let webpackConfig = {
86
86
  output: {
87
87
  ...baseConfig.output,
88
88
  publicPath: `./`,
89
- clean: false
89
+ clean: true
90
90
  },
91
91
  plugins: [
92
92
  ...baseConfig.plugins,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/cli",
3
- "version": "1.3.12",
3
+ "version": "1.3.14",
4
4
  "description": "CAWebPublishing Command Line Interface.",
5
5
  "exports": "./lib/env.js",
6
6
  "type": "module",
@@ -40,7 +40,6 @@
40
40
  "config": {
41
41
  "WP_VER": "6.4.3",
42
42
  "PHP_VER": "8.1",
43
- "CREATE_BLOCK_VER": "4.32.0",
44
43
  "DEFAULTS": {
45
44
  "FS_METHOD": "direct",
46
45
  "WP_DEBUG": true,
@@ -57,6 +56,7 @@
57
56
  }
58
57
  },
59
58
  "dependencies": {
59
+ "@wordpress/create-block": "^4.32.0",
60
60
  "@wordpress/env": "^9.6.0",
61
61
  "@wordpress/scripts": "^27.5.0",
62
62
  "accessibility-checker": "^3.1.68",
@@ -68,6 +68,7 @@
68
68
  "cross-spawn": "^7.0.3",
69
69
  "css-loader": "^6.10.0",
70
70
  "docker-compose": "^0.24.7",
71
+ "fs-extra": "^11.2.0",
71
72
  "handlebars-loader": "^1.7.3",
72
73
  "html-to-json-parser": "^2.0.1",
73
74
  "html-webpack-plugin": "^5.6.0",
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The following scripts get applied on the front of your site
3
+ *
4
+ * Add your own scripts.
5
+ */
@@ -0,0 +1,15 @@
1
+ <?php
2
+ /**
3
+ * {{title}} Dynamic Renderer Functions
4
+ *
5
+ * @package {{namespace}}
6
+ *
7
+ * @see https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/creating-dynamic-blocks/
8
+ *
9
+ * @param array $attributes Block attributes.
10
+ * @param string $content Block content.
11
+ * @param WP_Block_Type $block Current Block Type.
12
+ */
13
+ ?>
14
+
15
+ <p>Render Block Output</p>
@@ -13,12 +13,13 @@ const blockSlugTitle = capitalCase( blockSlug );
13
13
  const customScripts = {};
14
14
 
15
15
  const npmDependencies = [
16
- '@wordpress/icons@9.22.0'
16
+ '@wordpress/icons@9.45.0'
17
17
  ];
18
18
 
19
- const npmDevDependencies = [];
19
+ const npmDevDependencies = [
20
+ '@wordpress/scripts@27.6.0'
21
+ ];
20
22
 
21
- // assetsPath: join( __dirname, 'assets' ),
22
23
  module.exports = {
23
24
  pluginTemplatesPath: join( __dirname, 'plugin' ),
24
25
  blockTemplatesPath: join( __dirname, 'block' ),
@@ -26,7 +27,7 @@ module.exports = {
26
27
  pluginURI: `https://github.com/CAWebPublishing/${ blockSlug }`,
27
28
  plugin: true,
28
29
  description: `${ blockSlugTitle } Gutenberg Block`,
29
- version: '1.2.0',
30
+ version: '1.3.0',
30
31
  author: 'CAWebPublishing',
31
32
  license: 'GPL-2.0-or-later',
32
33
  licenseURI: 'https://www.gnu.org/licenses/gpl-2.0.html',
@@ -45,4 +46,8 @@ module.exports = {
45
46
  npmDependencies: npmDependencies,
46
47
  npmDevDependencies: npmDevDependencies,
47
48
  },
49
+ customBlockJSON: {
50
+ viewScript: "file:./frontend.js",
51
+ render: "file:./render.php"
52
+ }
48
53
  };
@@ -44,11 +44,6 @@ foreach ( glob( __DIR__ . '/core/*.php' ) as $file ) {
44
44
  require_once $file;
45
45
  }
46
46
 
47
- // Include {{title}} Functionality.
48
- foreach ( glob( __DIR__ . '/inc/*.php' ) as $file ) {
49
- require_once $file;
50
- }
51
-
52
47
  /**
53
48
  * Plugin API/Action Reference
54
49
  * Actions Run During a Typical Request
@@ -56,7 +51,6 @@ foreach ( glob( __DIR__ . '/inc/*.php' ) as $file ) {
56
51
  * @link https://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_a_Typical_Request
57
52
  */
58
53
  add_action( 'init', 'cagov_design_system_{{slugSnakeCase}}_init' );
59
- add_action( 'wp_enqueue_scripts', 'cagov_design_system_{{slugSnakeCase}}_wp_enqueue_scripts' );
60
54
 
61
55
  if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_init' ) ) {
62
56
  /**
@@ -71,12 +65,6 @@ if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_init' ) ) {
71
65
  function cagov_design_system_{{slugSnakeCase}}_init() {
72
66
  global $pagenow;
73
67
 
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
68
  /**
81
69
  * Enqueues the default ThickBox js and css. (if not on the login page or customizer page)
82
70
  *
@@ -86,16 +74,6 @@ if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_init' ) ) {
86
74
  add_thickbox();
87
75
  }
88
76
 
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
77
  /**
100
78
  * Registers the block using the metadata loaded from the `block.json` file.
101
79
  * Behind the scenes, it registers also all assets so they can be enqueued
@@ -103,33 +81,7 @@ if ( ! function_exists( 'cagov_design_system_{{slugSnakeCase}}_init' ) ) {
103
81
  *
104
82
  * @see https://developer.wordpress.org/reference/functions/register_block_type/
105
83
  */
106
- register_block_type( __DIR__ . '/build', $block_args );
84
+ register_block_type( __DIR__ . '/build' );
107
85
  }
108
86
  }
109
87
 
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
- }
@@ -1,80 +0,0 @@
1
-
2
- .popover-content {
3
- position: absolute;
4
- display: flex;
5
- flex-direction: column-reverse;
6
- row-gap: .5rem;
7
- left: -10000px;
8
- top: auto;
9
- width: 1px;
10
- height: 1px;
11
- background-color: white;
12
- padding: 1rem;
13
- z-index: 100;
14
- outline: 0;
15
- border-radius: .5rem;
16
- overflow: visible;
17
- pointer-events: none;
18
- --shadow-color: 220 3% 15%;
19
- --shadow-strength: 1%;
20
- box-shadow: 5px 7px 15px grey;
21
- }
22
- .popover-content:focus {
23
- outline: 2px solid var(--highlight-color, #fec02f);
24
- }
25
-
26
- .popover-container {
27
- position: relative;
28
- width: fit-content;
29
- }
30
-
31
- .popover-content::before {
32
- content: '';
33
- position: absolute;
34
- width: 1rem;
35
- height: 1rem;
36
- left: 0;
37
- top: 50%;
38
- background-color: white;
39
- transform: translate(-50%, -50%) rotate(45deg);
40
- }
41
- .popover-revealed {
42
- width: max-content;
43
- height: max-content;
44
- left: var(--x);
45
- top: var(--y);
46
- transform: translateY(-50%);
47
- }
48
- @media screen and (max-width: 950px) {
49
- .popover-content::before {
50
- content: none;
51
- }
52
- .popover-revealed {
53
- left: calc(50% + var(--x-offset-m, 0%));
54
- transform: translate(-50%, 0);
55
- }
56
- }
57
-
58
- .popover-legend {
59
- display: flex;
60
- flex-direction: row;
61
- gap: .75rem;
62
- align-items: flex-start;
63
- }
64
-
65
- .popover-legend svg {
66
- height: 1.5em;
67
- }
68
-
69
- .popover-revealed p {
70
- font-weight: 400;
71
- font-size: 1em;
72
- }
73
-
74
- .popover-header {
75
- margin: 0;
76
- }
77
-
78
- .popover-stat {
79
- margin: 0 0 .5rem 0;
80
- }
@@ -1,30 +0,0 @@
1
- jQuery( document ).ready( function ( $ ) { // eslint-disable-line
2
- $( document ).on( 'mouseover', '.popover', function ( ele ) {
3
- togglePopover( ele.currentTarget.id );
4
- } );
5
-
6
- $( document ).on( 'mouseout', '.popover', function ( ele ) {
7
- togglePopover( ele.currentTarget.id, false );
8
- } );
9
-
10
- function togglePopover( id, popin = true ) {
11
- if ( undefined !== id ) {
12
- const current = $( '#' + id );
13
- const popver = $( '#' + id + '-popover' );
14
-
15
- if ( popin ) {
16
- current.addClass( 'highlighted' );
17
-
18
- if ( undefined !== popver ) {
19
- $( popver ).addClass( 'popover-revealed' );
20
- }
21
- } else {
22
- current.removeClass( 'highlighted' );
23
-
24
- if ( undefined !== popver ) {
25
- $( popver ).removeClass( 'popover-revealed' );
26
- }
27
- }
28
- }
29
- }
30
- } );
@@ -1,44 +0,0 @@
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
- }
@@ -1,25 +0,0 @@
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
- }