diff --git a/.nvmrc b/.nvmrc index 3c03207..be9439d 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1,2 @@ 18 +hoist=true diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b05dcdf --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,37 @@ +# Changelog + +All notable changes to this project will be documented in this file. Dates are displayed in UTC. + +Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). + +## 1.0.0 + +- Update composer [`#66`](https://github.com/WebDevStudios/wd_f/pull/66) +- Feature/WDSUS-41 Design System [`#50`](https://github.com/WebDevStudios/wd_f/pull/50) +- Feature/WDSUS-39 Cleanup Deprecated Packages [`#49`](https://github.com/WebDevStudios/wd_f/pull/49) +- Feature/WDSUS-40 fix templates [`#48`](https://github.com/WebDevStudios/wd_f/pull/48) +- Bump autoprefixer from 10.4.14 to 10.4.15 [`#47`](https://github.com/WebDevStudios/wd_f/pull/47) +- Feature/wdsus 38 documentation [`#45`](https://github.com/WebDevStudios/wd_f/pull/45) +- 38 create a block specific build pattern so scss and css can be local to the block folder [`#44`](https://github.com/WebDevStudios/wd_f/pull/44) +- Feature/cleanup [`#42`](https://github.com/WebDevStudios/wd_f/pull/42) +- Feature/Fix Linting Errors [`#36`](https://github.com/WebDevStudios/wd_f/pull/36) +- Add the final find and replace fix. [`#34`](https://github.com/WebDevStudios/wd_f/pull/34) +- Fix / WDSUS-34 overhaul templates, ensuring proper alignment [`#35`](https://github.com/WebDevStudios/wd_f/pull/35) +- Feature/wdsus 32 remove old templates and cleanup [`#24`](https://github.com/WebDevStudios/wd_f/pull/24) +- Add a readme.txt with a copyright notice. [`#31`](https://github.com/WebDevStudios/wd_f/pull/31) +- Add an outline for blocks [`#21`](https://github.com/WebDevStudios/wd_f/pull/21) +- WDSUS-33: removes import error [`#28`](https://github.com/WebDevStudios/wd_f/pull/28) +- Add logo to theme and link to it [`#23`](https://github.com/WebDevStudios/wd_f/pull/23) +- Enhanced Editor Layout for Improved Frontend and Backend Experience [`#22`](https://github.com/WebDevStudios/wd_f/pull/22) +- Remove the Customizer [`#19`](https://github.com/WebDevStudios/wd_f/pull/19) +- Remove Critical CSS [`#18`](https://github.com/WebDevStudios/wd_f/pull/18) +- Fix #14: Remove CSS styles for columns and navigation link block from theme.json [`#17`](https://github.com/WebDevStudios/wd_f/pull/17) +- Feature/issue 6 multiple slashes [`#10`](https://github.com/WebDevStudios/wd_f/pull/10) +- 7 wds acf blocks wp cli replacement issues [`#8`](https://github.com/WebDevStudios/wd_f/pull/8) +- Hotfix/update readme [`#4`](https://github.com/WebDevStudios/wd_f/pull/4) +- Update README with instructions for scaffolding blocks [`#2`](https://github.com/WebDevStudios/wd_f/pull/2) +- Fix issue-1 deprecated warning for block_categories filter [`#3`](https://github.com/WebDevStudios/wd_f/pull/3) +- Merge pull request #17 from WebDevStudios/fix/#14-css-issues-in-theme-json [`#14`](https://github.com/WebDevStudios/wd_f/issues/14) +- updated out of date node dependencies [`b96845b`](https://github.com/WebDevStudios/wd_f/commit/b96845ba6995843c63521521662c5c4b5b0a595a) +- Update lock files [`bc49d03`](https://github.com/WebDevStudios/wd_f/commit/bc49d0368455c31e6abafc0b6e0b4ff4d40c37bc) +- WDS FSE Initial Commit [`ea3c439`](https://github.com/WebDevStudios/wd_f/commit/ea3c439dedb6b5cd659cc7fbd2829d8aa27a26de) diff --git a/README.md b/README.md index dacd989..c5ab780 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The WebDev FSE Starter Block Theme - [Quick Start](#quick-start) - [Setup](#setup) - [Development](#development) - - [Building a block with wpcli](#building-a-block-with-wpcli) + - [Scaffold a Block](#scaffold-a-block) - [Contributing and Support](#contributing-and-support) ## Introduction @@ -93,22 +93,18 @@ Command | Action `npm run format` | Fix all CSS, JS, MD, and PHP formatting errors automatically `npm run report` | Gives detailed information on coding standards violations in PHP code -### Building a block with wpcli +### Scaffold a Block -In order to build a block, run the following wpcli script. - -Note: If you're using Local, you can open the shell from within Local to do this. `Sitename -> Open site shell`. +In order to scaffold a custom block, run the following script in the root of the theme. ```bash -wp wds create_portable_block myblock --title="This is myblock" --desc="This block is used for wds." --keyword="myblock" --icon="table-row-before" --namespace="wds" +npm run create-block myblock ``` -This will scaffold out a block inside of the `blocks` folder in the theme. Replace `myblock` with the name of your block and update the other items `title`, `desc`, `keyword`, `icon`, `namespace` with the appropriate information. - -Note: If you don't see your new block available under the block listing in the editor after following the above steps, try changing the namespacing in your block's `block.json` to the following format `your-namespace/blockname` and check again. +This will scaffold out a block inside of the `blocks` folder in the theme. Replace `myblock` with the name of your block and run `npm run build` to build the block. ## Contributing and Support Your contributions and [support tickets](https://github.com/WebDevStudios/wd_f/issues) are welcome. Please see our [contributing guidelines](https://github.com/WebDevStudios/wd_f/blob/main/CONTRIBUTING.md) before submitting a pull request. -wd_f is free software, and is released under the terms of the GNU General Public License version 2 or any later version. See [LICENSE.md](https://github.com/WebDevStudios/wd_f/blob/main/LICENSE.md) for complete license. +`wd_f` is free software, and is released under the terms of the GNU General Public License version 2 or any later version. See [LICENSE.md](https://github.com/WebDevStudios/wd_f/blob/main/LICENSE.md) for complete license. diff --git a/docs/developers/_index.md b/docs/developers/_index.md index 17eabac..b4521c6 100644 --- a/docs/developers/_index.md +++ b/docs/developers/_index.md @@ -3,20 +3,14 @@ ## Custom Functions
-Building a block with wpcli +Scaffolding a block -

