Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix block assets compilation #1122

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions inc/hooks/register-blocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Register custom blocks for the WD_S theme.
*
* @package wd_s
*/

namespace WebDevStudios\wd_s;

/**
* Register Blocks
*
* @return void
*
* @author Jenna Hines
* @since 2.0.0
*/
function acf_register_blocks() {
$wds_acf_blocks = glob( ROOT_PATH . 'build/*/block.json' );

foreach ( $wds_acf_blocks as $block ) {
register_block_type( $block );
}
}
add_action( 'init', __NAMESPACE__ . '\acf_register_blocks' );
4 changes: 2 additions & 2 deletions inc/wpcli/block-starter/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"title": "{{title}}",
"description": "{{description}}",
"editorScript": "file:./editor.js",
"editorStyle": "file:../../build/{{name}}.editor.css",
"editorStyle": "file:./editor.css",
"script": "file:./script.js",
"style": "file:../../build/{{name}}.css",
"style": "file:./style-script.css",
"category": "wds-blocks-category",
"icon": "{{icon}}",
"keywords": [ "{{name}}", "{{keyword}}", "block" ],
Expand Down
12 changes: 6 additions & 6 deletions inc/wpcli/class-blocks-scaffold.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,15 @@ private function create_block_editor_assets() {
}

// copy styles.
if ( ! $this->init_filesystem()->copy( $asset_scss, ROOT_PATH . 'assets/scss/blocks/custom/' . $this->name . '.editor.scss' ) ) {
if ( ! $this->init_filesystem()->copy( $asset_scss, ROOT_PATH . 'blocks/' . $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 . 'assets/js/blocks/custom/' . $this->name . '.editor.js',
"import '../../../scss/blocks/custom/" . $this->name . ".editor.scss';\n"
ROOT_PATH . 'blocks/' . $this->name . '/editor.js',
"import './editor.scss';\n"
)
) {
WP_CLI::error( 'ERROR :: Could not create a block js style file.', true );
Expand Down Expand Up @@ -268,15 +268,15 @@ private function create_block_assets() {
}

// copy styles.
if ( ! $this->init_filesystem()->copy( $asset_scss, ROOT_PATH . 'assets/scss/blocks/custom/' . $this->name . '.scss' ) ) {
if ( ! $this->init_filesystem()->copy( $asset_scss, ROOT_PATH . 'blocks/' . $this->name . '/style.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 . 'assets/js/blocks/custom/' . $this->name . '.js',
"import '../../../scss/blocks/custom/" . $this->name . ".scss';\n"
ROOT_PATH . 'blocks/' . $this->name . '/script.js',
"import './style.scss';\n"
)
) {
WP_CLI::error( 'ERROR :: Could not create a block js style file.', true );
Expand Down
16 changes: 0 additions & 16 deletions inc/wpcli/wpcli.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,3 @@ 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 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__ . '\acf_register_blocks' );
Loading
Loading