diff --git a/Gruntfile.js b/Gruntfile.js index 61f18481e23a8..eff6674f503e0 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -751,6 +751,42 @@ module.exports = function(grunt) { } ], }, 'gutenberg-styles': { + options: { + process: function( content, srcpath ) { + if ( path.basename( srcpath ) !== 'registry.php' ) { + return 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',