diff --git a/tools/gutenberg/copy-gutenberg-build.js b/tools/gutenberg/copy-gutenberg-build.js index e5332f806f74a..fdd332c35eb24 100644 --- a/tools/gutenberg/copy-gutenberg-build.js +++ b/tools/gutenberg/copy-gutenberg-build.js @@ -12,6 +12,7 @@ const fs = require( 'fs' ); const path = require( 'path' ); const json2php = require( 'json2php' ); +const glob = require( 'glob' ); // Paths const rootDir = path.resolve( __dirname, '../..' ); @@ -98,6 +99,18 @@ const COPY_CONFIG = { { from: 'theme-i18n.json', to: 'theme-i18n.json' }, ], }, + + // Specific files to copy to wp-includes/$destination + wpIncludes: [ + { + files: [ 'packages/icons/src/manifest.php' ], + destination: 'icons', + }, + { + files: [ 'packages/icons/src/library/*.svg' ], + destination: 'icons/library', + }, + ], }; /** @@ -982,10 +995,7 @@ async function main() { } } } - } else if ( - entry.isFile() && - entry.name.endsWith( '.js' ) - ) { + } else if ( entry.isFile() && entry.name.endsWith( '.js' ) ) { // Copy root-level JS files const dest = path.join( scriptsDest, entry.name ); fs.mkdirSync( path.dirname( dest ), { recursive: true } ); @@ -1057,6 +1067,25 @@ async function main() { } } + // Copy remaining files to wp-includes + console.log( '\n📦 Copying remaining files to wp-includes...' ); + for ( const fileMap of COPY_CONFIG.wpIncludes ) { + const dest = path.join( wpIncludesDir, fileMap.destination ); + fs.mkdirSync( dest, { recursive: true } ); + for ( const src of fileMap.files ) { + const matches = glob.sync( path.join( gutenbergDir, src ) ); + if ( ! matches.length ) { + throw new Error( `No files found matching '${ src }'` ); + } + for ( const match of matches ) { + fs.copyFileSync( + match, + path.join( dest, path.basename( match ) ) + ); + } + } + } + // 7. Generate script-modules-packages.min.php from individual asset files console.log( '\n📦 Generating script-modules-packages.min.php...' ); generateScriptModulesPackages();