@@ -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 } ) ;
0 commit comments