@@ -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' ,
0 commit comments