Skip to content

Commit

Permalink
Build: Introduce the common build folder to be used by all modules (#…
Browse files Browse the repository at this point in the history
…6584)

* Build: Put all build files into build top folder

* Framework: Move a11y and dom-ready to their own modules

* Edit Post: Move domReady logic to client-assets

* Make phpcs happy by adding dot at the end of comment

* Make Eslint happy by removing no longer used domReady import
  • Loading branch information
gziolo committed May 7, 2018
1 parent 555c29a commit f564e6c
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 88 deletions.
2 changes: 1 addition & 1 deletion bin/build-plugin-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ rm -f gutenberg.zip
php bin/generate-gutenberg-php.php > gutenberg.tmp.php
mv gutenberg.tmp.php gutenberg.php

build_files=$(ls **/build/*.{js,css})
build_files=$(ls build/*/*.{js,css})

# Generate the plugin zip file
status "Creating archive..."
Expand Down
29 changes: 12 additions & 17 deletions edit-post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { get, isString, some } from 'lodash';
* WordPress dependencies
*/
import { registerCoreBlocks } from '@wordpress/core-blocks';
import domReady from '@wordpress/dom-ready';
import { render, unmountComponentAtNode } from '@wordpress/element';
import { deprecated } from '@wordpress/utils';

Expand Down Expand Up @@ -83,25 +82,21 @@ export function initializeEditor( id, post, settings ) {
);
}

return new Promise( ( resolve ) => {
domReady( () => {
const target = document.getElementById( id );
const reboot = reinitializeEditor.bind( null, target, settings );
const target = document.getElementById( id );
const reboot = reinitializeEditor.bind( null, target, settings );

registerCoreBlocks();
registerCoreBlocks();

render(
<Editor settings={ migratedSettings || settings } onError={ reboot } post={ post } />,
target
);
render(
<Editor settings={ migratedSettings || settings } onError={ reboot } post={ post } />,
target
);

resolve( {
initializeMetaBoxes( metaBoxes ) {
store.dispatch( initializeMetaBoxState( metaBoxes ) );
},
} );
} );
} );
return {
initializeMetaBoxes( metaBoxes ) {
store.dispatch( initializeMetaBoxState( metaBoxes ) );
},
};
}

