Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 84 additions & 37 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,43 @@ module.exports = function(grunt) {
'wp-admin/css/colors/**/*.css',
],

// Built js files, in /src or /build.
// Built JavaScript files that do not belong to a more specific group.
jsFiles = [
'wp-admin/js/',
'wp-includes/js/',
'wp-includes/js/*',
/*
* This directory has shared responsibility and is managed through
* gutenbergUnversionedFiles, webpackFiles, and copy:vendor-js.
*/
'!wp-includes/js/dist',
'wp-includes/js/dist/vendor/*.js',
// Managed by the Gutenberg-related tasks.
'!wp-includes/js/dist/vendor/react-jsx-runtime*',
],

// Files sourced from the Gutenberg repository built asset that are ignored by version control.
gutenbergUnversionedFiles = [
SOURCE_DIR + 'wp-includes/blocks/*/*.css',
SOURCE_DIR + 'wp-includes/css/dist',
SOURCE_DIR + 'wp-includes/js/dist/*.js',
SOURCE_DIR + 'wp-includes/js/dist/script-modules',
SOURCE_DIR + 'wp-includes/js/dist/vendor/react-jsx-runtime*',
],

// All files copied from the Gutenberg repository excluded from version control.
gutenbergFiles = [
'wp-includes/js/dist',
'wp-includes/css/dist',
// Old location kept temporarily to ensure they are cleaned up.
'wp-includes/icons',
// Files sourced from the Gutenberg repository built asset that are managed through version control.
gutenbergVersionedFiles = [
// Block assets (block.json, top-level PHP, nested PHP helpers).
SOURCE_DIR + 'wp-includes/blocks/*',
'!' + SOURCE_DIR + 'wp-includes/blocks/index.php',
SOURCE_DIR + 'wp-includes/images/icon-library',
SOURCE_DIR + 'wp-includes/theme.json',
SOURCE_DIR + 'wp-includes/theme-i18n.json',
// Routes and pages.
SOURCE_DIR + 'wp-includes/build',
// PHP manifests generated by gutenberg:copy.
SOURCE_DIR + 'wp-includes/assets/icon-library-manifest.php',
SOURCE_DIR + 'wp-includes/assets/script-loader-packages.php',
SOURCE_DIR + 'wp-includes/assets/script-modules-packages.php',
],

// All files built by Webpack, in /src or /build.
Expand Down Expand Up @@ -241,10 +266,27 @@ module.exports = function(grunt) {
return setFilePath( WORKING_DIR, file );
} ),

// Clean files built by the tools/gutenberg scripts.
gutenberg: gutenbergFiles.map( function( file ) {
return setFilePath( WORKING_DIR, file );
}),
/*
* Clean files sourced from the downloaded zip file built by the Gutenberg repository.
*
* All files originating from the Gutenberg repository's built assets (both tracked and untracked by version
* control) are deleted when `clean:gutenberg` is explicitly called. This ensures that versioned files that
* have been deleted upstream are also removed from version control in this repository.
*
* When `clean:gutenberg` is not explicitly called and run through `grunt clean`, only ignored files are
* cleaned.
*/
gutenberg: {
get src() {
const isExplicitGutenbergClean =
grunt.cli.tasks.length === 1 &&
grunt.cli.tasks[ 0 ] !== 'clean';
return isExplicitGutenbergClean ?
gutenbergUnversionedFiles.concat( gutenbergVersionedFiles ) :
gutenbergUnversionedFiles;
Comment on lines +281 to +286

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isExplicitGutenbergClean =
grunt.cli.tasks.length === 1 &&
grunt.cli.tasks[ 0 ] !== 'clean';
return isExplicitGutenbergClean ?
gutenbergUnversionedFiles.concat( gutenbergVersionedFiles ) :
gutenbergUnversionedFiles;
if( grunt.cli.tasks.length === 1 && grunt.cli.tasks[ 0 ] !== 'clean' ) {
return gutenbergUnversionedFiles.concat( gutenbergVersionedFiles );
} else {
return gutenbergUnversionedFiles;
}

Nit: The back to back multiple lines single line functions is a bit hard to grok.

},
},

