diff --git a/INSTALLATION.md b/INSTALLATION.md index 55f7a44..3967a3d 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -128,11 +128,11 @@ Run the following commands in the root directory to build the project: composer install npm ci && npm run build ``` -(See `packages/themes/block-theme` or `packages/plugins/blueprint` for more details) +(See `packages/themes/block-theme` for more details) ## Extending Builds -Project Base uses [wp-scripts](https://github.com/WordPress/gutenberg/tree/trunk/packages/scripts) out of the box for building front-end/view and editor assets. wp-script will scan all `block.json` files in the `src/` folder to find available entries. This means that if you have a `src` folder with a `view.js` and a `editor.js`, you also need to add a `block.json` file at the same location. Have a look in the `block-theme` theme or the `blueprint` plugin for examples or read up on [wp-script auto discovery for Webpack entry points](https://github.com/WordPress/gutenberg/blob/trunk/packages/scripts/utils/config.js#L198). For a more advanced setup, you can always customize builds by adding your own `webpack.config.js`. +Project Base uses [wp-scripts](https://github.com/WordPress/gutenberg/tree/trunk/packages/scripts) out of the box for building front-end/view and editor assets. wp-script will scan all `block.json` files in the `src/` folder to find available entries. This means that if you have a `src` folder with a `view.js` and a `editor.js`, you also need to add a `block.json` file at the same location. Have a look in the `block-theme` theme for example or read up on [wp-script auto discovery for Webpack entry points](https://github.com/WordPress/gutenberg/blob/trunk/packages/scripts/utils/config.js#L198). For a more advanced setup, you can always customize builds by adding your own `webpack.config.js`. ### A quick overview of wp-scripts auto discovery: 1. Supply entry points manully to the CLI, e.g. `wp-scripts build src/view src/editor src/admin src/some-other-entry`. This will bypass 2 and 3. diff --git a/composer.json b/composer.json index e5181dd..515f5c1 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,6 @@ "boxuk/wp-muplugin-loader": "~2.2.0", "composer/installers": "~2.3.0", "dekode/block-theme": "~1.0.0", - "dekode/blueprint": "~1.0.0", "dekodeinteraktiv/dekode-label-environment": "~1.0.0", "inpsyde/wp-translation-downloader": "~2.5.0", "roots/wordpress": "~6.6.2", diff --git a/composer.lock b/composer.lock index 0424201..1c9c9bc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "bd32bb5ec7abf2c723bc9c20d093f133", + "content-hash": "5eadeba949a9068f35ca7ce1432dda32", "packages": [ { "name": "boxuk/wp-muplugin-loader", @@ -251,24 +251,6 @@ "relative": true } }, - { - "name": "dekode/blueprint", - "version": "1.0.0", - "dist": { - "type": "path", - "url": "packages/plugins/blueprint", - "reference": "b3b2b31922a1bdc5c651e5dcb8586616f3652cc0" - }, - "type": "wordpress-plugin", - "license": [ - "GPL-3.0-or-later" - ], - "description": "Blueprint plugin with assets and blocks.", - "transport-options": { - "symlink": true, - "relative": true - } - }, { "name": "dekodeinteraktiv/dekode-label-environment", "version": "1.0.2", @@ -1729,13 +1711,13 @@ ], "aliases": [], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": true, "prefer-lowest": false, "platform": { "php": ">=8.2" }, - "platform-dev": [], + "platform-dev": {}, "platform-overrides": { "php": "8.2" }, diff --git a/packages/plugins/blueprint/composer.json b/packages/plugins/blueprint/composer.json deleted file mode 100644 index 5305f48..0000000 --- a/packages/plugins/blueprint/composer.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "dekode/blueprint", - "description": "Blueprint plugin with assets and blocks.", - "type": "wordpress-plugin", - "license": "GPL-3.0-or-later", - "version": "1.0.0" -} diff --git a/packages/plugins/blueprint/package.json b/packages/plugins/blueprint/package.json deleted file mode 100644 index 80401c8..0000000 --- a/packages/plugins/blueprint/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "@dekode/blueprint", - "version": "1.0.0", - "devDependencies": { - "@wordpress/dom-ready": "^4.8.0", - "@wordpress/scripts": "^30.0.2" - }, - "scripts": { - "build": "wp-scripts build --webpack-copy-php", - "start": "wp-scripts start --webpack-copy-php", - "clean": "rm -rf node_modules build dist .turbo" - } -} diff --git a/packages/plugins/blueprint/plugin.php b/packages/plugins/blueprint/plugin.php deleted file mode 100644 index 58803ad..0000000 --- a/packages/plugins/blueprint/plugin.php +++ /dev/null @@ -1,101 +0,0 @@ - require_once $f, \glob( __DIR__ . '/build/*/block.php' ) ); - -// Hooks. -\add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\do_enqueue_assets' ); -\add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\do_enqueue_block_editor_assets' ); -\add_action( 'init', __NAMESPACE__ . '\\load_textdomain' ); -\add_filter( 'allowed_block_types_all', __NAMESPACE__ . '\\do_override_allowed_block_types_all', 50 ); - -/** - * Enqueue frontend scripts and styles. - * - * @return void - */ -function do_enqueue_assets(): void { - do_enqueue_plugin_assets( 'view', [ 'block-theme' ], [ 'block-theme' ] ); -} - -/** - * Enqueue block editor scripts and styles. - * - * @return void - */ -function do_enqueue_block_editor_assets(): void { - do_enqueue_plugin_assets( 'editor', [ 'block-theme' ] ); -} - -/** - * Load plugin text domain. - * - * @return void. - */ -function load_textdomain(): void { - \load_plugin_textdomain( 'blueprint', false, \dirname( \plugin_basename( __FILE__ ) ) . '/languages' ); -} - -/** - * Automatically whitelist all block library block types. - * - * @param array|bool $blocks Allowed block types. - * @return array|bool - */ -function do_override_allowed_block_types_all( $blocks ) { - if ( ! \is_array( $blocks ) ) { - return $blocks; - } - - $block_library_blocks = \array_map( function ( string $path ): string { - $block_meta = get_block_meta( $path ); - return $block_meta['name']; - }, \glob( __DIR__ . '/src/*', GLOB_ONLYDIR ) ); - - return \array_merge( $blocks, $block_library_blocks ); -} - - -/** - * Enqueue plugin assets for entry. - * - * @param string $entry View or editor. - * @param array $style_dependencies Stylesheet dependenies. - * @param array $script_dependencies Script dependenies. - * @return void - */ -function do_enqueue_plugin_assets( string $entry = 'view', array $style_dependencies = [], array $script_dependencies = [] ): void { - $plugin_path = \plugin_dir_path( __FILE__ ); - $script_deps_file = \get_template_directory() . "/build/$entry.asset.php"; - - // Bundled stylesheet. - if ( \file_exists( "$plugin_path/build/$entry.css" ) ) { - $assets_version = \filemtime( "$plugin_path/build/$entry.css" ); - \wp_enqueue_style( 'blueprint', \plugins_url( "build/$entry.css", __FILE__ ), $style_dependencies, $assets_version ); - } - - // Bundled scripts. - if ( \file_exists( "$plugin_path/build/$entry.js" ) && \file_exists( $script_deps_file ) ) { - $dependencies = require $script_deps_file; - $dependencies = \array_merge( $dependencies, $script_dependencies ); - \wp_enqueue_script( 'blueprint', \plugins_url( "build/$entry.js", __FILE__ ), $dependencies['dependencies'], $dependencies['version'], true ); - } -} diff --git a/packages/plugins/blueprint/src/block.json b/packages/plugins/blueprint/src/block.json deleted file mode 100644 index d97e40f..0000000 --- a/packages/plugins/blueprint/src/block.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 3, - "editorScript": "file:editor.js", - "viewScript": "file:view.js" -} diff --git a/packages/plugins/blueprint/src/editor.css b/packages/plugins/blueprint/src/editor.css deleted file mode 100644 index ff71124..0000000 --- a/packages/plugins/blueprint/src/editor.css +++ /dev/null @@ -1 +0,0 @@ -/* stylelint-disable no-empty-source */ diff --git a/packages/plugins/blueprint/src/editor.js b/packages/plugins/blueprint/src/editor.js deleted file mode 100644 index ff10eea..0000000 --- a/packages/plugins/blueprint/src/editor.js +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Internal dependencies - */ -import './editor.css'; diff --git a/packages/plugins/blueprint/src/view.css b/packages/plugins/blueprint/src/view.css deleted file mode 100644 index ff71124..0000000 --- a/packages/plugins/blueprint/src/view.css +++ /dev/null @@ -1 +0,0 @@ -/* stylelint-disable no-empty-source */ diff --git a/packages/plugins/blueprint/src/view.js b/packages/plugins/blueprint/src/view.js deleted file mode 100644 index df11609..0000000 --- a/packages/plugins/blueprint/src/view.js +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Internal dependencies - */ -import './view.css'; diff --git a/packages/themes/block-theme/functions.php b/packages/themes/block-theme/functions.php index 308fece..47f89e6 100644 --- a/packages/themes/block-theme/functions.php +++ b/packages/themes/block-theme/functions.php @@ -6,6 +6,7 @@ */ declare( strict_types = 1 ); + defined( 'ABSPATH' ) || exit; // Autoload package Composer dependencies. @@ -15,3 +16,6 @@ // Require all files in includes folder. \array_map( fn( $f ) => require_once $f, \glob( __DIR__ . '/includes/*.php' ) ); + +// Require all block.php files in build/ folder. +\array_map( fn( $f ) => require_once $f, \glob( __DIR__ . '/build/*/block.php' ) ); diff --git a/packages/plugins/blueprint/src/example-block/block.json b/packages/themes/block-theme/src/example-block/block.json similarity index 92% rename from packages/plugins/blueprint/src/example-block/block.json rename to packages/themes/block-theme/src/example-block/block.json index 8499105..eb4f59b 100644 --- a/packages/plugins/blueprint/src/example-block/block.json +++ b/packages/themes/block-theme/src/example-block/block.json @@ -7,7 +7,7 @@ "icon": "menu", "description": "Example block", "attributes": {}, - "textdomain": "blueprint", + "textdomain": "block-theme", "supports": { "html": false, "align": ["wide"] diff --git a/packages/plugins/blueprint/src/example-block/block.php b/packages/themes/block-theme/src/example-block/block.php similarity index 100% rename from packages/plugins/blueprint/src/example-block/block.php rename to packages/themes/block-theme/src/example-block/block.php diff --git a/packages/plugins/blueprint/src/example-block/editor.js b/packages/themes/block-theme/src/example-block/editor.js similarity index 100% rename from packages/plugins/blueprint/src/example-block/editor.js rename to packages/themes/block-theme/src/example-block/editor.js diff --git a/packages/plugins/blueprint/src/example-block/view.js b/packages/themes/block-theme/src/example-block/view.js similarity index 100% rename from packages/plugins/blueprint/src/example-block/view.js rename to packages/themes/block-theme/src/example-block/view.js