Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1fa3c17
Build: Update Gutenberg => Core integration
youknowriad Dec 16, 2025
a8dc192
Fix checkout script
youknowriad Dec 16, 2025
ce99e8c
Simplify checkout script
youknowriad Dec 16, 2025
1de6928
Automation: Updating built files with changes.
Dec 16, 2025
83e4525
Fix build
youknowriad Dec 16, 2025
13832c0
Disable auto-commit
youknowriad Dec 16, 2025
f9aae7e
Fix JSHint
youknowriad Dec 16, 2025
4fd202c
Consolidate block-json building
youknowriad Dec 16, 2025
cbca0e2
Fix windows build
youknowriad Dec 16, 2025
7654a5a
Fix unit tests
youknowriad Dec 16, 2025
cd57438
Disable auto-commit workflow temporarily
youknowriad Dec 16, 2025
dc6ba78
update snapshot modules unit tests
youknowriad Dec 16, 2025
f734da1
Update src built files
youknowriad Dec 16, 2025
7d294c2
Fix MathML
youknowriad Dec 16, 2025
85681d8
Revert "Disable auto-commit workflow temporarily"
youknowriad Dec 16, 2025
2e34e56
Revert "Disable auto-commit"
youknowriad Dec 16, 2025
75ff641
Use content hashes for versions
youknowriad Dec 16, 2025
bd1eae2
Shallow clone
youknowriad Dec 16, 2025
d2d8179
Stable build
youknowriad Dec 16, 2025
742bf3b
Automation: Updating built files with changes.
Dec 16, 2025
4a97017
Increase memory for the build process
youknowriad Dec 16, 2025
429fbc9
Remove gutenberg built process workflow: Now Gutenberg is always buil…
youknowriad Dec 17, 2025
78e9db2
Normalize paths betweens Operating systems
youknowriad Dec 17, 2025
8bedcb8
More stable version hashes
youknowriad Dec 17, 2025
6d828b6
Avoid linting removed files
youknowriad Dec 17, 2025
eff7b55
gitignore all of Gutenberg generated code
youknowriad Dec 17, 2025
c207b12
Simplify modules registration
youknowriad Dec 17, 2025
fe07bf3
Simplify build
youknowriad Dec 17, 2025
034169d
Fix block CSS building
youknowriad Dec 18, 2025
8b113a3
Format build files
youknowriad Dec 18, 2025
ce9e365
More copy simplifications
youknowriad Dec 18, 2025
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
Prev Previous commit
Next Next commit
Consolidate block-json building
  • Loading branch information
youknowriad committed Dec 16, 2025
commit 4fd202ca36eb4dcee6e05705e35f938ce1ce6a33
19 changes: 0 additions & 19 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/* globals Set */
var webpackConfig = require( './webpack.config' );
var installChanged = require( 'install-changed' );
var json2php = require( 'json2php' );

module.exports = function(grunt) {
var path = require('path'),
Expand Down Expand Up @@ -1630,23 +1629,6 @@ module.exports = function(grunt) {
}
} );

grunt.registerTask( 'copy:block-json', 'Copies block.json file contents to block-json.php.', function() {
var blocks = {};
grunt.file.recurse( SOURCE_DIR + 'wp-includes/blocks', function( abspath, rootdir, subdir, filename ) {
if ( /^block\.json$/.test( filename ) ) {
blocks[ subdir ] = grunt.file.readJSON( abspath );
}
} );
grunt.file.write(
SOURCE_DIR + 'wp-includes/blocks/blocks-json.php',
'<?php return ' + json2php.make( {
linebreak: '\n',
indent: ' ',
shortArraySyntax: false
} )( blocks ) + ';'
);
} );

