Skip to content
This repository has been archived by the owner on Jan 17, 2025. It is now read-only.

Scope strategy of the migration from create-guten-block scripts to a @wordpress/scripts core setup #211

Closed
1 task done
possumbilities opened this issue Sep 6, 2022 · 4 comments
Assignees
Labels
💻 aspect: code Concerns the software code in the repository 🤖 aspect: dx Concerns developers' experience with the codebase ✨ goal: improvement Improvement to an existing feature 🟩 priority: low Low priority and doesn't need to be rushed 🏁 status: ready for work Ready for work
Milestone

Comments

@possumbilities
Copy link
Contributor

possumbilities commented Sep 6, 2022

Problem

Previously:

The use of create-guten-block as a scaffolding for the WordPress Gutenberg blocks has a number of compatibility and stability issues. Since the blocks were originally created with create-guten-block core WP has grown its capacity to handle scaffolding, dev, and build. To keep block dev stable long term, create-guten-block needs to be replaced entirely with core functionality.

Description

The entirety of create-guten-block needs to be removed, along with all its dependencies. Its implementation of block structure and file setup is not quite 1:1 compared to the @wordpress/scripts, which will require modification.

Additionally, the CGB setup has its own "cgb" namespace, which is not as intuitive or accurate post deprecation. The namespace should likely shift to "cc" or something similar.

As the namespace will be shifting, that will cause CSS rules, HTML classes, and JS naming conventions to shift as well. This means that any site utilizing a CGB built block will need a proper migration path to using the core scripts implementation with the new namespace and naming convention.

Above all, a proper strategy with adjoining scope needs to be drafted to establish the best migration path.

Implementation

  • I would be interested in drafting this plan.
@possumbilities possumbilities added 🟩 priority: low Low priority and doesn't need to be rushed 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work ✨ goal: improvement Improvement to an existing feature 💻 aspect: code Concerns the software code in the repository labels Sep 6, 2022
@possumbilities possumbilities changed the title [Feature] migrate from create-guten-block scripts to a @wordpress/scripts core setup Scope strategy of the migration from create-guten-block scripts to a @wordpress/scripts core setup Sep 6, 2022
@possumbilities possumbilities added this to the v2022.09.1 milestone Sep 6, 2022
@possumbilities possumbilities self-assigned this Sep 6, 2022
@possumbilities possumbilities added 🤖 aspect: dx Concerns developers' experience with the codebase 🏁 status: ready for work Ready for work and removed 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work labels Sep 6, 2022
@possumbilities possumbilities modified the milestones: v2022.09.1, v2022.10.1 Sep 9, 2022
@TimidRobot TimidRobot moved this to Backlog in possumbilities Sep 10, 2024
@RonaldRonnie
Copy link

hi my senior, do i need to first create the "docker-compose.yml file for building and testing."?

@RonaldRonnie
Copy link

Also Migration to @wordpress/scripts:

The README doesn't detail the migration process, it provides context for understanding the current workflow and the commands I'll likely need to modify.

Points for Migration basing on my finding:

npm remains relevant: Since @wordpress/scripts also utilizes npm for managing dependencies and scripts, the basic commands like npm install and npm run will still be used.
Build Process Updates: We will likely need to replace the existing build scripts for @wordpress/scripts.
WP-CLI remains useful: WP-CLI can still be used within a Docker environment or locally for interacting with WordPress during development and testing.

however, choose a development environment that supports @wordpress/scripts, such as a local WordPress instance with the necessary plugins installed is also crucial.

I requset you to enlight me about this please and to provide me more guidance about it.

@RonaldRonnie
Copy link

RonaldRonnie commented Oct 30, 2024

hi @possumbilities , i've tried out a few changes about this and I would like you go through this file and advise me .
I wanted to first work on one file and then proceed .

src/CC-BY/block.js

original: src/CC-BY/block.js

updated `src/CC-BY/block.js`
import './style.scss';
import './editor.scss';
import { __ } from '@wordpress/i18n';
import { registerBlockType } from '@wordpress/blocks';
import { InspectorControls, PanelColorSettings, RichText } from '@wordpress/block-editor';

/**
 * Register: CC-BY Gutenberg block.
 *
 * Registers a new block provided a unique name and an object defining its
 * behavior. Once registered, the block is made available as an option to any
 * editor interface where blocks are implemented.
 *
 * @link https://wordpress.org/gutenberg/handbook/block-api/
 * @param  {string}   name     Block name.
 * @param  {Object}   settings Block settings.
 * @return {?WPBlock}          The block, if it has been successfully
 *                             registered; otherwise `undefined`.
 */