In order to build a block, run the following wpcli script.

- -

Note: If you're using Local, you can open the shell from within Local to do this. -Sitename -> Open site shell.

+

In order to build a block, run the following script.

-wp wds create_portable_block myblock --title="This is myblock" --desc="This block -is used for wds." --keyword="myblock" --icon="table-row-before" --namespace="wds" +npm run create-block myblock"

This will scaffold out a block inside of the blocks folder in the -theme. Replace myblock with the name of your block and update the -other items title, desc, keyword, icon, -namespace with the appropriate information.

+theme. Replace myblock with the name of your block and run npm run build to build the block.

diff --git a/functions.php b/functions.php index 01b0348..4587b9c 100644 --- a/functions.php +++ b/functions.php @@ -22,7 +22,6 @@ function include_inc_files() { 'inc/setup/', // Theme setup. 'inc/shortcodes/', // Load shortcodes. 'inc/template-tags/', // Custom template tags for this theme. - 'inc/wpcli/', // WPClI to create custom blocks. ]; foreach ( $files as $include ) { diff --git a/inc/block-template/README.md b/inc/block-template/README.md new file mode 100644 index 0000000..7ec9c9e --- /dev/null +++ b/inc/block-template/README.md @@ -0,0 +1,31 @@ +# WDS Block Template + +This template is configured to generate a block that is ready for block registration using the [`@wordpress/create-block`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/) tool. + +## Usage + +Run the following in the terminal of your choice: + +`npx @wordpress/create-block@latest --template ../inc/block-template` + + +## Structure + +Once the command has completed, the following structure will be created: + +``` text +- src +--> {example-block} +---> block.json +---> edit.js +---> editor.scss +---> index.js +---> save.js +---> style.scss +---> view.js +.editorconfig +.eslintrc +.gitignore +{example-block}.php +package.json +``` diff --git a/inc/block-template/block/edit.js.mustache b/inc/block-template/block/edit.js.mustache new file mode 100644 index 0000000..8957438 --- /dev/null +++ b/inc/block-template/block/edit.js.mustache @@ -0,0 +1,38 @@ +/** + * Retrieves the translation of text. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/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/reference-guides/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/reference-guides/block-api/block-edit-save/#edit + * + * @return {WPElement} Element to render. + */ +export default function Edit() { + return ( +

+ { __( '{{title}} – hello from the editor!', '{{textdomain}}' ) } +

+ ); +} diff --git a/inc/block-template/block/editor.scss.mustache b/inc/block-template/block/editor.scss.mustache new file mode 100644 index 0000000..7669ecd --- /dev/null +++ b/inc/block-template/block/editor.scss.mustache @@ -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-{{namespace}}-{{slug}} { + border: 1px dashed var(--wp--preset--color--black); +} diff --git a/inc/block-template/block/index.js.mustache b/inc/block-template/block/index.js.mustache new file mode 100644 index 0000000..ade1e47 --- /dev/null +++ b/inc/block-template/block/index.js.mustache @@ -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, { + /** + * @see ./edit.js + */ + edit: Edit, + + /** + * @see ./save.js + */ + save, +} ); diff --git a/inc/block-template/block/save.js.mustache b/inc/block-template/block/save.js.mustache new file mode 100644 index 0000000..eeb81e4 --- /dev/null +++ b/inc/block-template/block/save.js.mustache @@ -0,0 +1,24 @@ +/** + * 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/reference-guides/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/reference-guides/block-api/block-edit-save/#save + * + * @return {WPElement} Element to render. + */ +export default function save() { + return ( +

+ { '{{title}} – hello from the saved content!' } +

+ ); +} diff --git a/inc/block-template/block/style.scss.mustache b/inc/block-template/block/style.scss.mustache new file mode 100644 index 0000000..9a3a3e2 --- /dev/null +++ b/inc/block-template/block/style.scss.mustache @@ -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-{{namespace}}-{{slug}} { + background-color: var(--wp--preset--color--tertiary-300); + color: var(--wp--preset--color--white); + padding: var(--wp--preset--spacing--30); +} diff --git a/inc/block-template/block/view.js.mustache b/inc/block-template/block/view.js.mustache new file mode 100644 index 0000000..8871d5d --- /dev/null +++ b/inc/block-template/block/view.js.mustache @@ -0,0 +1,25 @@ +/** + * Use this file for JavaScript code that you want to run in the front-end + * on posts/pages that contain this block. + * + * When this file is defined as the value of the `viewScript` property + * in `block.json` it will be enqueued on the front end of the site. + * + * Example: + * + * ```js + * { + * "viewScript": "file:./view.js" + * } + * ``` + * + * If you're not making any changes to this file because your project doesn't need any + * JavaScript running in the front-end, then you should delete this file and remove + * the `viewScript` property from `block.json`. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#view-script + */ + +/* eslint-disable no-console */ +console.log( 'Hello World! (from {{namespaceSnakeCase}}_{{slugSnakeCase}} block)' ); +/* eslint-enable no-console */ diff --git a/inc/block-template/index.js b/inc/block-template/index.js new file mode 100644 index 0000000..e22d7cd --- /dev/null +++ b/inc/block-template/index.js @@ -0,0 +1,30 @@ +const { join } = require( 'path' ); + +module.exports = { + defaultValues: { + description: 'The Block Description', + author: 'WebDevStudios', + category: 'wds-blocks-category', + dashicon: 'pets', + namespace: 'wds', + folderName: 'src', + editorScript: 'file:./index.js', + editorStyle: 'file:./index.css', + style: 'file:./style-index.css', + viewScript: 'file:./view.js', + example: {}, + supports: { + html: false, + }, + attributes: {}, + customScripts: { + build: 'wp-scripts build', + start: 'wp-scripts start', + }, + devDependencies: { + '@wordpress/scripts': '^26.14.0', + }, + }, + templatesPath: join( __dirname, 'plugin' ), + blockTemplatesPath: join( __dirname, 'block' ), +}; diff --git a/inc/block-template/package.json b/inc/block-template/package.json new file mode 100644 index 0000000..712e7a7 --- /dev/null +++ b/inc/block-template/package.json @@ -0,0 +1,24 @@ +{ + "name": "wds-block-template", + "version": "1.0.0", + "description": "A template designed to be used with @wordpress/create-block for enabling custom core blocks.", + "author": { + "name": "WebDevStudios", + "url": "https://webdevstudios.com" + }, + "license": "GPL-2.0-or-later", + "keywords": [ + "wordpress", + "create block", + "block template", + "wds block" + ], + "homepage": "https://github.com/WebDevStudios/wd_f", + "repository": { + "type": "git", + "url": "https://github.com/WebDevStudios/wd_f" + }, + "bugs": { + "url": "https://github.com/WebDevStudios/wd_f/issues" + } +} diff --git a/inc/block-template/plugin/$slug.php.mustache b/inc/block-template/plugin/$slug.php.mustache new file mode 100644 index 0000000..133b94f --- /dev/null +++ b/inc/block-template/plugin/$slug.php.mustache @@ -0,0 +1,32 @@ + array(), - 'version' => false, -); diff --git a/inc/wpcli/block-starter/editor.js b/inc/wpcli/block-starter/editor.js deleted file mode 100644 index 626553d..0000000 --- a/inc/wpcli/block-starter/editor.js +++ /dev/null @@ -1 +0,0 @@ -// Editor JS here. diff --git a/inc/wpcli/block-starter/editor.scss b/inc/wpcli/block-starter/editor.scss deleted file mode 100644 index 9916658..0000000 --- a/inc/wpcli/block-starter/editor.scss +++ /dev/null @@ -1 +0,0 @@ -// Editor styles. diff --git a/inc/wpcli/block-starter/script.asset.php b/inc/wpcli/block-starter/script.asset.php deleted file mode 100644 index 505aed1..0000000 --- a/inc/wpcli/block-starter/script.asset.php +++ /dev/null @@ -1,5 +0,0 @@ - array(), - 'version' => false, -); diff --git a/inc/wpcli/block-starter/script.js b/inc/wpcli/block-starter/script.js deleted file mode 100644 index 89edcf1..0000000 --- a/inc/wpcli/block-starter/script.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Block script. - * - * @package - * @since 2.0.0 - */ - -// add JS here. diff --git a/inc/wpcli/block-starter/style.scss b/inc/wpcli/block-starter/style.scss deleted file mode 100644 index 4364ccb..0000000 --- a/inc/wpcli/block-starter/style.scss +++ /dev/null @@ -1 +0,0 @@ -// Frontend styles. diff --git a/inc/wpcli/class-blocks-scaffold.php b/inc/wpcli/class-blocks-scaffold.php deleted file mode 100644 index 28a42a6..0000000 --- a/inc/wpcli/class-blocks-scaffold.php +++ /dev/null @@ -1,320 +0,0 @@ - [--title=] [--desc=] [--keyword=] [--icon=] [--namespace=] - * - * ## OPTIONS - * - * - * : The block name. Must only have alphabetical characters. - * - * [--desc=] - * : The bloc description. - * - * [--keyword=] - * : They keyword for the block. - * - * [--icon=] - * : Block Icon. - * - * [--namespace=] - * : Block Namespace. - * : Default: WebDevStudios\wd_f - * - * ## EXAMPLES - * - * wp wds create_portable_block myblock --title="This is myblock" --desc="This block is used for wds." --keyword="myblock" --icon="table-row-before" --namespace="wds" - * @since 2.0.0 - * @param string $name The block name. - * @param array $assoc_args The block args. - */ - public function create_portable_block( $name, $assoc_args ) { - $this->name = esc_html( $name[0] ); - - // validate name. - if ( ! preg_match( '/^[a-zA-Z0-9\-]+$/', $this->name ) ) { - WP_CLI::error( 'Invalid name, Block name must only contain upper and lowercase letters.', true ); - } - - if ( ! isset( $args['namespace'] ) && preg_match( '/[\/\\\\]/', $assoc_args['namespace'] ) ) { - WP_CLI::error( 'Invalid namespace, Block namespace must not contain slashes.', true ); - } - - // Merge with default args. - $args = wp_parse_args( - $assoc_args, - [ - 'title' => ucfirst( $this->name ), - 'desc' => '', - 'keywords' => strtolower( $this->name ), - 'icon' => 'table-row-before', - 'namespace' => 'wds/', - ] - ); - - // create the directory. - $this->create_block_dir(); - - // create block json. - $this->create_block_json( $args ); - - // create block renderer. - $this->create_block_render_php( $args ); - - // create editor assets. - $this->create_block_editor_assets(); - - // create FE assets. - $this->create_block_assets(); - - WP_CLI::success( $this->name . ' block created.' ); - } - - /** - * Init file system. - * - * @since 2.0.0 - */ - private function init_filesystem() { - // File system support. - global $wp_filesystem; - require_once ABSPATH . '/wp-admin/includes/file.php'; - WP_Filesystem(); - - return $wp_filesystem; - } - - /** - * Create the block directory. - * - * @author Biplav Subedi - * @since 2.0.0 - */ - private function create_block_dir() { - $dir = ROOT_PATH . 'blocks/' . $this->name; - - if ( ! $this->init_filesystem()->exists( $dir ) ) { - $this->init_filesystem()->mkdir( $dir, 0755 ); - } else { - WP_CLI::error( 'Block directory already exists.', true ); - } - } - - /** - * Create the block render file. - * - * @param array $args Block details. - * @since 2.0.0 - * @author Biplav Subedi - */ - private function create_block_render_php( $args ) { - $local_file = ROOT_PATH . 'inc/wpcli/block-starter/block.php'; - $content = ''; - - if ( $this->init_filesystem()->exists( $local_file ) ) { - $content = $this->init_filesystem()->get_contents( $local_file ); - $content = str_replace( 'wds', $args['namespace'], $content ); - if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'blocks/' . $this->name . '/' . $this->name . '.php', $content ) ) { - WP_CLI::error( 'ERROR :: Could not create a render file.', true ); - } - } else { - WP_CLI::error( 'ERROR :: Could not create a render file.', true ); - } - - } - - /** - * Create the block json. - * - * @param array $args Block details. - * @since 2.0.0 - * @author Biplav Subedi - */ - private function create_block_json( $args ) { - $local_file = ROOT_PATH . 'inc/wpcli/block-starter/block.json'; - $content = ''; - - if ( $this->init_filesystem()->exists( $local_file ) ) { - $content = $this->init_filesystem()->get_contents( $local_file ); - $content = str_replace( - [ - '{{name}}', - '{{title}}', - '{{description}}', - '{{icon}}', - 'wds/', - '{{keyword}}', - ], - [ - $this->name, - $args['title'], - $args['desc'], - $args['icon'], - trailingslashit( $args['namespace'] ), - $args['keyword'], - ], - $content - ); - } - - if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'blocks/' . $this->name . '/block.json', $content ) ) { - WP_CLI::error( 'ERROR :: Could not create a block json file.', true ); - } - } - - /** - * Create the block editor assets. - * - * @since 2.0.0 - * @author Biplav Subedi - */ - private function create_block_editor_assets() { - $asset_js = ROOT_PATH . 'inc/wpcli/block-starter/editor.js'; - $asset_php = ROOT_PATH . 'inc/wpcli/block-starter/editor.asset.php'; - - $asset_scss = ROOT_PATH . 'inc/wpcli/block-starter/editor.scss'; - - if ( - ! $this->init_filesystem()->exists( $asset_js ) - || ! $this->init_filesystem()->exists( $asset_php ) - || ! $this->init_filesystem()->exists( $asset_scss ) - ) { - WP_CLI::error( 'ERROR :: Could not find editor assets.', true ); - } - - // copy editor js. - if ( ! $this->init_filesystem()->copy( $asset_js, ROOT_PATH . 'blocks/' . $this->name . '/editor.js' ) ) { - WP_CLI::error( 'ERROR :: Could not create editor js file.', true ); - } - // copy editor.asset.php. - if ( ! $this->init_filesystem()->copy( $asset_php, ROOT_PATH . 'blocks/' . $this->name . '/editor.asset.php' ) ) { - WP_CLI::error( 'ERROR :: Could not create editor asset php file.', true ); - } - - // copy styles. - if ( ! $this->init_filesystem()->copy( $asset_scss, ROOT_PATH . 'src/scss/blocks/custom/' . $this->name . '.editor.scss' ) ) { - WP_CLI::error( 'ERROR :: Could not create styles file.', true ); - } - - // add js file for build process. - if ( - ! $this->init_filesystem()->put_contents( - ROOT_PATH . 'src/js/blocks/custom/' . $this->name . '.editor.js', - "import '../../../scss/blocks/custom/" . $this->name . ".editor.scss';\n" - ) - ) { - WP_CLI::error( 'ERROR :: Could not create a block js style file.', true ); - } - } - - /** - * Create the block main styles. - * - * @since 2.0.0 - * @author Biplav Subedi - */ - private function create_block_assets() { - $asset_js = ROOT_PATH . 'inc/wpcli/block-starter/script.js'; - $asset_php = ROOT_PATH . 'inc/wpcli/block-starter/script.asset.php'; - - $asset_scss = ROOT_PATH . 'inc/wpcli/block-starter/style.scss'; - - if ( - ! $this->init_filesystem()->exists( $asset_js ) - || ! $this->init_filesystem()->exists( $asset_php ) - || ! $this->init_filesystem()->exists( $asset_scss ) - ) { - WP_CLI::error( 'ERROR :: Could not find block assets.', true ); - } - - // copy editor js. - if ( ! $this->init_filesystem()->copy( $asset_js, ROOT_PATH . 'blocks/' . $this->name . '/script.js' ) ) { - WP_CLI::error( 'ERROR :: Could not create script js file.', true ); - } - - // copy script.asset.php. - if ( ! $this->init_filesystem()->copy( $asset_php, ROOT_PATH . 'blocks/' . $this->name . '/script.asset.php' ) ) { - WP_CLI::error( 'ERROR :: Could not create script asset php file.', true ); - } - - // copy styles. - if ( ! $this->init_filesystem()->copy( $asset_scss, ROOT_PATH . 'src/scss/blocks/custom/' . $this->name . '.scss' ) ) { - WP_CLI::error( 'ERROR :: Could not create styles file.', true ); - } - - // add js file for build process. - if ( - ! $this->init_filesystem()->put_contents( - ROOT_PATH . 'src/js/blocks/custom/' . $this->name . '.js', - "import '../../../scss/blocks/custom/" . $this->name . ".scss';\n" - ) - ) { - WP_CLI::error( 'ERROR :: Could not create a block js style file.', true ); - } - } - -} - -/** - * Registers our command when cli get's initialized. - * - * @since 4.0.0 - * @author Biplav Subedi - * @return void - */ -function cli_register_commands() { - WP_CLI::add_command( 'wds', __NAMESPACE__ . '\Blocks_Scaffold' ); -} -add_action( 'cli_init', __NAMESPACE__ . '\cli_register_commands' ); - -/** - * Register Blocks - * - * @return void - * @author Jenna Hines - * @since 2.0.0 - */ -function wds_acf_register_blocks() { - $wds_acf_blocks = glob( ROOT_PATH . 'blocks/*/block.json' ); - - foreach ( $wds_acf_blocks as $block ) { - register_block_type( $block ); - } -} -add_action( 'init', __NAMESPACE__ . '\wds_acf_register_blocks' ); diff --git a/package.json b/package.json index 00cf077..b53ac97 100644 --- a/package.json +++ b/package.json @@ -61,11 +61,12 @@ }, "scripts": { "a11y": "pa11y-ci --reporter=pa11y-ci-reporter-html --sitemap $npm_config_url/sitemap.xml", - "build": "cross-env NODE_ENV=production wp-scripts build --config webpack.prod.js", + "build:blocks": "for dir in blocks/*/; do (cd \"$dir\" && npm run build); done", "build:pot": "composer run-script pot", - "build:all": "composer install --quiet && composer run-script pot && npm run build", + "build": "cross-env NODE_ENV=production wp-scripts build --config webpack.prod.js && npm run build:blocks", "check-engines": "wp-scripts check-engines", "check-licenses": "wp-scripts check-licenses", + "create-block": "cd blocks && npx @wordpress/create-block@latest --template ../inc/block-template --no-wp-scripts", "dev": "npm run watch", "format": "run-p format:*", "format:css": "npx prettier '**/*.scss' --write && npm run lint:css -- --fix",