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
This commit is contained in:
Grzegorz (Greg) Ziółkowski 2020-02-02 19:17:07 +00:00
parent 3f050fcf63
commit 84f4d42cbb

View File

@ -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,
],
),
],