registerBlockType('cc/cc-by', {
	title: __('CC-BY'),
	icon: 'media-text',
	category: 'cc-licenses',
	keywords: [__('creative commons'), __('CC-BY'), __('attribution')],
	attributes: {
		bgColor: {
			type: 'string',
			default: 'white',
		},
		txtColor: {
			type: 'string',
			default: 'black',
		},
		contentName: {
			selector: '.cc-name',
			source: 'children',
		},
		contentText: {
			selector: '.cc-text',
			source: 'children',
		},
	},

	/**
	 * The edit function describes the structure of your block in the context of the editor.
	 * This represents what the editor will render when the block is used.
	 *
	 * The "edit" property must be a valid function.
	 *
	 * @link https://wordpress.org/gutenberg/handbook/block-api/block-edit-save/
	 * @param {Object} props Props.
	 * @returns {Mixed} JSX Component.
	 */
	edit: function (props) {
		const { bgColor, txtColor, contentName, contentText } = props.attributes;
		const { setAttributes } = props;

		const onChangeContentName = contentName => setAttributes({ contentName });
		const onChangeContentText = contentText => setAttributes({ contentText });

		return [
			<InspectorControls key="3">
				<PanelColorSettings
					title={__('Color Settings', 'creativecommons')}
					colorSettings={[
						{
							label: __('Background Color'),
							value: bgColor,
							onChange: colorValue => setAttributes({ bgColor: colorValue }),
						},
						{
							label: __('Text Color'),
							value: txtColor,
							onChange: colorValue => setAttributes({ txtColor: colorValue }),
						},
					]}
				/>
			</InspectorControls>,

			<div key="2" style={{ backgroundColor: bgColor, color: txtColor }}>
				<img src={`${pluginDirUrl}/includes/images/by.png`} alt="CC-BY" width="88" height="31" />
				<p>
					This content is licensed by{' '}
					<a href="https://creativecommons.org/licenses/by/4.0/" rel="license">
						Creative Commons Attribution 4.0 International license.
					</a>
				</p>
				<h4>Edit</h4>
				<span>
					Attribution name <i>(default: This content)</i>:
				</span>
				<div className="cc-richtext-input">
					<RichText
						placeholder={__('This content', 'CreativeCommons')}
						keepPlaceholderOnFocus={true}
						onChange={onChangeContentName}
						value={contentName}
					/>
				</div>
				<span>
					<br />
					Additional text <i>(optional)</i>:
				</span>
				<div className="cc-richtext-input">
					<RichText
						placeholder={__('Custom text/description/links ', 'CreativeCommons')}
						keepPlaceholderOnFocus={true}
						onChange={onChangeContentText}
						value={contentText}
					/>
				</div>
			</div>,
		];
	},

	/**
	 * The save function defines the way in which the different attributes should be combined
	 * into the final markup, which is then serialized by Gutenberg into post_content.
	 *
	 * The "save" property must be specified and must be a valid function.
	 *
	 * @link https://wordpress.org/gutenberg/handbook/block-api/block-edit-save/
	 * @param {Object} props Props.
	 * @returns {Mixed} JSX Frontend HTML.
	 */
	save: function (props) {
		const { bgColor, txtColor, contentName, contentText } = props.attributes;

		return (
			<div className="message-body" style={{ backgroundColor: bgColor, color: txtColor }}>
				<img src={`${pluginDirUrl}/includes/images/by.png`} alt="CC" width="88" height="31" />
				<p>
					<span className="cc-name">{contentName || 'This content'}</span> is licensed under a{' '}
					<a href="https://creativecommons.org/licenses/by/4.0/" rel="license">
						Creative Commons Attribution 4.0 International license.
					</a>{' '}
					<span className="cc-text">{contentText}</span>
				</p>
			</div>
		);
	},
});
--- original
+++ updated
@@ -1,16 +1,14 @@
 import './style.scss';
 import './editor.scss';
-import globals from 'cgbGlobal';
-const { __ } = wp.i18n; // Import __() from wp.i18n
-const { registerBlockType } = wp.blocks; // Import registerBlockType() from wp.blocks
-const { InspectorControls, PanelColorSettings } = wp.blockEditor; // Import color settings from wp.editor
-const { RichText } = wp.blockEditor; // Import RichText blocks from wp.editor
+import { __ } from '@wordpress/i18n';
+import { registerBlockType } from '@wordpress/blocks';
+import { InspectorControls, PanelColorSettings, RichText } from '@wordpress/block-editor';
 
 /**
  * Register: CC-BY Gutenberg block.
  *
  * Registers a new block provided a unique name and an object defining its
- * behavior. Once registered, the block is made editor as an option to any
+ * behavior. Once registered, the block is made available as an option to any
  * editor interface where blocks are implemented.
  *
  * @link https://wordpress.org/gutenberg/handbook/block-api/
@@ -19,7 +17,7 @@
  * @return {?WPBlock}          The block, if it has been successfully
  *                             registered; otherwise `undefined`.
  */
