Skip to content

Commit

Permalink
Feat: (CLI) Add blockset command.
Browse files Browse the repository at this point in the history
  • Loading branch information
theodesp committed Oct 5, 2023
1 parent 94b1551 commit 0e5bb77
Show file tree
Hide file tree
Showing 24 changed files with 26,714 additions and 13,132 deletions.
8 changes: 8 additions & 0 deletions .changeset/marmelade-big-cistern.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@faustwp/cli': minor
'@faustwp/wordpress-plugin': minor
---

Add blockset command in @faust/cli and faustwp plugin.

Add your blocks inside `wp-blocks` folder. Then run `faust blockset` to compile and upload the blocks into WordPress. Blocks will be available in the editor.
6 changes: 5 additions & 1 deletion examples/next/block-support/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"prebuild": "faust generatePossibleTypes && faust generateGlobalStylesheet",
"dev": "faust dev",
"build": "faust build",
"start": "faust start"
"start": "faust start",
"blockset": "faust blockset"
},
"dependencies": {
"@apollo/client": "^3.6.6",
Expand All @@ -23,6 +24,9 @@
"react-dom": "^17.0.2",
"sass": "^1.54.9"
},
"devDependencies": {
"@wordpress/scripts": "26.12.0"
},
"engines": {
"node": ">=16",
"npm": ">=8"
Expand Down
17 changes: 17 additions & 0 deletions examples/next/block-support/wp-blocks/block-a/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "create-block/block-a",
"version": "0.1.0",
"title": "Block A",
"category": "widgets",
"icon": "smiley",
"description": "Example static block scaffolded with Create Block tool.",
"supports": {
"html": false
},
"textdomain": "block-a",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css"
}
38 changes: 38 additions & 0 deletions examples/next/block-support/wp-blocks/block-a/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Retrieves the translation of text.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-i18n/
*/
import { __ } from '@wordpress/i18n';

/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps
*/
import { useBlockProps } from '@wordpress/block-editor';

/**
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
* Those files can contain any CSS code that gets applied to the editor.
*
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
*/
import './editor.scss';

/**
* 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.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#edit
*
* @return {WPElement} Element to render.
*/
export default function Edit() {
return (
<p {...useBlockProps()}>
{__('Block A – hello from the editor!', 'block-a')}
</p>
);
}
9 changes: 9 additions & 0 deletions examples/next/block-support/wp-blocks/block-a/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* The following styles get applied inside the editor only.
*
* Replace them with your own styles or remove the file completely.
*/

.wp-block-create-block-block-a {
border: 1px dotted #f00;
}
39 changes: 39 additions & 0 deletions examples/next/block-support/wp-blocks/block-a/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Registers a new block provided a unique name and an object defining its behavior.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
import { registerBlockType } from '@wordpress/blocks';

/**
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
* All files containing `style` keyword are bundled together. The code used
* gets applied both to the front of your site and to the editor.
*
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
*/
import './style.scss';

/**
* Internal dependencies
*/
import Edit from './edit';
import save from './save';
import metadata from './block.json';

/**
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
registerBlockType(metadata.name, {
title: 'Block A',
/**
* @see ./edit.js
*/
edit: Edit,
/**
* @see ./save.js
*/
save,
});
31 changes: 31 additions & 0 deletions examples/next/block-support/wp-blocks/block-a/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Retrieves the translation of text.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-i18n/
*/
import { __ } from '@wordpress/i18n';

/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps
*/
import { useBlockProps } from '@wordpress/block-editor';

/**
* The save function defines the way in which the different attributes should
* be combined into the final markup, which is then serialized by the block
* editor into `post_content`.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save
*
* @return {WPElement} Element to render.
*/
export default function save() {
return (
<p {...useBlockProps.save()}>
{__('Block A – hello from the saved content!', 'block-a')}
</p>
);
}
12 changes: 12 additions & 0 deletions examples/next/block-support/wp-blocks/block-a/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* The following styles get applied both on the front of your site
* and in the editor.
*
* Replace them with your own styles or remove the file completely.
*/

.wp-block-create-block-block-a {
background-color: #21759b;
color: #fff;
padding: 2px;
}
17 changes: 17 additions & 0 deletions examples/next/block-support/wp-blocks/block-b/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "create-block/block-b",
"version": "0.1.0",
"title": "Block B",
"category": "widgets",
"icon": "smiley",
"description": "Example static block scaffolded with Create Block tool.",
"supports": {
"html": false
},
"textdomain": "block-b",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css"
}
38 changes: 38 additions & 0 deletions examples/next/block-support/wp-blocks/block-b/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Retrieves the translation of text.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-i18n/
*/
import { __ } from '@wordpress/i18n';

/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps
*/
import { useBlockProps } from '@wordpress/block-editor';

/**
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
* Those files can contain any CSS code that gets applied to the editor.
*
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
*/
import './editor.scss';

/**
* 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.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#edit
*
* @return {WPElement} Element to render.
*/
export default function Edit() {
return (
<p {...useBlockProps()}>
{__('Block B – hello from the editor!', 'block-b')}
</p>
);
}
9 changes: 9 additions & 0 deletions examples/next/block-support/wp-blocks/block-b/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* The following styles get applied inside the editor only.
*
* Replace them with your own styles or remove the file completely.
*/

.wp-block-create-block-block-b {
border: 1px dotted #f00;
}
39 changes: 39 additions & 0 deletions examples/next/block-support/wp-blocks/block-b/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Registers a new block provided a unique name and an object defining its behavior.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
import { registerBlockType } from '@wordpress/blocks';

/**
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
* All files containing `style` keyword are bundled together. The code used
* gets applied both to the front of your site and to the editor.
*
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
*/
import './style.scss';

/**
* Internal dependencies
*/
import Edit from './edit';
import save from './save';
import metadata from './block.json';

/**
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
registerBlockType(metadata.name, {
title: 'Block B',
/**
* @see ./edit.js
*/
edit: Edit,
/**
* @see ./save.js
*/
save,
});
31 changes: 31 additions & 0 deletions examples/next/block-support/wp-blocks/block-b/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Retrieves the translation of text.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-i18n/
*/
import { __ } from '@wordpress/i18n';

/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps
*/
import { useBlockProps } from '@wordpress/block-editor';

/**
* The save function defines the way in which the different attributes should
* be combined into the final markup, which is then serialized by the block
* editor into `post_content`.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save
*
* @return {WPElement} Element to render.
*/
export default function save() {
return (
<p {...useBlockProps.save()}>
{__('Block B – hello from the saved content!', 'block-b')}
</p>
);
}
12 changes: 12 additions & 0 deletions examples/next/block-support/wp-blocks/block-b/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* The following styles get applied both on the front of your site
* and in the editor.
*
* Replace them with your own styles or remove the file completely.
*/

.wp-block-create-block-block-b {
background-color: #21759b;
color: #fff;
padding: 2px;
}
Loading

0 comments on commit 0e5bb77

Please sign in to comment.