-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Proof of concept: Remove the requirement to check out the gutenberg repository and running the full build script
#11019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f8a7238
29a617f
cd08d60
8729f37
800fb06
7dfec4f
c7563fa
9cfff8e
732a54b
7f932ec
4faa486
82ae215
d06292c
83e549a
16722a4
07f2e5c
6ec39d8
a2c1856
50c6285
b1c3842
25c90b9
330a83e
fbb1c58
3050cd1
f588cf5
e822046
7d0ca6c
5dffecc
29baaf4
fdda592
5669f70
7ce0157
aad2939
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,6 @@ module.exports = function(grunt) { | |
| webpackFiles = [ | ||
| 'wp-includes/assets/*', | ||
| 'wp-includes/css/dist', | ||
| 'wp-includes/blocks/**/*.css', | ||
| '!wp-includes/assets/script-loader-packages.min.php', | ||
| '!wp-includes/assets/script-modules-packages.min.php', | ||
| ], | ||
|
|
@@ -588,7 +587,97 @@ module.exports = function(grunt) { | |
| certificates: { | ||
| src: 'vendor/composer/ca-bundle/res/cacert.pem', | ||
| dest: SOURCE_DIR + 'wp-includes/certificates/ca-bundle.crt' | ||
| } | ||
| }, | ||
| // Gutenberg PHP infrastructure files (routes.php, pages.php, constants.php, pages/, routes/). | ||
| 'gutenberg-php': { | ||
| options: { | ||
| process: function( content ) { | ||
| // Fix boot module asset file path for Core's different directory structure. | ||
| return content.replace( | ||
| /__DIR__\s*\.\s*(['"])\/..\/\..\/modules\/boot\/index\.min\.asset\.php\1/g, | ||
| 'ABSPATH . WPINC . \'/js/dist/script-modules/boot/index.min.asset.php\'' | ||
| ); | ||
| } | ||
| }, | ||
| files: [ { | ||
| expand: true, | ||
| cwd: 'gutenberg/build', | ||
| src: [ | ||
| 'routes.php', | ||
| 'pages.php', | ||
| 'constants.php', | ||
| 'pages/**/*.php', | ||
| 'routes/**/*.php', | ||
| ], | ||
| dest: WORKING_DIR + 'wp-includes/build/', | ||
| } ], | ||
| }, | ||
| 'gutenberg-modules': { | ||
| files: [ { | ||
| expand: true, | ||
| cwd: 'gutenberg/build/modules', | ||
| src: [ '**/*', '!**/*.map' ], | ||
| dest: WORKING_DIR + 'wp-includes/js/dist/script-modules/', | ||
| } ], | ||
| }, | ||
| 'gutenberg-styles': { | ||
| files: [ { | ||
| expand: true, | ||
| cwd: 'gutenberg/build/styles', | ||
| src: [ '**/*', '!**/*.map' ], | ||
| dest: WORKING_DIR + 'wp-includes/css/dist/', | ||
| } ], | ||
| }, | ||
| 'gutenberg-theme-json': { | ||
| options: { | ||
| process: function( content, srcpath ) { | ||
| // Replace the local schema URL with the canonical public URL for Core. | ||
| if ( path.basename( srcpath ) === 'theme.json' ) { | ||
| return content.replace( | ||
| '"$schema": "../schemas/json/theme.json"', | ||
| '"$schema": "https://schemas.wp.org/trunk/theme.json"' | ||
| ); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this does in a string things that are likely to mis-parse or be mislead. again, there should be extra layers of protection here, however, it is not likely that much more difficult to do this in a more robust way. process: function( content, srcpath ) {
if ( path.basename( srcpath ) !== 'theme.json' ) {
return content;
}
return JSON.stringify(
JSON.parse( content ),
( key, value ) =>
( '$schema' === key && '../schemas/json/theme.json' === value )
? 'https://schemas.wp.org/trunk/theme.json'
: value,
2
);
}this is marginally larger but contains none of the issues with treating JSON as a string. it’s not a big deal here, so not a blocker in any way, but it would be nice if we could at least follow-up after fixing things to return to these low-level build functions and make sure they don’t contain foot-guns for handling well-specified data. |
||
| return content; | ||
| } | ||
| }, | ||
| files: [ | ||
| { | ||
| src: 'gutenberg/lib/theme.json', | ||
| dest: WORKING_DIR + 'wp-includes/theme.json', | ||
| }, | ||
| { | ||
| src: 'gutenberg/lib/theme-i18n.json', | ||
| dest: WORKING_DIR + 'wp-includes/theme-i18n.json', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while it looks like not really a block, but something perhaps to earmark. |
||
| }, | ||
| ], | ||
| }, | ||
| 'gutenberg-icons': { | ||
| options: { | ||
| process: function( content, srcpath ) { | ||
| // Remove the 'gutenberg' text domain from _x() calls in manifest.php. | ||
| if ( path.basename( srcpath ) === 'manifest.php' ) { | ||
| return content.replace( | ||
| /_x\(\s*([^,]+),\s*([^,]+),\s*['"]gutenberg['"]\s*\)/g, | ||
| '_x( $1, $2 )' | ||
| ); | ||
| } | ||
| return content; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here again we’re apparently adding automation which nobody is likely to be maintaining familiarity with, doing something that looks sound today when all of the files are the way we expect them, and then one day it will all break and nobody will know what the goal here is. we’re also doing naive string parsing of JSON files again. it seems like Gutenberg’s should the shape of the manifest change, I have no idea how to expect someone to know what the original goal of this RegExp was supposed to be or do. this is definitely a nice-to-have, particularly since the generator file should be available whenever we have the I would think we could directly call the generator, like |
||
| } | ||
| }, | ||
| files: [ | ||
| { | ||
| src: 'gutenberg/packages/icons/src/manifest.php', | ||
| dest: WORKING_DIR + 'wp-includes/icons/manifest.php', | ||
| }, | ||
| { | ||
| expand: true, | ||
| cwd: 'gutenberg/packages/icons/src/library', | ||
| src: '*.svg', | ||
| dest: WORKING_DIR + 'wp-includes/icons/library/', | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| sass: { | ||
| colors: { | ||
|
|
@@ -1323,20 +1412,21 @@ module.exports = function(grunt) { | |
| }, | ||
| { | ||
| expand: true, | ||
| flatten: true, | ||
| src: [ | ||
| BUILD_DIR + 'wp-includes/js/dist/block-editor.js', | ||
| BUILD_DIR + 'wp-includes/js/dist/commands.js', | ||
| ], | ||
| dest: BUILD_DIR + 'wp-includes/js/dist/' | ||
| cwd: BUILD_DIR + 'wp-includes/js/dist/', | ||
| src: [ '*.js' ], | ||
| dest: BUILD_DIR + 'wp-includes/js/dist/', | ||
| }, | ||
| { | ||
| expand: true, | ||
| flatten: true, | ||
| src: [ | ||
| BUILD_DIR + 'wp-includes/js/dist/vendor/**/*.js' | ||
| ], | ||
| dest: BUILD_DIR + 'wp-includes/js/dist/vendor/' | ||
| cwd: BUILD_DIR + 'wp-includes/js/dist/vendor/', | ||
| src: [ '**/*.js' ], | ||
| dest: BUILD_DIR + 'wp-includes/js/dist/vendor/', | ||
| }, | ||
| { | ||
| expand: true, | ||
| cwd: BUILD_DIR + 'wp-includes/js/dist/script-modules/', | ||
| src: [ '**/*.js' ], | ||
| dest: BUILD_DIR + 'wp-includes/js/dist/script-modules/', | ||
| } | ||
| ] | ||
| } | ||
|
|
@@ -1475,45 +1565,38 @@ module.exports = function(grunt) { | |
| } ); | ||
|
|
||
| // Gutenberg integration tasks. | ||
| grunt.registerTask( 'gutenberg-checkout', 'Checks out the Gutenberg repository.', function() { | ||
| grunt.registerTask( 'gutenberg:verify', 'Verifies the installed Gutenberg version matches the expected SHA.', function() { | ||
| const done = this.async(); | ||
| grunt.util.spawn( { | ||
| cmd: 'node', | ||
| args: [ 'tools/gutenberg/checkout-gutenberg.js' ], | ||
| args: [ 'tools/gutenberg/utils.js' ], | ||
| opts: { stdio: 'inherit' } | ||
| }, function( error ) { | ||
| done( ! error ); | ||
| } ); | ||
| } ); | ||
|
|
||
| grunt.registerTask( 'gutenberg-build', 'Builds the Gutenberg repository.', function() { | ||
| grunt.registerTask( 'gutenberg:download', 'Downloads the built Gutenberg artifact.', function() { | ||
| const done = this.async(); | ||
| const args = [ 'tools/gutenberg/download.js' ]; | ||
| if ( grunt.option( 'force' ) ) { | ||
| args.push( '--force' ); | ||
| } | ||
| grunt.util.spawn( { | ||
| cmd: 'node', | ||
| args: [ 'tools/gutenberg/build-gutenberg.js' ], | ||
| args, | ||
| opts: { stdio: 'inherit' } | ||
| }, function( error ) { | ||
| done( ! error ); | ||
| } ); | ||
| } ); | ||
|
|
||
| grunt.registerTask( 'gutenberg-copy', 'Copies Gutenberg build output to WordPress Core.', function() { | ||
| 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-gutenberg-build.js', `--build-dir=${ buildDir }` ], | ||
| opts: { stdio: 'inherit' } | ||
| }, function( error ) { | ||
| done( ! error ); | ||
| } ); | ||
| } ); | ||
|
|
||
| grunt.registerTask( 'gutenberg-sync', 'Syncs Gutenberg checkout and build if ref has changed.', function() { | ||
| const done = this.async(); | ||
| grunt.util.spawn( { | ||
| cmd: 'node', | ||
| args: [ 'tools/gutenberg/sync-gutenberg.js' ], | ||
| args: [ 'tools/gutenberg/copy.js', `--build-dir=${ buildDir }` ], | ||
| opts: { stdio: 'inherit' } | ||
| }, function( error ) { | ||
| done( ! error ); | ||
|
|
@@ -1956,26 +2039,35 @@ module.exports = function(grunt) { | |
| } ); | ||
| } ); | ||
|
|
||
| grunt.registerTask( 'build:gutenberg', [ | ||
| 'copy:gutenberg-php', | ||
| 'gutenberg:copy', | ||
| 'copy:gutenberg-modules', | ||
| 'copy:gutenberg-styles', | ||
| 'copy:gutenberg-theme-json', | ||
| 'copy:gutenberg-icons', | ||
| ] ); | ||
|
|
||
| grunt.registerTask( 'build', function() { | ||
| if ( grunt.option( 'dev' ) ) { | ||
| grunt.task.run( [ | ||
| 'gutenberg:verify', | ||
| 'build:js', | ||
| 'build:css', | ||
| 'build:codemirror', | ||
| 'gutenberg-sync', | ||
| 'gutenberg-copy', | ||
| 'build:gutenberg', | ||
| 'copy-vendor-scripts', | ||
| 'build:certificates' | ||
| ] ); | ||
| } else { | ||
| grunt.task.run( [ | ||
| 'gutenberg:verify', | ||
| 'build:certificates', | ||
| 'build:files', | ||
| 'build:js', | ||
| 'build:css', | ||
| 'build:codemirror', | ||
| 'gutenberg-sync', | ||
| 'gutenberg-copy', | ||
| 'build:gutenberg', | ||
| 'copy-vendor-scripts', | ||
| 'replace:source-maps', | ||
| 'verify:build' | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.