dynamic: {
dot: true,
expand: true,
Expand Down Expand Up @@ -289,7 +331,6 @@ module.exports = function(grunt) {
expand: true,
cwd: SOURCE_DIR,
src: buildFiles.concat( [
'!wp-includes/assets/**', // Assets is extracted into separate copy tasks.
'!js/**', // JavaScript is extracted into separate copy tasks.
'!.{svn,git}', // Exclude version control folders.
'!wp-includes/version.php', // Exclude version.php.
Expand Down Expand Up @@ -666,24 +707,18 @@ module.exports = function(grunt) {
'constants.php',
'pages/**/*.php',
],
dest: WORKING_DIR + 'wp-includes/build/',
dest: SOURCE_DIR + 'wp-includes/build/',
} ],
},
/*
* Only copy files relevant to the routes specified in the registry file.
*
* While the registry file does not contain any experimental routes, the `gutenberg/build/routes` directory
* includes the files for all registered routes. Only the files related to the routes specified in the
* registry should be included in the WordPress build.
*
* The `src` list is populated at task runtime by `routes:setup`, which reads the registry after
* `gutenberg:download` has run. See the `routes:setup` task registration for implementation details.
* The list of route source files is populated from the contents of the registry.php file at task runtime by
* `routes:setup`.
*/
routes: {
expand: true,
cwd: 'gutenberg/build',
src: [],
dest: WORKING_DIR + 'wp-includes/build/',
dest: SOURCE_DIR + 'wp-includes/build/',
},
'gutenberg-js': {
files: [ {
Expand All @@ -692,7 +727,7 @@ module.exports = function(grunt) {
src: [
'pages/**/*.js',
],
dest: WORKING_DIR + 'wp-includes/build/',
dest: SOURCE_DIR + 'wp-includes/build/',
} ],
},
'gutenberg-modules': {
Expand All @@ -706,7 +741,7 @@ module.exports = function(grunt) {
// with no debugging value over the minified versions.
'!vips/!(*.min).js',
],
dest: WORKING_DIR + 'wp-includes/js/dist/script-modules/',
dest: SOURCE_DIR + 'wp-includes/js/dist/script-modules/',
} ],
},
'gutenberg-styles': {
Expand All @@ -719,7 +754,7 @@ module.exports = function(grunt) {
// Per-block CSS is copied to wp-includes/blocks/ by tools/gutenberg/copy.js.
'!block-library/*/**',
],
dest: WORKING_DIR + 'wp-includes/css/dist/',
dest: SOURCE_DIR + 'wp-includes/css/dist/',
} ],
},
'gutenberg-theme-json': {
Expand All @@ -738,20 +773,20 @@ module.exports = function(grunt) {
files: [
{
src: 'gutenberg/lib/theme.json',
dest: WORKING_DIR + 'wp-includes/theme.json',
dest: SOURCE_DIR + 'wp-includes/theme.json',
},
{
src: 'gutenberg/lib/theme-i18n.json',
dest: WORKING_DIR + 'wp-includes/theme-i18n.json',
dest: SOURCE_DIR + 'wp-includes/theme-i18n.json',
},
],
},
'icon-library-images': {
files: [ {
expand: true,
cwd: 'gutenberg/packages/icons/src/library',
src: '*.svg',
dest: WORKING_DIR + 'wp-includes/images/icon-library',
src: [ '*.svg' ],
dest: SOURCE_DIR + 'wp-includes/images/icon-library',
} ],
},
'icon-library-manifest': {
Expand All @@ -773,7 +808,7 @@ module.exports = function(grunt) {
},
files: [ {
src: 'gutenberg/packages/icons/src/manifest.php',
dest: WORKING_DIR + 'wp-includes/assets/icon-library-manifest.php',
dest: SOURCE_DIR + 'wp-includes/assets/icon-library-manifest.php',
} ],
},
},
Expand Down Expand Up @@ -1677,10 +1712,9 @@ module.exports = function(grunt) {

grunt.registerTask( 'gutenberg:copy', 'Copies Gutenberg JS packages and block assets to WordPress Core.', function() {
const done = this.async();
const buildDir = grunt.option( 'dev' ) ? 'src' : 'build';
grunt.util.spawn( {
cmd: 'node',
args: [ 'tools/gutenberg/copy.js', `--build-dir=${ buildDir }` ],
args: [ 'tools/gutenberg/copy.js' ],
opts: { stdio: 'inherit' }
}, function( error ) {
done( ! error );
Expand Down Expand Up @@ -2164,10 +2198,23 @@ module.exports = function(grunt) {
} );
} );

grunt.registerTask( 'build:gutenberg', [
'copy:gutenberg-php',
// Detects and copies stable routes.
grunt.registerTask( 'build:routes', [
'routes:setup',
'copy:routes',
] );

/*
* Refresh the Gutenberg-sourced content in src/.
*
* clean:gutenberg must run first to ensure files removed upstream are purged.
*
* Because all of these tasks write to src/, the outcome is identical for build and build:dev.
*/
grunt.registerTask( 'build:gutenberg', [
'clean:gutenberg',
'copy:gutenberg-php',
'build:routes',
'copy:gutenberg-js',
'gutenberg:copy',
'copy:gutenberg-modules',
Expand All @@ -2181,21 +2228,21 @@ module.exports = function(grunt) {
if ( grunt.option( 'dev' ) ) {
grunt.task.run( [
'gutenberg:verify',
'build:gutenberg',
'build:js',
'build:css',
'build:codemirror',
'build:gutenberg',
'build:certificates'
] );
} else {
grunt.task.run( [
'gutenberg:verify',
'build:gutenberg',
'build:certificates',
'build:files',
'build:js',
'build:css',
'build:codemirror',
'build:gutenberg',
'replace:source-maps',
'verify:build'
] );
Expand Down
Loading
Loading