mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Tools: Automate backporting core blocks from Gutenberg to Core
Syncing stable blocks from the Gutenberg repository to wordpress-develop was a manual process, but it got automated with the script that runs together with syncing WordPress packages changed in the Gutenberg package. Props zieladam. Fixes #56179. git-svn-id: https://develop.svn.wordpress.org/trunk@53688 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1246,9 +1246,6 @@ module.exports = function(grunt) {
|
||||
* Update any non-@wordpress deps to the same version as required in the @wordpress packages (e.g. react 16 -> 17).
|
||||
*/
|
||||
grunt.task.run( 'wp-packages:refresh-deps' );
|
||||
|
||||
// Build the files stored in the src/ directory.
|
||||
grunt.task.run( 'build' );
|
||||
} );
|
||||
|
||||
grunt.renameTask( 'watch', '_watch' );
|
||||
@@ -1698,6 +1695,12 @@ module.exports = function(grunt) {
|
||||
} );
|
||||
} );
|
||||
|
||||
grunt.registerTask( 'wp-packages:sync-stable-blocks', 'Refresh the PHP files referring to stable @wordpress/block-library blocks.', function() {
|
||||
grunt.log.writeln( `Syncing stable blocks from @wordpress/block-library to src/` );
|
||||
const { main } = require( './tools/release/sync-stable-blocks' );
|
||||
main();
|
||||
} );
|
||||
|
||||
// Patch task.
|
||||
grunt.renameTask('patch_wordpress', 'patch');
|
||||
|
||||
|
||||
@@ -175,6 +175,7 @@
|
||||
"test:php": "node ./tools/local-env/scripts/docker.js run -T php composer update -W && node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit",
|
||||
"test:e2e": "node ./tests/e2e/run-tests.js",
|
||||
"test:visual": "node ./tests/visual-regression/run-tests.js",
|
||||
"sync-gutenberg-packages": "grunt sync-gutenberg-packages --dev"
|
||||
"sync-gutenberg-packages": "grunt sync-gutenberg-packages",
|
||||
"postsync-gutenberg-packages": "grunt wp-packages:sync-stable-blocks && grunt build --dev && grunt build"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,68 +5,12 @@
|
||||
* @package WordPress
|
||||
*/
|
||||
|
||||
define( 'BLOCKS_PATH', ABSPATH . WPINC . '/blocks/' );
|
||||
|
||||
// Include files required for core blocks registration.
|
||||
require ABSPATH . WPINC . '/blocks/archives.php';
|
||||
require ABSPATH . WPINC . '/blocks/avatar.php';
|
||||
require ABSPATH . WPINC . '/blocks/block.php';
|
||||
require ABSPATH . WPINC . '/blocks/calendar.php';
|
||||
require ABSPATH . WPINC . '/blocks/categories.php';
|
||||
require ABSPATH . WPINC . '/blocks/comment-author-name.php';
|
||||
require ABSPATH . WPINC . '/blocks/comment-content.php';
|
||||
require ABSPATH . WPINC . '/blocks/comment-date.php';
|
||||
require ABSPATH . WPINC . '/blocks/comment-edit-link.php';
|
||||
require ABSPATH . WPINC . '/blocks/comment-reply-link.php';
|
||||
require ABSPATH . WPINC . '/blocks/comment-template.php';
|
||||
require ABSPATH . WPINC . '/blocks/comments-pagination.php';
|
||||
require ABSPATH . WPINC . '/blocks/comments-pagination-next.php';
|
||||
require ABSPATH . WPINC . '/blocks/comments-pagination-numbers.php';
|
||||
require ABSPATH . WPINC . '/blocks/comments-pagination-previous.php';
|
||||
require ABSPATH . WPINC . '/blocks/comments-title.php';
|
||||
require ABSPATH . WPINC . '/blocks/cover.php';
|
||||
require ABSPATH . WPINC . '/blocks/file.php';
|
||||
require ABSPATH . WPINC . '/blocks/gallery.php';
|
||||
require ABSPATH . WPINC . '/blocks/home-link.php';
|
||||
require ABSPATH . WPINC . '/blocks/image.php';
|
||||
require ABSPATH . WPINC . '/blocks/latest-comments.php';
|
||||
require ABSPATH . WPINC . '/blocks/latest-posts.php';
|
||||
require ABSPATH . WPINC . '/blocks/legacy-widget.php';
|
||||
require ABSPATH . WPINC . '/blocks/loginout.php';
|
||||
require ABSPATH . WPINC . '/blocks/navigation.php';
|
||||
require ABSPATH . WPINC . '/blocks/navigation-link.php';
|
||||
require ABSPATH . WPINC . '/blocks/navigation-submenu.php';
|
||||
require ABSPATH . WPINC . '/blocks/page-list.php';
|
||||
require ABSPATH . WPINC . '/blocks/pattern.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-author.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-author-biography.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-comments.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-comments-form.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-content.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-date.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-excerpt.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-featured-image.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-navigation-link.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-template.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-terms.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-title.php';
|
||||
require ABSPATH . WPINC . '/blocks/query.php';
|
||||
require ABSPATH . WPINC . '/blocks/query-no-results.php';
|
||||
require ABSPATH . WPINC . '/blocks/query-pagination.php';
|
||||
require ABSPATH . WPINC . '/blocks/query-pagination-next.php';
|
||||
require ABSPATH . WPINC . '/blocks/query-pagination-numbers.php';
|
||||
require ABSPATH . WPINC . '/blocks/query-pagination-previous.php';
|
||||
require ABSPATH . WPINC . '/blocks/query-title.php';
|
||||
require ABSPATH . WPINC . '/blocks/read-more.php';
|
||||
require ABSPATH . WPINC . '/blocks/rss.php';
|
||||
require ABSPATH . WPINC . '/blocks/search.php';
|
||||
require ABSPATH . WPINC . '/blocks/shortcode.php';
|
||||
require ABSPATH . WPINC . '/blocks/site-logo.php';
|
||||
require ABSPATH . WPINC . '/blocks/site-tagline.php';
|
||||
require ABSPATH . WPINC . '/blocks/site-title.php';
|
||||
require ABSPATH . WPINC . '/blocks/social-link.php';
|
||||
require ABSPATH . WPINC . '/blocks/tag-cloud.php';
|
||||
require ABSPATH . WPINC . '/blocks/template-part.php';
|
||||
require ABSPATH . WPINC . '/blocks/term-description.php';
|
||||
require ABSPATH . WPINC . '/blocks/widget-group.php';
|
||||
require BLOCKS_PATH . 'legacy-widget.php';
|
||||
require BLOCKS_PATH . 'widget-group.php';
|
||||
require BLOCKS_PATH . 'require-dynamic-blocks.php';
|
||||
|
||||
/**
|
||||
* Registers core block types using metadata files.
|
||||
@@ -75,40 +19,10 @@ require ABSPATH . WPINC . '/blocks/widget-group.php';
|
||||
* @since 5.5.0
|
||||
*/
|
||||
function register_core_block_types_from_metadata() {
|
||||
$block_folders = array(
|
||||
'audio',
|
||||
'button',
|
||||
'buttons',
|
||||
'code',
|
||||
'column',
|
||||
'columns',
|
||||
'comments-query-loop',
|
||||
'embed',
|
||||
'freeform',
|
||||
'group',
|
||||
'heading',
|
||||
'html',
|
||||
'list',
|
||||
'media-text',
|
||||
'missing',
|
||||
'more',
|
||||
'nextpage',
|
||||
'paragraph',
|
||||
'preformatted',
|
||||
'pullquote',
|
||||
'quote',
|
||||
'separator',
|
||||
'social-links',
|
||||
'spacer',
|
||||
'table',
|
||||
'text-columns',
|
||||
'verse',
|
||||
'video',
|
||||
);
|
||||
|
||||
$block_folders = require BLOCKS_PATH . 'require-static-blocks.php';
|
||||
foreach ( $block_folders as $block_folder ) {
|
||||
register_block_type(
|
||||
ABSPATH . WPINC . '/blocks/' . $block_folder
|
||||
BLOCKS_PATH . $block_folder
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
63
src/wp-includes/blocks/require-dynamic-blocks.php
Normal file
63
src/wp-includes/blocks/require-dynamic-blocks.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
// This file was autogenerated by tools/release/sync-stable-blocks.js, do not change manually!
|
||||
// Requires files for dynamic blocks necessary for core blocks registration.
|
||||
require ABSPATH . WPINC . '/blocks/archives.php';
|
||||
require ABSPATH . WPINC . '/blocks/avatar.php';
|
||||
require ABSPATH . WPINC . '/blocks/block.php';
|
||||
require ABSPATH . WPINC . '/blocks/calendar.php';
|
||||
require ABSPATH . WPINC . '/blocks/categories.php';
|
||||
require ABSPATH . WPINC . '/blocks/comment-author-name.php';
|
||||
require ABSPATH . WPINC . '/blocks/comment-content.php';
|
||||
require ABSPATH . WPINC . '/blocks/comment-date.php';
|
||||
require ABSPATH . WPINC . '/blocks/comment-edit-link.php';
|
||||
require ABSPATH . WPINC . '/blocks/comment-reply-link.php';
|
||||
require ABSPATH . WPINC . '/blocks/comment-template.php';
|
||||
require ABSPATH . WPINC . '/blocks/comments-pagination-next.php';
|
||||
require ABSPATH . WPINC . '/blocks/comments-pagination-numbers.php';
|
||||
require ABSPATH . WPINC . '/blocks/comments-pagination-previous.php';
|
||||
require ABSPATH . WPINC . '/blocks/comments-pagination.php';
|
||||
require ABSPATH . WPINC . '/blocks/comments-title.php';
|
||||
require ABSPATH . WPINC . '/blocks/cover.php';
|
||||
require ABSPATH . WPINC . '/blocks/file.php';
|
||||
require ABSPATH . WPINC . '/blocks/gallery.php';
|
||||
require ABSPATH . WPINC . '/blocks/home-link.php';
|
||||
require ABSPATH . WPINC . '/blocks/image.php';
|
||||
require ABSPATH . WPINC . '/blocks/latest-comments.php';
|
||||
require ABSPATH . WPINC . '/blocks/latest-posts.php';
|
||||
require ABSPATH . WPINC . '/blocks/loginout.php';
|
||||
require ABSPATH . WPINC . '/blocks/navigation-link.php';
|
||||
require ABSPATH . WPINC . '/blocks/navigation-submenu.php';
|
||||
require ABSPATH . WPINC . '/blocks/navigation.php';
|
||||
require ABSPATH . WPINC . '/blocks/page-list.php';
|
||||
require ABSPATH . WPINC . '/blocks/pattern.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-author.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-author-biography.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-comments.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-comments-form.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-content.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-date.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-excerpt.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-featured-image.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-navigation-link.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-template.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-terms.php';
|
||||
require ABSPATH . WPINC . '/blocks/post-title.php';
|
||||
require ABSPATH . WPINC . '/blocks/query-no-results.php';
|
||||
require ABSPATH . WPINC . '/blocks/query-pagination-next.php';
|
||||
require ABSPATH . WPINC . '/blocks/query-pagination-numbers.php';
|
||||
require ABSPATH . WPINC . '/blocks/query-pagination-previous.php';
|
||||
require ABSPATH . WPINC . '/blocks/query-pagination.php';
|
||||
require ABSPATH . WPINC . '/blocks/query-title.php';
|
||||
require ABSPATH . WPINC . '/blocks/query.php';
|
||||
require ABSPATH . WPINC . '/blocks/read-more.php';
|
||||
require ABSPATH . WPINC . '/blocks/rss.php';
|
||||
require ABSPATH . WPINC . '/blocks/search.php';
|
||||
require ABSPATH . WPINC . '/blocks/shortcode.php';
|
||||
require ABSPATH . WPINC . '/blocks/site-logo.php';
|
||||
require ABSPATH . WPINC . '/blocks/site-tagline.php';
|
||||
require ABSPATH . WPINC . '/blocks/site-title.php';
|
||||
require ABSPATH . WPINC . '/blocks/social-link.php';
|
||||
require ABSPATH . WPINC . '/blocks/tag-cloud.php';
|
||||
require ABSPATH . WPINC . '/blocks/template-part.php';
|
||||
require ABSPATH . WPINC . '/blocks/term-description.php';
|
||||
34
src/wp-includes/blocks/require-static-blocks.php
Normal file
34
src/wp-includes/blocks/require-static-blocks.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
// This file was autogenerated by tools/release/sync-stable-blocks.js, do not change manually!
|
||||
// Returns folder names for static blocks necessary for core blocks registration.
|
||||
return array(
|
||||
'audio',
|
||||
'button',
|
||||
'buttons',
|
||||
'code',
|
||||
'column',
|
||||
'columns',
|
||||
'comments-query-loop',
|
||||
'embed',
|
||||
'freeform',
|
||||
'group',
|
||||
'heading',
|
||||
'html',
|
||||
'list',
|
||||
'media-text',
|
||||
'missing',
|
||||
'more',
|
||||
'nextpage',
|
||||
'paragraph',
|
||||
'preformatted',
|
||||
'pullquote',
|
||||
'quote',
|
||||
'separator',
|
||||
'social-links',
|
||||
'spacer',
|
||||
'table',
|
||||
'text-columns',
|
||||
'verse',
|
||||
'video',
|
||||
);
|
||||
@@ -332,66 +332,9 @@ tests_add_filter( 'send_auth_cookies', '__return_false' );
|
||||
* @since 5.0.0
|
||||
*/
|
||||
function _unhook_block_registration() {
|
||||
remove_action( 'init', 'register_block_core_archives' );
|
||||
remove_action( 'init', 'register_block_core_avatar' );
|
||||
remove_action( 'init', 'register_block_core_block' );
|
||||
remove_action( 'init', 'register_block_core_calendar' );
|
||||
remove_action( 'init', 'register_block_core_categories' );
|
||||
remove_action( 'init', 'register_block_core_comment_author_name' );
|
||||
remove_action( 'init', 'register_block_core_comment_content' );
|
||||
remove_action( 'init', 'register_block_core_comment_date' );
|
||||
remove_action( 'init', 'register_block_core_comment_edit_link' );
|
||||
remove_action( 'init', 'register_block_core_comment_reply_link' );
|
||||
remove_action( 'init', 'register_block_core_comment_template' );
|
||||
remove_action( 'init', 'register_block_core_comments_pagination' );
|
||||
remove_action( 'init', 'register_block_core_comments_pagination_next' );
|
||||
remove_action( 'init', 'register_block_core_comments_pagination_numbers' );
|
||||
remove_action( 'init', 'register_block_core_comments_pagination_previous' );
|
||||
remove_action( 'init', 'register_block_core_comments_title' );
|
||||
remove_action( 'init', 'register_block_core_cover' );
|
||||
remove_action( 'init', 'register_block_core_file' );
|
||||
remove_action( 'init', 'register_block_core_gallery' );
|
||||
remove_action( 'init', 'register_block_core_home_link' );
|
||||
remove_action( 'init', 'register_block_core_image' );
|
||||
remove_action( 'init', 'register_block_core_latest_comments' );
|
||||
remove_action( 'init', 'register_block_core_latest_posts' );
|
||||
require __DIR__ . '/unregister-blocks-hooks.php';
|
||||
remove_action( 'init', 'register_core_block_types_from_metadata' );
|
||||
remove_action( 'init', 'register_block_core_legacy_widget' );
|
||||
remove_action( 'init', 'register_block_core_loginout' );
|
||||
remove_action( 'init', 'register_block_core_navigation' );
|
||||
remove_action( 'init', 'register_block_core_navigation_link' );
|
||||
remove_action( 'init', 'register_block_core_navigation_submenu' );
|
||||
remove_action( 'init', 'register_block_core_page_list' );
|
||||
remove_action( 'init', 'register_block_core_pattern' );
|
||||
remove_action( 'init', 'register_block_core_post_author' );
|
||||
remove_action( 'init', 'register_block_core_post_author_biography' );
|
||||
remove_action( 'init', 'register_block_core_post_comments' );
|
||||
remove_action( 'init', 'register_block_core_post_comments_form' );
|
||||
remove_action( 'init', 'register_block_core_post_content' );
|
||||
remove_action( 'init', 'register_block_core_post_date' );
|
||||
remove_action( 'init', 'register_block_core_post_excerpt' );
|
||||
remove_action( 'init', 'register_block_core_post_featured_image' );
|
||||
remove_action( 'init', 'register_block_core_post_navigation_link' );
|
||||
remove_action( 'init', 'register_block_core_post_template' );
|
||||
remove_action( 'init', 'register_block_core_post_terms' );
|
||||
remove_action( 'init', 'register_block_core_post_title' );
|
||||
remove_action( 'init', 'register_block_core_query' );
|
||||
remove_action( 'init', 'register_block_core_query_no_results' );
|
||||
remove_action( 'init', 'register_block_core_query_pagination' );
|
||||
remove_action( 'init', 'register_block_core_query_pagination_next' );
|
||||
remove_action( 'init', 'register_block_core_query_pagination_numbers' );
|
||||
remove_action( 'init', 'register_block_core_query_pagination_previous' );
|
||||
remove_action( 'init', 'register_block_core_query_title' );
|
||||
remove_action( 'init', 'register_block_core_read_more' );
|
||||
remove_action( 'init', 'register_block_core_rss' );
|
||||
remove_action( 'init', 'register_block_core_search' );
|
||||
remove_action( 'init', 'register_block_core_shortcode' );
|
||||
remove_action( 'init', 'register_block_core_site_logo' );
|
||||
remove_action( 'init', 'register_block_core_site_tagline' );
|
||||
remove_action( 'init', 'register_block_core_site_title' );
|
||||
remove_action( 'init', 'register_block_core_social_link' );
|
||||
remove_action( 'init', 'register_block_core_tag_cloud' );
|
||||
remove_action( 'init', 'register_block_core_template_part' );
|
||||
remove_action( 'init', 'register_block_core_term_description' );
|
||||
remove_action( 'init', 'register_block_core_widget_group' );
|
||||
remove_action( 'init', 'register_core_block_types_from_metadata' );
|
||||
}
|
||||
|
||||
62
tests/phpunit/includes/unregister-blocks-hooks.php
Normal file
62
tests/phpunit/includes/unregister-blocks-hooks.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
// This file was autogenerated by tools/release/sync-stable-blocks.js, do not change manually!
|
||||
remove_action( 'init', 'register_block_core_archives' );
|
||||
remove_action( 'init', 'register_block_core_avatar' );
|
||||
remove_action( 'init', 'register_block_core_block' );
|
||||
remove_action( 'init', 'register_block_core_calendar' );
|
||||
remove_action( 'init', 'register_block_core_categories' );
|
||||
remove_action( 'init', 'register_block_core_comment_author_name' );
|
||||
remove_action( 'init', 'register_block_core_comment_content' );
|
||||
remove_action( 'init', 'register_block_core_comment_date' );
|
||||
remove_action( 'init', 'register_block_core_comment_edit_link' );
|
||||
remove_action( 'init', 'register_block_core_comment_reply_link' );
|
||||
remove_action( 'init', 'register_block_core_comment_template' );
|
||||
remove_action( 'init', 'register_block_core_comments_pagination' );
|
||||
remove_action( 'init', 'register_block_core_comments_pagination_next' );
|
||||
remove_action( 'init', 'register_block_core_comments_pagination_numbers' );
|
||||
remove_action( 'init', 'register_block_core_comments_pagination_previous' );
|
||||
remove_action( 'init', 'register_block_core_comments_title' );
|
||||
remove_action( 'init', 'register_block_core_cover' );
|
||||
remove_action( 'init', 'register_block_core_file' );
|
||||
remove_action( 'init', 'register_block_core_gallery' );
|
||||
remove_action( 'init', 'register_block_core_home_link' );
|
||||
remove_action( 'init', 'register_block_core_image' );
|
||||
remove_action( 'init', 'register_block_core_latest_comments' );
|
||||
remove_action( 'init', 'register_block_core_latest_posts' );
|
||||
remove_action( 'init', 'register_block_core_loginout' );
|
||||
remove_action( 'init', 'register_block_core_navigation' );
|
||||
remove_action( 'init', 'register_block_core_navigation_link' );
|
||||
remove_action( 'init', 'register_block_core_navigation_submenu' );
|
||||
remove_action( 'init', 'register_block_core_page_list' );
|
||||
remove_action( 'init', 'register_block_core_pattern' );
|
||||
remove_action( 'init', 'register_block_core_post_author' );
|
||||
remove_action( 'init', 'register_block_core_post_author_biography' );
|
||||
remove_action( 'init', 'register_block_core_post_comments' );
|
||||
remove_action( 'init', 'register_block_core_post_comments_form' );
|
||||
remove_action( 'init', 'register_block_core_post_content' );
|
||||
remove_action( 'init', 'register_block_core_post_date' );
|
||||
remove_action( 'init', 'register_block_core_post_excerpt' );
|
||||
remove_action( 'init', 'register_block_core_post_featured_image' );
|
||||
remove_action( 'init', 'register_block_core_post_navigation_link' );
|
||||
remove_action( 'init', 'register_block_core_post_template' );
|
||||
remove_action( 'init', 'register_block_core_post_terms' );
|
||||
remove_action( 'init', 'register_block_core_post_title' );
|
||||
remove_action( 'init', 'register_block_core_query' );
|
||||
remove_action( 'init', 'register_block_core_query_no_results' );
|
||||
remove_action( 'init', 'register_block_core_query_pagination' );
|
||||
remove_action( 'init', 'register_block_core_query_pagination_next' );
|
||||
remove_action( 'init', 'register_block_core_query_pagination_numbers' );
|
||||
remove_action( 'init', 'register_block_core_query_pagination_previous' );
|
||||
remove_action( 'init', 'register_block_core_query_title' );
|
||||
remove_action( 'init', 'register_block_core_read_more' );
|
||||
remove_action( 'init', 'register_block_core_rss' );
|
||||
remove_action( 'init', 'register_block_core_search' );
|
||||
remove_action( 'init', 'register_block_core_shortcode' );
|
||||
remove_action( 'init', 'register_block_core_site_logo' );
|
||||
remove_action( 'init', 'register_block_core_site_tagline' );
|
||||
remove_action( 'init', 'register_block_core_site_title' );
|
||||
remove_action( 'init', 'register_block_core_social_link' );
|
||||
remove_action( 'init', 'register_block_core_tag_cloud' );
|
||||
remove_action( 'init', 'register_block_core_template_part' );
|
||||
remove_action( 'init', 'register_block_core_term_description' );
|
||||
144
tools/release/sync-stable-blocks.js
Normal file
144
tools/release/sync-stable-blocks.js
Normal file
@@ -0,0 +1,144 @@
|
||||
/* eslint-disable no-console */
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
const fs = require( 'fs' );
|
||||
const path = require( 'path' );
|
||||
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const BLOCK_LIBRARY_SRC = 'node_modules/@wordpress/block-library/src/';
|
||||
|
||||
const REPOSITORY_ROOT = path.dirname( path.dirname( __dirname ) );
|
||||
|
||||
/**
|
||||
* The main function of this task.
|
||||
*
|
||||
* Refreshes the PHP files referring to stable @wordpress/block-library blocks.
|
||||
*/
|
||||
function main() {
|
||||
const blocks = getStableBlocksMetadata();
|
||||
const toolWarningMessage = '// This file was autogenerated by tools/release/sync-stable-blocks.js, do not change manually!';
|
||||
|
||||
// wp-includes/blocks/require-blocks.php
|
||||
console.log( 'Refreshing wp-includes/blocks/require-static-blocks.php...' );
|
||||
const staticBlockFolderNames = blocks
|
||||
.filter( ( metadata ) => ! isDynamic( metadata ) )
|
||||
.map( toDirectoryName )
|
||||
.sort()
|
||||
// To the block folder name statement:
|
||||
.map( dirname => ` '${ dirname }',` )
|
||||
.join( "\n" );
|
||||
|
||||
fs.writeFileSync(
|
||||
`${ REPOSITORY_ROOT }/src/wp-includes/blocks/require-static-blocks.php`,
|
||||
`<?php
|
||||
|
||||
${ toolWarningMessage }
|
||||
// Returns folder names for static blocks necessary for core blocks registration.
|
||||
return array(
|
||||
${ staticBlockFolderNames }
|
||||
);
|
||||
`,
|
||||
);
|
||||
|
||||
// wp-includes/blocks/require-blocks.php
|
||||
console.log( 'Refreshing wp-includes/blocks/require-dynamic-blocks.php...' );
|
||||
const dynamicBlockFileRequires = blocks
|
||||
.filter( isDynamic )
|
||||
.map( toDirectoryName )
|
||||
.sort()
|
||||
// To PHP require statement:
|
||||
.map( dirname => `require ABSPATH . WPINC . '/blocks/${ dirname }.php';` )
|
||||
.join( "\n" );
|
||||
|
||||
fs.writeFileSync(
|
||||
`${ REPOSITORY_ROOT }/src/wp-includes/blocks/require-dynamic-blocks.php`,
|
||||
`<?php
|
||||
|
||||
${ toolWarningMessage }
|
||||
// Requires files for dynamic blocks necessary for core blocks registration.
|
||||
${ dynamicBlockFileRequires }
|
||||
`,
|
||||
);
|
||||
|
||||
// tests/phpunit/includes/unregister-blocks-hooks.php
|
||||
console.log( 'Refreshing tests/phpunit/includes/unregister-blocks-hooks.php...' );
|
||||
const unregisterHooks = blocks.filter( isDynamic )
|
||||
.map( function toHookName( metadata ) {
|
||||
const php = fs.readFileSync( path.join( metadata.path, '..', 'index.php' ) ).toString();
|
||||
let hookName = php.substring( php.indexOf( "add_action( 'init', 'register_block_core_" ) );
|
||||
return hookName.split( "'" )[ 3 ];
|
||||
} )
|
||||
.sort()
|
||||
.map( function toUnregisterCall( hookName ) {
|
||||
return `remove_action( 'init', '${ hookName }' );`;
|
||||
} )
|
||||
.join( "\n" );
|
||||
|
||||
fs.writeFileSync(
|
||||
`${ REPOSITORY_ROOT }/tests/phpunit/includes/unregister-blocks-hooks.php`,
|
||||
`<?php
|
||||
|
||||
${ toolWarningMessage }
|
||||
${ unregisterHooks }
|
||||
`,
|
||||
);
|
||||
console.log( 'Done!' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of unserialized block.json metadata of the
|
||||
* stable blocks shipped with the currently installed version
|
||||
* of the @wordpress/block-library package/
|
||||
*
|
||||
* @return {Array} List of stable blocks metadata.
|
||||
*/
|
||||
function getStableBlocksMetadata() {
|
||||
return (
|
||||
fs.readdirSync( BLOCK_LIBRARY_SRC )
|
||||
.map( dirMaybe => path.join( BLOCK_LIBRARY_SRC, dirMaybe, 'block.json' ) )
|
||||
.filter( fs.existsSync )
|
||||
.map( blockJsonPath => ( {
|
||||
...JSON.parse( fs.readFileSync( blockJsonPath ) ),
|
||||
path: blockJsonPath,
|
||||
} ) )
|
||||
.filter( metadata => (
|
||||
!( '__experimental' in metadata ) || metadata.__experimental === false
|
||||
) )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the specified metadata refers to a dynamic block.
|
||||
*
|
||||
* @param {Object} metadata Block metadata in question.
|
||||
* @return {boolean} Is it a dynamic block?
|
||||
*/
|
||||
function isDynamic( metadata ) {
|
||||
return (
|
||||
fs.existsSync( path.join( metadata.path, '..', 'index.php' ) )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a name of the directory where a given block resides.
|
||||
*
|
||||
* @param {Object} metadata Block metadata in question.
|
||||
* @return {string} Parent directory name.
|
||||
*/
|
||||
function toDirectoryName( metadata ) {
|
||||
return (
|
||||
path.basename( path.dirname( metadata.path ) )
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
main,
|
||||
isDynamic,
|
||||
toDirectoryName,
|
||||
getStableBlocksMetadata,
|
||||
};
|
||||
|
||||
/* eslint-enable no-console */
|
||||
Reference in New Issue
Block a user