Skip to content
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ module.exports = function(grunt) {
src: 'vendor/composer/ca-bundle/res/cacert.pem',
dest: SOURCE_DIR + 'wp-includes/certificates/ca-bundle.crt'
},
// Gutenberg PHP infrastructure files (routes.php, pages.php, constants.php, pages/, routes/).
// Gutenberg PHP infrastructure files (pages.php, constants.php, pages/).
'gutenberg-php': {
options: {
process: function( content ) {
Expand All @@ -616,22 +616,35 @@ module.exports = function(grunt) {
expand: true,
cwd: 'gutenberg/build',
src: [
'routes.php',
'pages.php',
'constants.php',
Comment thread
desrosj marked this conversation as resolved.
'pages/**/*.php',
'routes/**/*.php',
],
dest: WORKING_DIR + 'wp-includes/build/',
} ],
},
/*
* Only copy files relevant to the routes specified in the registry file.
*
* While the registry file does not contain any experimental routes, the `gutenberg/build/routes` directory
* includes the files for all registered routes. Only the files related to the routes specified in the
* registry should be included in the WordPress build.
*
* The `src` list is populated at task runtime by `routes:setup`, which reads the registry after
* `gutenberg:download` has run. See the `routes:setup` task registration for implementation details.
*/
routes: {
expand: true,
cwd: 'gutenberg/build',
src: [],
dest: WORKING_DIR + 'wp-includes/build/',
},
'gutenberg-js': {
files: [ {
expand: true,
cwd: 'gutenberg/build',
src: [
'pages/**/*.js',
'routes/**/*.js',
],
dest: WORKING_DIR + 'wp-includes/build/',
} ],
Expand Down Expand Up @@ -2052,8 +2065,34 @@ module.exports = function(grunt) {
} );
} );

grunt.registerTask( 'routes:setup', 'Reads the routes registry and configures the copy:routes task.', function() {
var registryPath = 'gutenberg/build/routes/registry.php';
if ( ! fs.existsSync( registryPath ) ) {
grunt.fatal(
'Route registry not found at ' + registryPath + '. Run `grunt gutenberg:download` first.'
);
}
var registryContent = fs.readFileSync( registryPath, 'utf8' );
var routeNames = [];
var namePattern = /'name'\s*=>\s*'([^']+)'/g;
var match;
while ( ( match = namePattern.exec( registryContent ) ) !== null ) {
routeNames.push( match[ 1 ] );
}
Comment thread
desrosj marked this conversation as resolved.
grunt.config( [ 'copy', 'routes', 'src' ], [ 'routes/registry.php' ].concat(
routeNames.flatMap( function( name ) {
return [
'routes/' + name + '/**/*.php',
'routes/' + name + '/**/*.js',
];
Comment thread
desrosj marked this conversation as resolved.
} )
) );
} );

grunt.registerTask( 'build:gutenberg', [
'copy:gutenberg-php',
'routes:setup',
'copy:routes',
'copy:gutenberg-js',
'gutenberg:copy',
'copy:gutenberg-modules',
Expand Down
Loading