diff --git a/Gruntfile.js b/Gruntfile.js index f96eda8ce5f61..4dcaf1e3e3fb7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -763,6 +763,39 @@ module.exports = function(grunt) { } ], }, 'gutenberg-styles': { + options: { + noProcess: [ '**/*', '!**/registry.php' ], + process: function( content ) { + /* + * Gutenberg's generated style registry does not currently + * meet Core's PHP coding standards. Format its known keys + * while copying it so build jobs do not require PHP tooling. + * + * @ticket 65278 + */ + const longestKey = 'dependencies'; + + return content.replace( + /^(\t\t)'(handle|path|dependencies)'\s*=>\s*([^\r\n]*)$/gm, + function( match, indentation, key, value ) { + const padding = ' '.repeat( longestKey.length - key.length + 1 ); + + if ( key === 'dependencies' ) { + value = value.replace( + /^array\((.*)\),$/, + function( array, dependencies ) { + dependencies = dependencies.trim(); + + return dependencies ? 'array( ' + dependencies + ' ),' : 'array(),'; + } + ); + } + + return indentation + '\'' + key + '\'' + padding + '=> ' + value; + } + ); + } + }, files: [ { expand: true, cwd: 'gutenberg/build/styles',