33/* globals Set */
44var webpackConfig = require ( './webpack.config' ) ;
55var installChanged = require ( 'install-changed' ) ;
6- var json2php = require ( 'json2php' ) ;
76
87module . exports = function ( grunt ) {
98 var path = require ( 'path' ) ,
@@ -1279,6 +1278,14 @@ module.exports = function(grunt) {
12791278 BUILD_DIR + 'wp-includes/js/dist/commands.js' ,
12801279 ] ,
12811280 dest : BUILD_DIR + 'wp-includes/js/dist/'
1281+ } ,
1282+ {
1283+ expand : true ,
1284+ flatten : true ,
1285+ src : [
1286+ BUILD_DIR + 'wp-includes/js/dist/vendor/**/*.js'
1287+ ] ,
1288+ dest : BUILD_DIR + 'wp-includes/js/dist/vendor/'
12821289 }
12831290 ]
12841291 }
@@ -1414,6 +1421,59 @@ module.exports = function(grunt) {
14141421 grunt . task . run ( 'wp-packages:refresh-deps' ) ;
14151422 } ) ;
14161423
1424+ // Gutenberg integration tasks.
1425+ grunt . registerTask ( 'gutenberg-checkout' , 'Checks out the Gutenberg repository.' , function ( ) {
1426+ const done = this . async ( ) ;
1427+ grunt . util . spawn ( {
1428+ cmd : 'node' ,
1429+ args : [ 'tools/gutenberg/checkout-gutenberg.js' ] ,
1430+ opts : { stdio : 'inherit' }
1431+ } , function ( error ) {
1432+ done ( ! error ) ;
1433+ } ) ;
1434+ } ) ;
1435+
1436+ grunt . registerTask ( 'gutenberg-build' , 'Builds the Gutenberg repository.' , function ( ) {
1437+ const done = this . async ( ) ;
1438+ grunt . util . spawn ( {
1439+ cmd : 'node' ,
1440+ args : [ 'tools/gutenberg/build-gutenberg.js' ] ,
1441+ opts : { stdio : 'inherit' }
1442+ } , function ( error ) {
1443+ done ( ! error ) ;
1444+ } ) ;
1445+ } ) ;
1446+
1447+ grunt . registerTask ( 'gutenberg-copy' , 'Copies Gutenberg build output to WordPress Core.' , function ( ) {
1448+ const done = this . async ( ) ;
1449+ const buildDir = grunt . option ( 'dev' ) ? 'src' : 'build' ;
1450+ grunt . util . spawn ( {
1451+ cmd : 'node' ,
1452+ args : [ 'tools/gutenberg/copy-gutenberg-build.js' , `--build-dir=${ buildDir } ` ] ,
1453+ opts : { stdio : 'inherit' }
1454+ } , function ( error ) {
1455+ done ( ! error ) ;
1456+ } ) ;
1457+ } ) ;
1458+
1459+ grunt . registerTask ( 'gutenberg-integrate' , 'Complete Gutenberg integration workflow.' , [
1460+ 'gutenberg-checkout' ,
1461+ 'gutenberg-build' ,
1462+ 'gutenberg-copy'
1463+ ] ) ;
1464+
1465+ grunt . registerTask ( 'copy-vendor-scripts' , 'Copies vendor scripts from node_modules to wp-includes/js/dist/vendor/.' , function ( ) {
1466+ const done = this . async ( ) ;
1467+ const buildDir = grunt . option ( 'dev' ) ? 'src' : 'build' ;
1468+ grunt . util . spawn ( {
1469+ cmd : 'node' ,
1470+ args : [ 'tools/vendors/copy-vendors.js' , `--build-dir=${ buildDir } ` ] ,
1471+ opts : { stdio : 'inherit' }
1472+ } , function ( error ) {
1473+ done ( ! error ) ;
1474+ } ) ;
1475+ } ) ;
1476+
14171477 grunt . renameTask ( 'watch' , '_watch' ) ;
14181478
14191479 grunt . registerTask ( 'watch' , function ( ) {
@@ -1569,23 +1629,6 @@ module.exports = function(grunt) {
15691629 }
15701630 } ) ;
15711631
1572- grunt . registerTask ( 'copy:block-json' , 'Copies block.json file contents to block-json.php.' , function ( ) {
1573- var blocks = { } ;
1574- grunt . file . recurse ( SOURCE_DIR + 'wp-includes/blocks' , function ( abspath , rootdir , subdir , filename ) {
1575- if ( / ^ b l o c k \. j s o n $ / . test ( filename ) ) {
1576- blocks [ subdir ] = grunt . file . readJSON ( abspath ) ;
1577- }
1578- } ) ;
1579- grunt . file . write (
1580- SOURCE_DIR + 'wp-includes/blocks/blocks-json.php' ,
1581- '<?php return ' + json2php . make ( {
1582- linebreak : '\n' ,
1583- indent : ' ' ,
1584- shortArraySyntax : false
1585- } ) ( blocks ) + ';'
1586- ) ;
1587- } ) ;
1588-
15891632 grunt . registerTask ( 'copy:js' , [
15901633 'copy:npm-packages' ,
15911634 'copy:vendor-js' ,
@@ -1723,7 +1766,6 @@ module.exports = function(grunt) {
17231766 grunt . registerTask ( 'build:files' , [
17241767 'clean:files' ,
17251768 'copy:files' ,
1726- 'copy:block-json' ,
17271769 'copy:version' ,
17281770 ] ) ;
17291771
@@ -1853,6 +1895,8 @@ module.exports = function(grunt) {
18531895 grunt . task . run ( [
18541896 'build:js' ,
18551897 'build:css' ,
1898+ 'gutenberg-integrate' ,
1899+ 'copy-vendor-scripts' ,
18561900 'build:certificates'
18571901 ] ) ;
18581902 } else {
@@ -1861,6 +1905,8 @@ module.exports = function(grunt) {
18611905 'build:files' ,
18621906 'build:js' ,
18631907 'build:css' ,
1908+ 'gutenberg-integrate' ,
1909+ 'copy-vendor-scripts' ,
18641910 'replace:source-maps' ,
18651911 'verify:build'
18661912 ] ) ;
0 commit comments