Skip to content

Commit

Permalink
Build: Include block.json files in the build output
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Jan 21, 2020
1 parent 26062c8 commit b63a8c3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bin/build-plugin-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ npm run build
php bin/generate-gutenberg-php.php > gutenberg.tmp.php
mv gutenberg.tmp.php gutenberg.php

build_files=$(ls build/*/*.{js,css,asset.php} build/block-library/blocks/*.{php,json})
build_files=$(ls build/*/*.{js,css,asset.php} build/block-library/blocks/*/*.{php,json})

# Generate the plugin zip file.
status "Creating archive... 🎁"
Expand Down
44 changes: 22 additions & 22 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@ function gutenberg_reregister_core_block_types() {
}

$block_names = array(
'archives.php' => 'core/archives',
'block.php' => 'core/block',
'calendar.php' => 'core/calendar',
'categories.php' => 'core/categories',
'latest-comments.php' => 'core/latest-comments',
'latest-posts.php' => 'core/latest-posts',
'legacy-widget.php' => 'core/legacy-widget',
'navigation.php' => 'core/navigation',
'rss.php' => 'core/rss',
'shortcode.php' => 'core/shortcode',
'search.php' => 'core/search',
'social-link.php' => gutenberg_get_registered_social_link_blocks(),
'tag-cloud.php' => 'core/tag-cloud',
'site-title.php' => 'core/site-title',
'template-part.php' => 'core/template-part',
'post-title.php' => 'core/post-title',
'post-content.php' => 'core/post-content',
'post-author.php' => 'core/post-author',
'post-date.php' => 'core/post-date',
'post-excerpt.php' => 'core/post-excerpt',
'archives' => 'core/archives',
'block' => 'core/block',
'calendar' => 'core/calendar',
'categories' => 'core/categories',
'latest-comments' => 'core/latest-comments',
'latest-posts' => 'core/latest-posts',
'legacy-widget' => 'core/legacy-widget',
'navigation' => 'core/navigation',
'rss' => 'core/rss',
'shortcode' => 'core/shortcode',
'search' => 'core/search',
'social-link' => gutenberg_get_registered_social_link_blocks(),
'tag-cloud' => 'core/tag-cloud',
'site-title' => 'core/site-title',
'template-part' => 'core/template-part',
'post-title' => 'core/post-title',
'post-content' => 'core/post-content',
'post-author' => 'core/post-author',
'post-date' => 'core/post-date',
'post-excerpt' => 'core/post-excerpt',
);

$registry = WP_Block_Type_Registry::get_instance();

foreach ( $block_names as $file => $block_names ) {
foreach ( $block_names as $folder_name => $block_names ) {
if ( ! file_exists( $blocks_dir . $file ) ) {
return;
}
Expand All @@ -80,7 +80,7 @@ function gutenberg_reregister_core_block_types() {
}
}

require $blocks_dir . $file;
require $blocks_dir . $folder_name . '/index.php';
}
}
add_action( 'init', 'gutenberg_reregister_core_block_types' );
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/shortcode/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function render_block_core_shortcode( $attributes, $content ) {
* Registers the `core/shortcode` block on server.
*/
function register_block_core_shortcode() {
$path = __DIR__ . '/shortcode.json';
$path = realpath( __DIR__ . '/block.json' );
$metadata = json_decode( file_get_contents( $path ), true );
register_block_type(
'core/shortcode',
Expand Down
8 changes: 3 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module.exports = {
{
from: './packages/block-library/src/**/index.php',
test: new RegExp( `([\\w-]+)${ escapeRegExp( sep ) }index\\.php$` ),
to: 'build/block-library/blocks/[1].php',
to: 'build/block-library/blocks/[1]/index.php',
transform( content ) {
content = content.toString();

Expand Down Expand Up @@ -149,12 +149,10 @@ module.exports = {
.replace( /(add_action\(\s*'init',\s*'gutenberg_register_block_[^']+'(?!,))/, '$1, 20' );
},
},
] ),
new CopyWebpackPlugin( [
{
from: './packages/block-library/src/+(shortcode)/block.json',
from: './packages/block-library/src/*/block.json',
test: new RegExp( `([\\w-]+)${ escapeRegExp( sep ) }block\\.json$` ),
to: 'build/block-library/blocks/[1].json',
to: 'build/block-library/blocks/[1]/block.json',
},
] ),
new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ),
Expand Down

0 comments on commit b63a8c3

Please sign in to comment.