Skip to content

Commit 9fb661c

Browse files
committed
Tools: Simplify syncing core blocks from Gutenberg plugin to Core
Follow-up [53688]. Removes the hardcoded list of blocks that should be synced from the Gutenberg plugin. webpack reads all information from the `@wordpress/block-library` by scanning `block.json` files. Props zieladam, azaozz. Fixes #56179. git-svn-id: https://develop.svn.wordpress.org/trunk@54308 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 00d2562 commit 9fb661c

File tree

1 file changed

+12
-96
lines changed

1 file changed

+12
-96
lines changed

tools/webpack/blocks.js

Lines changed: 12 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -13,120 +13,36 @@ const DependencyExtractionPlugin = require( '@wordpress/dependency-extraction-we
1313
* Internal dependencies
1414
*/
1515
const { normalizeJoin, stylesTransform, baseConfig, baseDir } = require( './shared' );
16+
const {
17+
isDynamic,
18+
toDirectoryName,
19+
getStableBlocksMetadata,
20+
} = require( '../release/sync-stable-blocks' );
1621

1722
module.exports = function( env = { environment: 'production', watch: false, buildTarget: false } ) {
1823
const mode = env.environment;
1924
const suffix = mode === 'production' ? '.min' : '';
2025
let buildTarget = env.buildTarget ? env.buildTarget : ( mode === 'production' ? 'build' : 'src' );
21-
buildTarget = buildTarget + '/wp-includes';
26+
buildTarget = buildTarget + '/wp-includes';
2227

23-
const dynamicBlockFolders = [
24-
'archives',
25-
'avatar',
26-
'block',
27-
'calendar',
28-
'categories',
29-
'comment-author-name',
30-
'comment-content',
31-
'comment-date',
32-
'comment-edit-link',
33-
'comment-reply-link',
34-
'comment-template',
35-
'comments',
36-
'comments-pagination',
37-
'comments-pagination-next',
38-
'comments-pagination-numbers',
39-
'comments-pagination-previous',
40-
'comments-title',
41-
'cover',
42-
'file',
43-
'gallery',
44-
'home-link',
45-
'image',
46-
'latest-comments',
47-
'latest-posts',
48-
'loginout',
49-
'navigation',
50-
'navigation-link',
51-
'navigation-submenu',
52-
'page-list',
53-
'pattern',
54-
'post-author',
55-
'post-author-biography',
56-
'post-comments-form',
57-
'post-content',
58-
'post-date',
59-
'post-excerpt',
60-
'post-featured-image',
61-
'post-navigation-link',
62-
'post-template',
63-
'post-terms',
64-
'post-title',
65-
'query',
66-
'query-no-results',
67-
'query-pagination',
68-
'query-pagination-next',
69-
'query-pagination-numbers',
70-
'query-pagination-previous',
71-
'query-title',
72-
'read-more',
73-
'rss',
74-
'search',
75-
'shortcode',
76-
'site-logo',
77-
'site-tagline',
78-
'site-title',
79-
'social-link',
80-
'tag-cloud',
81-
'template-part',
82-
'term-description',
83-
];
84-
const blockFolders = [
85-
'audio',
86-
'button',
87-
'buttons',
88-
'code',
89-
'column',
90-
'columns',
91-
'embed',
92-
'freeform',
93-
'group',
94-
'heading',
95-
'html',
96-
'list',
97-
'list-item',
98-
'media-text',
99-
'missing',
100-
'more',
101-
'nextpage',
102-
'paragraph',
103-
'preformatted',
104-
'pullquote',
105-
'quote',
106-
'separator',
107-
'social-links',
108-
'spacer',
109-
'table',
110-
'text-columns',
111-
'verse',
112-
'video',
113-
...dynamicBlockFolders,
114-
];
28+
const blocks = getStableBlocksMetadata();
29+
const dynamicBlockFolders = blocks.filter( isDynamic ).map( toDirectoryName );
30+
const blockFolders = blocks.map( toDirectoryName );
11531
const blockPHPFiles = {
11632
'widgets/src/blocks/legacy-widget/index.php': 'wp-includes/blocks/legacy-widget.php',
11733
'widgets/src/blocks/widget-group/index.php': 'wp-includes/blocks/widget-group.php',
11834
...dynamicBlockFolders.reduce( ( files, blockName ) => {
11935
files[ `block-library/src/${ blockName }/index.php` ] = `wp-includes/blocks/${ blockName }.php`;
12036
return files;
121-
} , {} ),
37+
}, {} ),
12238
};
12339
const blockMetadataFiles = {
12440
'widgets/src/blocks/legacy-widget/block.json': 'wp-includes/blocks/legacy-widget/block.json',
12541
'widgets/src/blocks/widget-group/block.json': 'wp-includes/blocks/widget-group/block.json',
12642
...blockFolders.reduce( ( files, blockName ) => {
12743
files[ `block-library/src/${ blockName }/block.json` ] = `wp-includes/blocks/${ blockName }/block.json`;
12844
return files;
129-
} , {} ),
45+
}, {} ),
13046
};
13147

13248
const blockPHPCopies = Object.keys( blockPHPFiles ).map( ( filename ) => ( {
@@ -163,7 +79,7 @@ module.exports = function( env = { environment: 'production', watch: false, buil
16379
// Inject the `IS_GUTENBERG_PLUGIN` global, used for feature flagging.
16480
'process.env.IS_GUTENBERG_PLUGIN': false,
16581
'process.env.FORCE_REDUCED_MOTION': JSON.stringify(
166-
process.env.FORCE_REDUCED_MOTION
82+
process.env.FORCE_REDUCED_MOTION,
16783
),
16884
} ),
16985
new DependencyExtractionPlugin( {

0 commit comments

Comments
 (0)