From 84f4d42cbb30663c85559d4b28f94298b990d2e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=28Greg=29=20Zi=C3=83=C2=B3=C3=85=E2=80=9Akowsk?= =?UTF-8?q?i?= Date: Sun, 2 Feb 2020 19:17:07 +0000 Subject: [PATCH] Build: Copy block metadata files for dynamic blocks. For dynamic blocks, there are several blocks whose metadata needs to be loaded in PHP. The attributes that are loaded via PHP are not exposed to the ReactNative components when Gutenberg loads the index.js files in the Mobile Apps. To support one master set of metadata that can be used to register in the PHP files and the Javascript files; with this patch, the block.json files are copied over with their corresponding PHP files. Props chipsnyder and azaozz. Fixes #49196. git-svn-id: https://develop.svn.wordpress.org/trunk@47168 602fd350-edb4-49c9-b593-d223f7449a82 --- tools/webpack/packages.js | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/tools/webpack/packages.js b/tools/webpack/packages.js index e58b5274f3..ab9e2fdef1 100644 --- a/tools/webpack/packages.js +++ b/tools/webpack/packages.js @@ -94,18 +94,29 @@ module.exports = function( env = { environment: 'production', watch: false, buil 'wp-polyfill-node-contains.min.js': 'polyfill-library/polyfills/Node/prototype/contains/polyfill.js', }; + const blockNames = [ + 'archives', + 'block', + 'calendar', + 'categories', + 'latest-comments', + 'latest-posts', + 'rss', + 'search', + 'shortcode', + 'tag-cloud', + ]; const phpFiles = { 'block-serialization-default-parser/parser.php': 'wp-includes/class-wp-block-parser.php', - 'block-library/src/archives/index.php': 'wp-includes/blocks/archives.php', - 'block-library/src/block/index.php': 'wp-includes/blocks/block.php', - 'block-library/src/calendar/index.php': 'wp-includes/blocks/calendar.php', - 'block-library/src/categories/index.php': 'wp-includes/blocks/categories.php', - 'block-library/src/latest-comments/index.php': 'wp-includes/blocks/latest-comments.php', - 'block-library/src/latest-posts/index.php': 'wp-includes/blocks/latest-posts.php', - 'block-library/src/rss/index.php': 'wp-includes/blocks/rss.php', - 'block-library/src/search/index.php': 'wp-includes/blocks/search.php', - 'block-library/src/shortcode/index.php': 'wp-includes/blocks/shortcode.php', - 'block-library/src/tag-cloud/index.php': 'wp-includes/blocks/tag-cloud.php', + ...blockNames.reduce( ( files, blockName ) => { + files[ `block-library/src/${ blockName }/index.php` ] = `wp-includes/blocks/${ blockName }.php`; + return files; + } , {} ), + }; + const blockMetadataCopies = { + from: join( baseDir, `node_modules/@wordpress/block-library/src/+(${ blockNames.join( '|' ) })/block.json` ), + test: new RegExp( `\/([^/]+)\/block\.json$` ), + to: join( baseDir, `${ buildTarget }/blocks/[1]/block.json` ), }; const developmentCopies = mapVendorCopies( vendors, buildTarget ); @@ -231,6 +242,7 @@ module.exports = function( env = { environment: 'production', watch: false, buil ...vendorCopies, ...cssCopies, ...phpCopies, + blockMetadataCopies, ], ), ],