Skip to content

Commit

Permalink
Add faust blockset command (#1585)
Browse files Browse the repository at this point in the history
* Add new block-support example project

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Auto analyze new project

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Update dependencies

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Remove hardcoded theme.json

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Ignore globalStylesheet.css

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Reduce example to just block things

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Add newline to EOF

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Reduce example

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Update lockfile after merge

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Constrain layout using existing core class

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Not being used

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Irrelevant comment

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Scaffold out new plugin files

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Add new dependencies

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Add blockset command

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Add new command to block support example

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Register new REST endpoint to handle unzipping blocks

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Fix example project deps

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Fix namespace issue

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Refactor into testable functions

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Mock custom block

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Ignore .faust

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Fix namespacing issues in WP plugin

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Clean up comments

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Improve readability

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Add deps

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Add second block example to test blockset

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Export functions for tests

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Remove unused jest-dom in CLI package

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Remove unused package

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Add new utility function

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Ignore for tests

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Refactor blockset command

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* New line at EOF

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Linting fixes

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Return true upon success

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Use available logging methods

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Remove code already in handle_uploaded_blockset & setup translations

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Add missing dep

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Linting fixes

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Linting fixes

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Resolve merge conflicts

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Feat: Add compileBlocks step.

* Automatically load custom blocks from uploads

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Fix enqueues from the uploads directory

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Fix linting issues

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Feat: Check if project uses yarn when compiling blocks

* Use enqueue_block_editor_assets to avoid unnecessary runs

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Remove explicit registration using args

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Add required titles

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Correct the asset src for the blocks in uploads

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Linting fixes

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Remove unused functions

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Deps: Add wp-scripts in peer deps.

* Chore: Add changeset.

* Deps: Update rimraf

* Chore: Update deps.

* Refactor: Update hasYarn

* Chore: Update package-lock

* Chore: update package-lock again

* Chore: add missing export.

* Chore: remove faust blockset from predev,prebuild

* Fix blocks missing from WPGraphQL & prevent unnecessary block registrations

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Fix linting issues

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Example: Add block using `registerFaustBlock` helper

* Refactor: Update block comments

* Add plugin tests

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Add Plugin Tests (#1601)

* Add plugin tests

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Add test coverage for utility functions

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

---------

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Remove orphaned test

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Track possibleTypes & globalStylesheet generated files

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Build possibleTypes

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Add @wordpress/scripts to block-support-example

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Auto run blockset in block example

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Ignore Faust generated files

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Remove previously tracked file

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Fix version regression from merge conflict

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>

* Refactor: Change block-C as block-B

* Fix: Remove @ts-ignore comment.

* CI/CD fix tests with faustwp-cli

* Example block support: Remove blockset.

* Chore: Code review fixes.

* Chore: add Component.fragments

* Chore: Update package-lock.json

* Chore: Add gql missing import.

* Tests: Update fromThemeJson.test snapshot.

* Style: Add block styles in front-end

* Styles: Consistent styles fixed.

* CI/CD: Fix test cases.

* Test: Update CoreCode test snapshot.

* CI/CD: Update types in Toolbar.test.tsx

* CI/CD: Remove examples/next/block-support from bundle analysis.

---------

Signed-off-by: Joe Fusco <joe.fusco@wpengine.com>
Co-authored-by: theodesp <328805+theodesp@users.noreply.github.com>
  • Loading branch information
josephfusco and theodesp committed Oct 18, 2023
1 parent 3722ab3 commit c29f83d
Show file tree
Hide file tree
Showing 41 changed files with 13,567 additions and 24,827 deletions.
8 changes: 8 additions & 0 deletions .changeset/rotten-hats-exercise.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.
1 change: 0 additions & 1 deletion .github/workflows/nextjs-bundle-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
matrix:
next-dir: [
'examples/next/faustwp-getting-started',
'examples/next/block-support'
]

runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion examples/next/block-support/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
possibleTypes.json
.faust
globalStylesheet.css
possibleTypes.json
5 changes: 3 additions & 2 deletions examples/next/block-support/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
"prebuild": "faust generatePossibleTypes && faust generateGlobalStylesheet",
"dev": "faust dev",
"build": "faust build",
"blockset": "faust blockset",
"start": "faust start"
},
"dependencies": {
"@apollo/client": "^3.6.6",
"@faustwp/blocks": "2.0.0",
"@faustwp/cli": "1.0.1",
"@faustwp/core": "1.1.0",
"@faustwp/cli": "1.1.4",
"@faustwp/core": "1.1.2",
"@wordpress/base-styles": "^4.26.0",
"@wordpress/block-library": "^7.19.0",
"classnames": "^2.3.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/next/block-support/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useRouter } from 'next/router';
import { WordPressBlocksProvider, fromThemeJson } from '@faustwp/blocks';
import { FaustProvider } from '@faustwp/core';
import blocks from '../wp-blocks';
// import '../styles/blocks.scss'; // <-- Import block styles from WordPress.
import '../styles/blocks.scss'; // <-- Import block styles from WordPress.
import '../globalStylesheet.css'; // <-- Generated by @faustwp/cli

export default function MyApp({ Component, pageProps }) {
Expand Down
2 changes: 2 additions & 0 deletions examples/next/block-support/styles/blocks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
@import '@wordpress/base-styles/breakpoints';
@import '@wordpress/block-library/src/style';
@import '@wordpress/block-library/src/theme';

@import '../wp-blocks/block-b/style.scss'
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;
}
38 changes: 38 additions & 0 deletions examples/next/block-support/wp-blocks/block-b/Component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { gql } from '@apollo/client';

function Component({ style, attributes, children, ...props }) {
const styles = {
...style,
};
const cssClassName = 'create-block-block-b-message';
return (
<div
style={styles}
className={cssClassName}
dangerouslySetInnerHTML={{ __html: attributes.message }}
/>
);
}

Component.fragments = {
key: `CreateBlockBlockBFragment`,
entry: gql`
fragment CreateBlockBlockBFragment on CreateBlockBlockB {
attributes {
message
}
}
`,
};

Component.config = {
name: 'CreateBlockBlockB',
editorFields: {
message: {
type: 'string',
label: 'My Message',
location: 'editor',
},
},
};
export default Component;
23 changes: 23 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,23 @@
{
"$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
},
"attributes": {
"message": {
"type": "string",
"default": "Hello World"
}
},
"textdomain": "block-b",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css"
}
13 changes: 13 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,13 @@
import { registerFaustBlock } from '@faustwp/block-editor-utils';
import './style.scss';
import BlockB from './Component.js'
/**
* Block.json metadata
*/
import metadata from './block.json';
/**
* Register React block on the Block Editor
*/
registerFaustBlock(BlockB, {
blockJson: metadata
});
15 changes: 15 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,15 @@
/**
* 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 {
color: #333;
padding: 2px;
}

.create-block-block-b-message {
border: 1px solid pink;
}
2 changes: 2 additions & 0 deletions examples/next/block-support/wp-blocks/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CoreBlocks } from '@faustwp/blocks';
import BlockB from './block-b/Component.js';

export default {
CoreParagraph: CoreBlocks.CoreParagraph,
Expand All @@ -12,4 +13,5 @@ export default {
CoreButton: CoreBlocks.CoreButton,
CoreButtons: CoreBlocks.CoreButtons,
CoreHeading: CoreBlocks.CoreHeading,
CreateBlockBlockB: BlockB,
};
2 changes: 2 additions & 0 deletions examples/next/block-support/wp-templates/front-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Component.query = gql`
${blocks.CoreSeparator.fragments.entry}
${blocks.CoreList.fragments.entry}
${blocks.CoreHeading.fragments.entry}
${blocks.CreateBlockBlockB.fragments.entry}
query GetPage(
$databaseId: ID!
$asPreview: Boolean = false
Expand All @@ -56,6 +57,7 @@ Component.query = gql`
...${blocks.CoreSeparator.fragments.key}
...${blocks.CoreList.fragments.key}
...${blocks.CoreHeading.fragments.key}
...${blocks.CreateBlockBlockB.fragments.key}
}
}
}
Expand Down
Loading

0 comments on commit c29f83d

Please sign in to comment.