Skip to content

Commit 640397b

Browse files
committed
Ensure files deleted in gutenberg are removed.
1 parent b3341ca commit 640397b

2 files changed

Lines changed: 43 additions & 28 deletions

File tree

Gruntfile.js

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,22 @@ 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',
54-
'wp-includes/images/icon-library',
5554
// Old location kept temporarily to ensure they are cleaned up.
5655
'wp-includes/icons',
5756
],
5857

58+
// Files copied from Gutenberg subject to version control.
59+
gutenbergVersionedFiles = [
60+
'wp-includes/images/icon-library',
61+
'wp-includes/build',
62+
'wp-includes/blocks/*',
63+
'!wp-includes/blocks/index.php',
64+
],
65+
5966
// All files built by Webpack, in /src or /build.
6067
// Webpack only builds Core-specific media files and development scripts.
6168
// Blocks, packages, script modules, and vendors come from the Gutenberg build.
@@ -246,6 +253,25 @@ module.exports = function(grunt) {
246253
gutenberg: gutenbergFiles.map( function( file ) {
247254
return setFilePath( WORKING_DIR, file );
248255
}),
256+
257+
/*
258+
* Delete directories and files subjet to version control where the contents come from Gutenberg.
259+
*
260+
* This handles instances where a file remains present even after being deleted upstream.
261+
*
262+
* This task is intentionally skipped unless the current task will re-copy the corresponding files.
263+
*/
264+
'gutenberg-versioned': {
265+
filter: function() {
266+
var allowedTasks = [ 'build', 'build:dev', 'build:gutenberg', 'clean:gutenberg-versioned' ];
267+
return allowedTasks.some( function( task ) {
268+
return grunt.cli.tasks.indexOf( task ) !== -1;
269+
} );
270+
},
271+
src: gutenbergVersionedFiles.map( function( file ) {
272+
return setFilePath( SOURCE_DIR, file );
273+
} ),
274+
},
249275
dynamic: {
250276
dot: true,
251277
expand: true,
@@ -667,7 +693,7 @@ module.exports = function(grunt) {
667693
'constants.php',
668694
'pages/**/*.php',
669695
],
670-
dest: WORKING_DIR + 'wp-includes/build/',
696+
dest: SOURCE_DIR + 'wp-includes/build/',
671697
} ],
672698
},
673699
/*
@@ -684,7 +710,7 @@ module.exports = function(grunt) {
684710
expand: true,
685711
cwd: 'gutenberg/build',
686712
src: [],
687-
dest: WORKING_DIR + 'wp-includes/build/',
713+
dest: SOURCE_DIR + 'wp-includes/build/',
688714
},
689715
'gutenberg-js': {
690716
files: [ {
@@ -693,7 +719,7 @@ module.exports = function(grunt) {
693719
src: [
694720
'pages/**/*.js',
695721
],
696-
dest: WORKING_DIR + 'wp-includes/build/',
722+
dest: SOURCE_DIR + 'wp-includes/build/',
697723
} ],
698724
},
699725
'gutenberg-modules': {
@@ -707,7 +733,7 @@ module.exports = function(grunt) {
707733
// with no debugging value over the minified versions.
708734
'!vips/!(*.min).js',
709735
],
710-
dest: WORKING_DIR + 'wp-includes/js/dist/script-modules/',
736+
dest: SOURCE_DIR + 'wp-includes/js/dist/script-modules/',
711737
} ],
712738
},
713739
'gutenberg-styles': {
@@ -720,7 +746,7 @@ module.exports = function(grunt) {
720746
// Per-block CSS is copied to wp-includes/blocks/ by tools/gutenberg/copy.js.
721747
'!block-library/*/**',
722748
],
723-
dest: WORKING_DIR + 'wp-includes/css/dist/',
749+
dest: SOURCE_DIR + 'wp-includes/css/dist/',
724750
} ],
725751
},
726752
'gutenberg-theme-json': {
@@ -739,11 +765,11 @@ module.exports = function(grunt) {
739765
files: [
740766
{
741767
src: 'gutenberg/lib/theme.json',
742-
dest: WORKING_DIR + 'wp-includes/theme.json',
768+
dest: SOURCE_DIR + 'wp-includes/theme.json',
743769
},
744770
{
745771
src: 'gutenberg/lib/theme-i18n.json',
746-
dest: WORKING_DIR + 'wp-includes/theme-i18n.json',
772+
dest: SOURCE_DIR + 'wp-includes/theme-i18n.json',
747773
},
748774
],
749775
},
@@ -752,7 +778,7 @@ module.exports = function(grunt) {
752778
expand: true,
753779
cwd: 'gutenberg/packages/icons/src/library',
754780
src: '*.svg',
755-
dest: WORKING_DIR + 'wp-includes/images/icon-library',
781+
dest: SOURCE_DIR + 'wp-includes/images/icon-library',
756782
} ],
757783
},
758784
'icon-library-manifest': {
@@ -774,7 +800,7 @@ module.exports = function(grunt) {
774800
},
775801
files: [ {
776802
src: 'gutenberg/packages/icons/src/manifest.php',
777-
dest: WORKING_DIR + 'wp-includes/assets/icon-library-manifest.php',
803+
dest: SOURCE_DIR + 'wp-includes/assets/icon-library-manifest.php',
778804
} ],
779805
},
780806
},
@@ -1678,10 +1704,9 @@ module.exports = function(grunt) {
16781704

16791705
grunt.registerTask( 'gutenberg:copy', 'Copies Gutenberg JS packages and block assets to WordPress Core.', function() {
16801706
const done = this.async();
1681-
const buildDir = grunt.option( 'dev' ) ? 'src' : 'build';
16821707
grunt.util.spawn( {
16831708
cmd: 'node',
1684-
args: [ 'tools/gutenberg/copy.js', `--build-dir=${ buildDir }` ],
1709+
args: [ 'tools/gutenberg/copy.js' ],
16851710
opts: { stdio: 'inherit' }
16861711
}, function( error ) {
16871712
done( ! error );
@@ -2159,6 +2184,7 @@ module.exports = function(grunt) {
21592184

21602185
grunt.registerTask( 'build:gutenberg', [
21612186
'gutenberg:verify',
2187+
'clean:gutenberg-versioned',
21622188
'clean:gutenberg',
21632189
'copy:gutenberg-php',
21642190
'routes:setup',

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)