Skip to content

Commit 55bd7a2

Browse files
committed
Merge branch 'fix/gutenberg-clean-before-build' into fix/missing-new-files
2 parents 03b1817 + 640397b commit 55bd7a2

2 files changed

Lines changed: 49 additions & 34 deletions

File tree

Gruntfile.js

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = function(grunt) {
4747
'wp-includes/js/',
4848
],
4949

50-
// All files copied from the Gutenberg repository excluded from version control.
50+
// Unversioned files copied from the Gutenberg repository.
5151
gutenbergFiles = [
5252
'wp-includes/js/dist',
5353
'wp-includes/css/dist',
@@ -56,6 +56,14 @@ module.exports = function(grunt) {
5656
'wp-includes/icons',
5757
],
5858

59+
// Files copied from Gutenberg subject to version control.
60+
gutenbergVersionedFiles = [
61+
'wp-includes/images/icon-library',
62+
'wp-includes/build',
63+
'wp-includes/blocks/*',
64+
'!wp-includes/blocks/index.php',
65+
],
66+
5967
// All files built by Webpack, in /src or /build.
6068
// Webpack only builds Core-specific media files and development scripts.
6169
// Blocks, packages, script modules, and vendors come from the Gutenberg build.
@@ -246,6 +254,25 @@ module.exports = function(grunt) {
246254
gutenberg: gutenbergFiles.map( function( file ) {
247255
return setFilePath( WORKING_DIR, file );
248256
}),
257+
258+
/*
259+
* Delete directories and files subjet to version control where the contents come from Gutenberg.
260+
*
261+
* This handles instances where a file remains present even after being deleted upstream.
262+
*
263+
* This task is intentionally skipped unless the current task will re-copy the corresponding files.
264+
*/
265+
'gutenberg-versioned': {
266+
filter: function() {
267+
var allowedTasks = [ 'build', 'build:dev', 'build:gutenberg', 'clean:gutenberg-versioned' ];
268+
return allowedTasks.some( function( task ) {
269+
return grunt.cli.tasks.indexOf( task ) !== -1;
270+
} );
271+
},
272+
src: gutenbergVersionedFiles.map( function( file ) {
273+
return setFilePath( SOURCE_DIR, file );
274+
} ),
275+
},
249276
dynamic: {
250277
dot: true,
251278
expand: true,
@@ -667,7 +694,7 @@ module.exports = function(grunt) {
667694
'constants.php',
668695
'pages/**/*.php',
669696
],
670-
dest: WORKING_DIR + 'wp-includes/build/',
697+
dest: SOURCE_DIR + 'wp-includes/build/',
671698
} ],
672699
},
673700
/*
@@ -684,7 +711,7 @@ module.exports = function(grunt) {
684711
expand: true,
685712
cwd: 'gutenberg/build',
686713
src: [],
687-
dest: WORKING_DIR + 'wp-includes/build/',
714+
dest: SOURCE_DIR + 'wp-includes/build/',
688715
},
689716
'gutenberg-js': {
690717
files: [ {
@@ -693,7 +720,7 @@ module.exports = function(grunt) {
693720
src: [
694721
'pages/**/*.js',
695722
],
696-
dest: WORKING_DIR + 'wp-includes/build/',
723+
dest: SOURCE_DIR + 'wp-includes/build/',
697724
} ],
698725
},
699726
'gutenberg-modules': {
@@ -707,7 +734,7 @@ module.exports = function(grunt) {
707734
// with no debugging value over the minified versions.
708735
'!vips/!(*.min).js',
709736
],
710-
dest: WORKING_DIR + 'wp-includes/js/dist/script-modules/',
737+
dest: SOURCE_DIR + 'wp-includes/js/dist/script-modules/',
711738
} ],
712739
},
713740
'gutenberg-styles': {
@@ -720,7 +747,7 @@ module.exports = function(grunt) {
720747
// Per-block CSS is copied to wp-includes/blocks/ by tools/gutenberg/copy.js.
721748
'!block-library/*/**',
722749
],
723-
dest: WORKING_DIR + 'wp-includes/css/dist/',
750+
dest: SOURCE_DIR + 'wp-includes/css/dist/',
724751
} ],
725752
},
726753
'gutenberg-theme-json': {
@@ -739,11 +766,11 @@ module.exports = function(grunt) {
739766
files: [
740767
{
741768
src: 'gutenberg/lib/theme.json',
742-
dest: WORKING_DIR + 'wp-includes/theme.json',
769+
dest: SOURCE_DIR + 'wp-includes/theme.json',
743770
},
744771
{
745772
src: 'gutenberg/lib/theme-i18n.json',
746-
dest: WORKING_DIR + 'wp-includes/theme-i18n.json',
773+
dest: SOURCE_DIR + 'wp-includes/theme-i18n.json',
747774
},
748775
],
749776
},
@@ -752,7 +779,7 @@ module.exports = function(grunt) {
752779
expand: true,
753780
cwd: 'gutenberg/packages/icons/src/library',
754781
src: '*.svg',
755-
dest: WORKING_DIR + 'wp-includes/images/icon-library',
782+
dest: SOURCE_DIR + 'wp-includes/images/icon-library',
756783
} ],
757784
},
758785
'icon-library-manifest': {
@@ -774,7 +801,7 @@ module.exports = function(grunt) {
774801
},
775802
files: [ {
776803
src: 'gutenberg/packages/icons/src/manifest.php',
777-
dest: WORKING_DIR + 'wp-includes/assets/icon-library-manifest.php',
804+
dest: SOURCE_DIR + 'wp-includes/assets/icon-library-manifest.php',
778805
} ],
779806
},
780807
},
@@ -1678,10 +1705,9 @@ module.exports = function(grunt) {
16781705

16791706
grunt.registerTask( 'gutenberg:copy', 'Copies Gutenberg JS packages and block assets to WordPress Core.', function() {
16801707
const done = this.async();
1681-
const buildDir = grunt.option( 'dev' ) ? 'src' : 'build';
16821708
grunt.util.spawn( {
16831709
cmd: 'node',
1684-
args: [ 'tools/gutenberg/copy.js', `--build-dir=${ buildDir }` ],
1710+
args: [ 'tools/gutenberg/copy.js' ],
16851711
opts: { stdio: 'inherit' }
16861712
}, function( error ) {
16871713
done( ! error );
@@ -2158,6 +2184,8 @@ module.exports = function(grunt) {
21582184
} );
21592185

21602186
grunt.registerTask( 'build:gutenberg', [
2187+
'gutenberg:verify',
2188+
'clean:gutenberg-versioned',
21612189
'clean:gutenberg',
21622190
'copy:gutenberg-php',
21632191
'routes:setup',
@@ -2174,24 +2202,22 @@ module.exports = function(grunt) {
21742202
grunt.registerTask( 'build', function() {
21752203
if ( grunt.option( 'dev' ) ) {
21762204
grunt.task.run( [
2177-
'gutenberg:verify',
2205+
'build:gutenberg',
21782206
'build:js',
21792207
'build:css',
21802208
'build:codemirror',
2181-
'build:gutenberg',
2182-
'build:certificates'
2209+
'build:certificates',
21832210
] );
21842211
} else {
21852212
grunt.task.run( [
2186-
'gutenberg:verify',
2187-
'build:certificates',
2213+
'build:gutenberg',
21882214
'build:files',
21892215
'build:js',
21902216
'build:css',
21912217
'build:codemirror',
2192-
'build:gutenberg',
2218+
'build:certificates',
21932219
'replace:source-maps',
2194-
'verify:build'
2220+
'verify:build',
21952221
] );
21962222
}
21972223
} );

tools/gutenberg/copy.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,10 @@ const rootDir = path.resolve( __dirname, '../..' );
1919
const gutenbergDir = path.join( rootDir, 'gutenberg' );
2020
const gutenbergBuildDir = path.join( gutenbergDir, 'build' );
2121

22-
/*
23-
* Determine build target from command line argument (--dev or --build-dir).
24-
* Default to 'src' for development.
25-
*/
26-
const args = process.argv.slice( 2 );
27-
const buildDirArg = args.find( ( arg ) => arg.startsWith( '--build-dir=' ) );
28-
const buildTarget = buildDirArg
29-
? buildDirArg.split( '=' )[ 1 ]
30-
: args.includes( '--dev' )
31-
? 'src'
32-
: 'build';
33-
34-
const wpIncludesDir = path.join( rootDir, buildTarget, 'wp-includes' );
22+
// All files handled in this script are subject to version control, so they should always be placed into src/.
23+
const wpIncludesDir = path.join( rootDir, 'src', 'wp-includes' );
3524

36-
/**
25+
/*
3726
* Copy configuration.
3827
* Defines what to copy from Gutenberg build and where it goes in Core.
3928
*/
@@ -508,7 +497,7 @@ function generateBlocksJson() {
508497
* Main execution function.
509498
*/
510499
async function main() {
511-
console.log( `📦 Copying Gutenberg build to ${ buildTarget }/...` );
500+
console.log( '📦 Copying versioned Gutenberg files to src/...' );
512501

513502
if ( ! fs.existsSync( gutenbergBuildDir ) ) {
514503
console.error( '❌ Gutenberg build directory not found' );

0 commit comments

Comments
 (0)