grunt.registerTask( 'copy:js', [
'copy:npm-packages',
'copy:vendor-js',
Expand Down Expand Up @@ -1784,7 +1766,6 @@ module.exports = function(grunt) {
grunt.registerTask( 'build:files', [
'clean:files',
'copy:files',
'copy:block-json',
'copy:version',
] );

Expand Down
104 changes: 32 additions & 72 deletions tools/gutenberg/copy-gutenberg-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

const fs = require( 'fs' );
const path = require( 'path' );
const json2php = require( 'json2php' );

// Paths
const rootDir = path.resolve( __dirname, '../..' );
Expand Down Expand Up @@ -281,11 +282,18 @@ function generateScriptModulesPackages() {

processDirectory( modulesDir, modulesDir );

// Generate both minified and non-minified PHP files
const phpContentMin = `<?php return ${ phpEncode( assetsMin ) };
`;
const phpContentRegular = `<?php return ${ phpEncode( assetsRegular ) };
`;
// Generate both minified and non-minified PHP files using json2php
const phpContentMin = '<?php return ' + json2php.make( {
linebreak: '\n',
indent: ' ',
shortArraySyntax: false
} )( assetsMin ) + ';';

const phpContentRegular = '<?php return ' + json2php.make( {
linebreak: '\n',
indent: ' ',
shortArraySyntax: false
} )( assetsRegular ) + ';';

const outputPathMin = path.join( wpIncludesDir, 'assets/script-modules-packages.min.php' );
const outputPathRegular = path.join( wpIncludesDir, 'assets/script-modules-packages.php' );
Expand Down Expand Up @@ -354,11 +362,18 @@ function generateScriptLoaderPackages() {
}
}

// Generate both minified and non-minified PHP files
const phpContentMin = `<?php return ${ phpEncode( assetsMin ) };
`;
const phpContentRegular = `<?php return ${ phpEncode( assetsRegular ) };
`;
// Generate both minified and non-minified PHP files using json2php
const phpContentMin = '<?php return ' + json2php.make( {
linebreak: '\n',
indent: ' ',
shortArraySyntax: false
} )( assetsMin ) + ';';

const phpContentRegular = '<?php return ' + json2php.make( {
linebreak: '\n',
indent: ' ',
shortArraySyntax: false
} )( assetsRegular ) + ';';

const outputPathMin = path.join( wpIncludesDir, 'assets/script-loader-packages.min.php' );
const outputPathRegular = path.join( wpIncludesDir, 'assets/script-loader-packages.php' );
Expand Down Expand Up @@ -460,6 +475,7 @@ ${ staticBlocks.map( name => `\t'${ name }',` ).join( '\n' ) }
/**
* Generate blocks-json.php from all block.json files.
* Reads all block.json files and combines them into a single PHP array.
* Uses json2php to maintain consistency with Core's formatting.
*/
function generateBlocksJson() {
const blocksDir = path.join( wpIncludesDir, 'blocks' );
Expand Down Expand Up @@ -489,9 +505,12 @@ function generateBlocksJson() {
}
}

// Generate the PHP file content
const phpContent = `<?php return ${ phpEncode( blocks ) };
`;
// Generate the PHP file content using json2php for consistent formatting
const phpContent = '<?php return ' + json2php.make( {
linebreak: '\n',
indent: ' ',
shortArraySyntax: false
} )( blocks ) + ';';

fs.writeFileSync(
path.join( wpIncludesDir, 'blocks/blocks-json.php' ),
Expand Down Expand Up @@ -664,65 +683,6 @@ function parsePHPArray( phpArrayContent ) {
}
}

/**
* Convert JavaScript value to PHP representation.
* Similar to json2php used in Gruntfile.
*
* @param {*} value - Value to encode.
* @param {number} indent - Indentation level.
* @return {string} PHP representation.
*/
function phpEncode( value, indent = 0 ) {
const indentStr = ' '.repeat( indent );
const nextIndentStr = ' '.repeat( indent + 1 );

if ( value === null ) {
return 'null';
}

if ( typeof value === 'boolean' ) {
return value ? 'true' : 'false';
}

if ( typeof value === 'number' ) {
return String( value );
}

if ( typeof value === 'string' ) {
// Escape single quotes and backslashes
const escaped = value
.replace( /\\/g, '\\\\' )
.replace( /'/g, "\\'" );
return `'${ escaped }'`;
}

if ( Array.isArray( value ) ) {
if ( value.length === 0 ) {
return 'array()';
}

const items = value.map( item => `${ nextIndentStr }${ phpEncode( item, indent + 1 ) }` );
return `array(\n${ items.join( ',\n' ) }\n${ indentStr })`;
}

if ( typeof value === 'object' ) {
const keys = Object.keys( value );

if ( keys.length === 0 ) {
return 'array()';
}

const items = keys.map( key => {
const phpKey = phpEncode( key, indent + 1 );
const phpValue = phpEncode( value[ key ], indent + 1 );
return `${ nextIndentStr }${ phpKey } => ${ phpValue }`;
} );

return `array(\n${ items.join( ',\n' ) }\n${ indentStr })`;
}

return 'null';
}

/**
* Transform PHP file contents to work in Core.
Expand Down
Loading