export { default as PluginPostStatusInfo } from './components/sidebar/plugin-post-status-info';
Expand Down
2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function gutenberg_build_files_notice() {
* @since 1.5.0
*/
function gutenberg_pre_init() {
if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( dirname( __FILE__ ) . '/blocks/build' ) ) {
if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( dirname( __FILE__ ) . '/build/blocks' ) ) {
add_action( 'admin_notices', 'gutenberg_build_files_notice' );
return;
}
Expand Down
177 changes: 112 additions & 65 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,49 +75,72 @@ function gutenberg_get_script_polyfill( $tests ) {
function gutenberg_register_scripts_and_styles() {
gutenberg_register_vendor_scripts();

// Editor Scripts.
// WordPress packages.
wp_register_script(
'wp-dom-ready',
gutenberg_url( 'build/dom-ready/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'build/dom-ready/index.js' ),
true
);
wp_register_script(
'wp-a11y',
gutenberg_url( 'build/a11y/index.js' ),
array( 'wp-dom-ready' ),
filemtime( gutenberg_dir_path() . 'build/a11y/index.js' ),
true
);
wp_register_script(
'wp-hooks',
gutenberg_url( 'build/hooks/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'build/hooks/index.js' ),
true
);
wp_register_script(
'wp-i18n',
gutenberg_url( 'build/i18n/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'build/i18n/index.js' ),
true
);
wp_register_script(
'wp-is-shallow-equal',
gutenberg_url( 'is-shallow-equal/build/index.js' ),
gutenberg_url( 'build/is-shallow-equal/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'is-shallow-equal/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/is-shallow-equal/index.js' ),
true
);

// Editor Scripts.
wp_register_script(
'wp-data',
gutenberg_url( 'data/build/index.js' ),
gutenberg_url( 'build/data/index.js' ),
array( 'wp-element', 'wp-utils', 'wp-is-shallow-equal', 'lodash' ),
filemtime( gutenberg_dir_path() . 'data/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/data/index.js' ),
true
);
wp_register_script(
'wp-core-data',
gutenberg_url( 'core-data/build/index.js' ),
gutenberg_url( 'build/core-data/index.js' ),
array( 'wp-data', 'wp-api-request', 'lodash' ),
filemtime( gutenberg_dir_path() . 'core-data/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/core-data/index.js' ),
true
);
wp_register_script(
'wp-utils',
gutenberg_url( 'utils/build/index.js' ),
gutenberg_url( 'build/utils/index.js' ),
array( 'tinymce-latest', 'lodash' ),
filemtime( gutenberg_dir_path() . 'utils/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/utils/index.js' ),
true
);
wp_add_inline_script( 'wp-utils', 'var originalUtils = window.wp && window.wp.utils ? window.wp.utils : {};', 'before' );
wp_add_inline_script( 'wp-utils', 'for ( var key in originalUtils ) wp.utils[ key ] = originalUtils[ key ];' );
wp_register_script(
'wp-hooks',
gutenberg_url( 'hooks/build/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'hooks/build/index.js' ),
true
);
wp_register_script(
'wp-date',
gutenberg_url( 'date/build/index.js' ),
gutenberg_url( 'build/date/index.js' ),
array( 'moment' ),
filemtime( gutenberg_dir_path() . 'date/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/date/index.js' ),
true
);
global $wp_locale;
Expand Down Expand Up @@ -146,30 +169,33 @@ function gutenberg_register_scripts_and_styles() {
'string' => get_option( 'timezone_string', 'UTC' ),
),
) ), 'before' );
wp_register_script(
'wp-i18n',
gutenberg_url( 'i18n/build/index.js' ),
array(),
filemtime( gutenberg_dir_path() . 'i18n/build/index.js' ),
true
);
wp_register_script(
'wp-element',
gutenberg_url( 'element/build/index.js' ),
gutenberg_url( 'build/element/index.js' ),
array( 'react', 'react-dom', 'wp-utils', 'wp-is-shallow-equal', 'lodash' ),
filemtime( gutenberg_dir_path() . 'element/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/element/index.js' ),
true
);
wp_register_script(
'wp-components',
gutenberg_url( 'components/build/index.js' ),
array( 'wp-element', 'wp-i18n', 'wp-utils', 'wp-hooks', 'wp-api-request', 'wp-is-shallow-equal', 'moment', 'lodash' ),
filemtime( gutenberg_dir_path() . 'components/build/index.js' ),
gutenberg_url( 'build/components/index.js' ),
array(
'lodash',
'moment',
'wp-a11y',
'wp-api-request',
'wp-element',
'wp-hooks',
'wp-i18n',
'wp-is-shallow-equal',
'wp-utils',
),
filemtime( gutenberg_dir_path() . 'build/components/index.js' ),
true
);
wp_register_script(
'wp-blocks',
gutenberg_url( 'blocks/build/index.js' ),
gutenberg_url( 'build/blocks/index.js' ),
array(
'wp-element',
'wp-components',
Expand All @@ -185,7 +211,7 @@ function gutenberg_register_scripts_and_styles() {
'wp-core-data',
'lodash',
),
filemtime( gutenberg_dir_path() . 'blocks/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/blocks/index.js' ),
true
);
wp_add_inline_script(
Expand All @@ -198,16 +224,16 @@ function gutenberg_register_scripts_and_styles() {
);
wp_register_script(
'wp-viewport',
gutenberg_url( 'viewport/build/index.js' ),
gutenberg_url( 'build/viewport/index.js' ),
array( 'wp-element', 'wp-data', 'wp-components', 'lodash' ),
filemtime( gutenberg_dir_path() . 'viewport/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/viewport/index.js' ),
true
);
wp_register_script(
'wp-core-blocks',
gutenberg_url( 'core-blocks/build/index.js' ),
gutenberg_url( 'build/core-blocks/index.js' ),
array( 'wp-element', 'wp-components', 'wp-utils', 'wp-blocks', 'wp-i18n', 'editor', 'wp-core-data', 'lodash' ),
filemtime( gutenberg_dir_path() . 'core-blocks/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/core-blocks/index.js' ),
true
);
// Loading the old editor and its config to ensure the classic block works as expected.
Expand Down Expand Up @@ -281,33 +307,52 @@ function gutenberg_register_scripts_and_styles() {

wp_register_script(
'wp-editor',
gutenberg_url( 'editor/build/index.js' ),
gutenberg_url( 'build/editor/index.js' ),
array(
'postbox',
'editor',
'jquery',
'lodash',
'postbox',
'wp-a11y',
'wp-api',
'wp-blocks',
'wp-components',
'wp-core-data',
'wp-data',
'wp-date',
'wp-i18n',
'wp-blocks',
'wp-element',
'wp-components',
'wp-plugins',
'wp-utils',
'wp-viewport',
'wp-plugins',
'wp-core-data',
'editor',
'lodash',
),
filemtime( gutenberg_dir_path() . 'editor/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/editor/index.js' ),
true
);

wp_register_script(
'wp-edit-post',
gutenberg_url( 'edit-post/build/index.js' ),
array( 'jquery', 'media-views', 'media-models', 'wp-element', 'wp-components', 'wp-editor', 'wp-i18n', 'wp-date', 'wp-utils', 'wp-data', 'wp-embed', 'wp-viewport', 'wp-plugins', 'wp-core-blocks', 'lodash' ),
filemtime( gutenberg_dir_path() . 'edit-post/build/index.js' ),
gutenberg_url( 'build/edit-post/index.js' ),
array(
'jquery',
'lodash',
'media-models',
'media-views',
'wp-a11y',
'wp-components',
'wp-core-blocks',
'wp-date',
'wp-data',
'wp-dom-ready',
'wp-editor',
'wp-element',
'wp-embed',
'wp-i18n',
'wp-plugins',
'wp-viewport',
'wp-utils',
),
filemtime( gutenberg_dir_path() . 'build/edit-post/index.js' ),
true
);
wp_add_inline_script(
Expand All @@ -324,57 +369,57 @@ function gutenberg_register_scripts_and_styles() {

wp_register_style(
'wp-editor',
gutenberg_url( 'editor/build/style.css' ),
gutenberg_url( 'build/editor/style.css' ),
array( 'wp-components', 'wp-blocks', 'wp-editor-font' ),
filemtime( gutenberg_dir_path() . 'editor/build/style.css' )
filemtime( gutenberg_dir_path() . 'build/editor/style.css' )
);
wp_style_add_data( 'wp-editor', 'rtl', 'replace' );

wp_register_style(
'wp-edit-post',
gutenberg_url( 'edit-post/build/style.css' ),
gutenberg_url( 'build/edit-post/style.css' ),
array( 'wp-components', 'wp-editor', 'wp-edit-blocks', 'wp-core-blocks' ),
filemtime( gutenberg_dir_path() . 'edit-post/build/style.css' )
filemtime( gutenberg_dir_path() . 'build/edit-post/style.css' )
);
wp_style_add_data( 'wp-edit-post', 'rtl', 'replace' );

wp_register_style(
'wp-components',
gutenberg_url( 'components/build/style.css' ),
gutenberg_url( 'build/components/style.css' ),
array(),
filemtime( gutenberg_dir_path() . 'components/build/style.css' )
filemtime( gutenberg_dir_path() . 'build/components/style.css' )
);
wp_style_add_data( 'wp-components', 'rtl', 'replace' );

wp_register_style(
'wp-blocks',
gutenberg_url( 'blocks/build/style.css' ),
gutenberg_url( 'build/blocks/style.css' ),
array(),
filemtime( gutenberg_dir_path() . 'blocks/build/style.css' )
filemtime( gutenberg_dir_path() . 'build/blocks/style.css' )
);
wp_style_add_data( 'wp-blocks', 'rtl', 'replace' );

wp_register_style(
'wp-core-blocks',
gutenberg_url( 'core-blocks/build/style.css' ),
gutenberg_url( 'build/core-blocks/style.css' ),
array(),
filemtime( gutenberg_dir_path() . 'core-blocks/build/style.css' )
filemtime( gutenberg_dir_path() . 'build/core-blocks/style.css' )
);
wp_style_add_data( 'wp-core-blocks', 'rtl', 'replace' );

wp_register_style(
'wp-edit-blocks',
gutenberg_url( 'core-blocks/build/edit-blocks.css' ),
gutenberg_url( 'build/core-blocks/edit-blocks.css' ),
array( 'wp-components', 'wp-blocks' ),
filemtime( gutenberg_dir_path() . 'core-blocks/build/edit-blocks.css' )
filemtime( gutenberg_dir_path() . 'build/core-blocks/edit-blocks.css' )
);
wp_style_add_data( 'wp-edit-blocks', 'rtl', 'replace' );

wp_register_script(
'wp-plugins',
gutenberg_url( 'plugins/build/index.js' ),
gutenberg_url( 'build/plugins/index.js' ),
array( 'wp-element', 'wp-components', 'wp-utils', 'wp-data' ),
filemtime( gutenberg_dir_path() . 'plugins/build/index.js' )
filemtime( gutenberg_dir_path() . 'build/plugins/index.js' )
);
}
add_action( 'wp_enqueue_scripts', 'gutenberg_register_scripts_and_styles', 5 );
Expand Down Expand Up @@ -1002,9 +1047,11 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
$script .= sprintf( 'var editorSettings = %s;', wp_json_encode( $editor_settings ) );
$script .= <<<JS
window._wpLoadGutenbergEditor = new Promise( function( resolve ) {
wp.api.init().then( resolve );
} ).then( function() {
return wp.editPost.initializeEditor( 'editor', window._wpGutenbergPost, editorSettings );
wp.api.init().then( function() {
wp.domReady.default( function() {
resolve( wp.editPost.initializeEditor( 'editor', window._wpGutenbergPost, editorSettings ) );
} );
} );
} );
JS;
$script .= '} )();';
Expand Down
Loading

0 comments on commit f564e6c

Please sign in to comment.