-registerBlockType('cgb/cc-by', {
+registerBlockType('cc/cc-by', {
 	title: __('CC-BY'),
 	icon: 'media-text',
 	category: 'cc-licenses',
@@ -34,11 +32,11 @@
 			default: 'black',
 		},
 		contentName: {
-			selector: '.cc-cgb-name',
+			selector: '.cc-name',
 			source: 'children',
 		},
 		contentText: {
-			selector: '.cc-cgb-text',
+			selector: '.cc-text',
 			source: 'children',
 		},
 	},
@@ -54,18 +52,11 @@
 	 * @returns {Mixed} JSX Component.
 	 */
 	edit: function (props) {
-		const bgColor = props.attributes.bgColor;
-		const txtColor = props.attributes.txtColor;
-		const contentName = props.attributes.contentName;
-		const contentText = props.attributes.contentText;
-		const { attributes: className, setAttributes } = props;
+		const { bgColor, txtColor, contentName, contentText } = props.attributes;
+		const { setAttributes } = props;
 
-		const onChangeContentName = contentName => {
-			setAttributes({ contentName });
-		};
-		const onChangeContentText = contentText => {
-			setAttributes({ contentText });
-		};
+		const onChangeContentName = contentName => setAttributes({ contentName });
+		const onChangeContentText = contentText => setAttributes({ contentText });
 
 		return [
 			<InspectorControls key="3">
@@ -75,19 +66,19 @@
 						{
 							label: __('Background Color'),
 							value: bgColor,
-							onChange: colorValue => props.setAttributes({ bgColor: colorValue }),
+							onChange: colorValue => setAttributes({ bgColor: colorValue }),
 						},
 						{
 							label: __('Text Color'),
 							value: txtColor,
-							onChange: colorValue => props.setAttributes({ txtColor: colorValue }),
+							onChange: colorValue => setAttributes({ txtColor: colorValue }),
 						},
 					]}
 				/>
 			</InspectorControls>,
 
-			<div key="2" className={className} style={{ backgroundColor: bgColor, color: txtColor }}>
-				<img src={`${globals.pluginDirUrl}includes/images/by.png`} alt="CC-BY" width="88" height="31" />
+			<div key="2" style={{ backgroundColor: bgColor, color: txtColor }}>
+				<img src={`${pluginDirUrl}/includes/images/by.png`} alt="CC-BY" width="88" height="31" />
 				<p>
 					This content is licensed by{' '}
 					<a href="https://creativecommons.org/licenses/by/4.0/" rel="license">
@@ -98,9 +89,8 @@
 				<span>
 					Attribution name <i>(default: This content)</i>:
 				</span>
-				<div className="cc-cgb-richtext-input">
+				<div className="cc-richtext-input">
 					<RichText
-						className={className}
 						placeholder={__('This content', 'CreativeCommons')}
 						keepPlaceholderOnFocus={true}
 						onChange={onChangeContentName}
@@ -111,9 +101,8 @@
 					<br />
 					Additional text <i>(optional)</i>:
 				</span>
-				<div className="cc-cgb-richtext-input">
+				<div className="cc-richtext-input">
 					<RichText
-						className={className}
 						placeholder={__('Custom text/description/links ', 'CreativeCommons')}
 						keepPlaceholderOnFocus={true}
 						onChange={onChangeContentText}
@@ -135,26 +124,19 @@
 	 * @returns {Mixed} JSX Frontend HTML.
 	 */
 	save: function (props) {
-		const bgColor = props.attributes.bgColor;
-		const txtColor = props.attributes.txtColor;
-		let contentName = props.attributes.contentName;
-		const contentText = props.attributes.contentText;
+		const { bgColor, txtColor, contentName, contentText } = props.attributes;
 
-		if (contentName == '') {
-			contentName = 'This content'; // Default to "This Content".
-		}
 		return (
 			<div className="message-body" style={{ backgroundColor: bgColor, color: txtColor }}>
-				<img src={`${globals.pluginDirUrl}includes/images/by.png`} alt="CC" width="88" height="31" />
+				<img src={`${pluginDirUrl}/includes/images/by.png`} alt="CC" width="88" height="31" />
 				<p>
-					<span className="cc-cgb-name">{contentName}</span> is licensed under a{' '}
+					<span className="cc-name">{contentName || 'This content'}</span> is licensed under a{' '}
 					<a href="https://creativecommons.org/licenses/by/4.0/" rel="license">
 						Creative Commons Attribution 4.0 International license.
 					</a>{' '}
-					<span className="cc-cgb-text">{contentText}</span>
+					<span className="cc-text">{contentText}</span>
 				</p>
 			</div>
 		);
 	},
 });

@possumbilities
Copy link
Contributor Author

Closing due to imminent archiving

@possumbilities possumbilities closed this as not planned Won't fix, can't repro, duplicate, stale Jan 17, 2025
@github-project-automation github-project-automation bot moved this from Backlog to Done in possumbilities Jan 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository 🤖 aspect: dx Concerns developers' experience with the codebase ✨ goal: improvement Improvement to an existing feature 🟩 priority: low Low priority and doesn't need to be rushed 🏁 status: ready for work Ready for work
2 participants