From cf00fa5992e20d803fd36c904fc2c436e5624988 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 24 Mar 2017 09:20:33 -0400 Subject: [PATCH 1/4] Further simplify webpack entry configuration --- webpack.config.js | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 7b28a9ca1f09a..9f9aebf4602a9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -14,22 +14,12 @@ const ExtractTextPlugin = require( 'extract-text-webpack-plugin' ); */ const BASE_PATH = './modules'; -/** - * Object of Webpack entry points consisting of modules discovered in the base - * path subdirectory. Treating each as an independent bundle with a shared - * configuration for library output provides a consistent authoring environment - * and exposes each separately on the global scope (window.wp.blocks, etc.). - * - * @type {Object} - */ -const entry = [ 'blocks', 'editor', 'element' ].reduce( ( memo, submodule ) => { - return Object.assign( memo, { - [ submodule ]: [ BASE_PATH, submodule, 'index.js' ].join( '/' ) - } ); -}, {} ); - const config = { - entry: entry, + entry: { + blocks: BASE_PATH + '/blocks/index.js', + editor: BASE_PATH + '/editor/index.js', + element: BASE_PATH + '/element/index.js' + }, output: { filename: '[name]/build/index.js', path: path.resolve( BASE_PATH ), From 3c35361182be200b29b2996ce15b5a49fdde95d4 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 24 Mar 2017 09:20:46 -0400 Subject: [PATCH 2/4] Update hpq dependency to v1.1.1 --- package.json | 2 +- webpack.config.js | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6373bec01c37d..e83483807ebff 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,6 @@ "webpack-node-externals": "^1.5.4" }, "dependencies": { - "hpq": "^1.1.0" + "hpq": "^1.1.1" } } diff --git a/webpack.config.js b/webpack.config.js index 9f9aebf4602a9..e769726006377 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -38,10 +38,7 @@ const config = { }, { test: /\.js$/, - include: [ - __dirname + '/modules', - __dirname + '/node_modules/hpq' - ], + exclude: /node_modules/, use: 'babel-loader' }, { From fa8cd1c797d36de85a211b0e3594b0c581343616 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 24 Mar 2017 10:38:56 -0400 Subject: [PATCH 3/4] Flatten modules into top-level directory --- .eslintignore | 2 +- .../components/editable/index.js | 0 {modules/blocks => blocks}/index.js | 0 {modules/blocks => blocks}/parser/index.js | 0 {modules/blocks => blocks}/parser/post.pegjs | 0 .../blocks => blocks}/parser/test/index.js | 0 {modules/blocks => blocks}/test/index.js | 0 .../assets/stylesheets/main.scss | 0 {modules/editor => editor}/blocks/index.js | 0 .../blocks/text-block/index.js | 0 {modules/editor => editor}/editor/editor.js | 0 {modules/editor => editor}/editor/index.js | 0 {modules/editor => editor}/index.js | 0 {modules/editor => editor}/inserter/button.js | 0 {modules/editor => editor}/inserter/index.js | 0 {modules/editor => editor}/inserter/style.scss | 0 {modules/element => element}/index.js | 0 index.php | 8 ++++---- package.json | 2 +- webpack.config.js | 18 +++++------------- 20 files changed, 11 insertions(+), 19 deletions(-) rename {modules/blocks => blocks}/components/editable/index.js (100%) rename {modules/blocks => blocks}/index.js (100%) rename {modules/blocks => blocks}/parser/index.js (100%) rename {modules/blocks => blocks}/parser/post.pegjs (100%) rename {modules/blocks => blocks}/parser/test/index.js (100%) rename {modules/blocks => blocks}/test/index.js (100%) rename {modules/editor => editor}/assets/stylesheets/main.scss (100%) rename {modules/editor => editor}/blocks/index.js (100%) rename {modules/editor => editor}/blocks/text-block/index.js (100%) rename {modules/editor => editor}/editor/editor.js (100%) rename {modules/editor => editor}/editor/index.js (100%) rename {modules/editor => editor}/index.js (100%) rename {modules/editor => editor}/inserter/button.js (100%) rename {modules/editor => editor}/inserter/index.js (100%) rename {modules/editor => editor}/inserter/style.scss (100%) rename {modules/element => element}/index.js (100%) diff --git a/.eslintignore b/.eslintignore index 1f6015f87718e..378eac25d3117 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1 @@ -modules/*/build +build diff --git a/modules/blocks/components/editable/index.js b/blocks/components/editable/index.js similarity index 100% rename from modules/blocks/components/editable/index.js rename to blocks/components/editable/index.js diff --git a/modules/blocks/index.js b/blocks/index.js similarity index 100% rename from modules/blocks/index.js rename to blocks/index.js diff --git a/modules/blocks/parser/index.js b/blocks/parser/index.js similarity index 100% rename from modules/blocks/parser/index.js rename to blocks/parser/index.js diff --git a/modules/blocks/parser/post.pegjs b/blocks/parser/post.pegjs similarity index 100% rename from modules/blocks/parser/post.pegjs rename to blocks/parser/post.pegjs diff --git a/modules/blocks/parser/test/index.js b/blocks/parser/test/index.js similarity index 100% rename from modules/blocks/parser/test/index.js rename to blocks/parser/test/index.js diff --git a/modules/blocks/test/index.js b/blocks/test/index.js similarity index 100% rename from modules/blocks/test/index.js rename to blocks/test/index.js diff --git a/modules/editor/assets/stylesheets/main.scss b/editor/assets/stylesheets/main.scss similarity index 100% rename from modules/editor/assets/stylesheets/main.scss rename to editor/assets/stylesheets/main.scss diff --git a/modules/editor/blocks/index.js b/editor/blocks/index.js similarity index 100% rename from modules/editor/blocks/index.js rename to editor/blocks/index.js diff --git a/modules/editor/blocks/text-block/index.js b/editor/blocks/text-block/index.js similarity index 100% rename from modules/editor/blocks/text-block/index.js rename to editor/blocks/text-block/index.js diff --git a/modules/editor/editor/editor.js b/editor/editor/editor.js similarity index 100% rename from modules/editor/editor/editor.js rename to editor/editor/editor.js diff --git a/modules/editor/editor/index.js b/editor/editor/index.js similarity index 100% rename from modules/editor/editor/index.js rename to editor/editor/index.js diff --git a/modules/editor/index.js b/editor/index.js similarity index 100% rename from modules/editor/index.js rename to editor/index.js diff --git a/modules/editor/inserter/button.js b/editor/inserter/button.js similarity index 100% rename from modules/editor/inserter/button.js rename to editor/inserter/button.js diff --git a/modules/editor/inserter/index.js b/editor/inserter/index.js similarity index 100% rename from modules/editor/inserter/index.js rename to editor/inserter/index.js diff --git a/modules/editor/inserter/style.scss b/editor/inserter/style.scss similarity index 100% rename from modules/editor/inserter/style.scss rename to editor/inserter/style.scss diff --git a/modules/element/index.js b/element/index.js similarity index 100% rename from modules/element/index.js rename to element/index.js diff --git a/index.php b/index.php index 139ba71466e6d..8e62cf3f3db0f 100644 --- a/index.php +++ b/index.php @@ -40,8 +40,8 @@ function gutenberg_register_scripts() { wp_register_script( 'react-dom', 'https://unpkg.com/react-dom@15/dist/react-dom' . $suffix . '.js', array( 'react' ) ); // Editor - wp_register_script( 'wp-element', plugins_url( 'modules/element/build/index.js', __FILE__ ), array( 'react', 'react-dom' ) ); - wp_register_script( 'wp-blocks', plugins_url( 'modules/blocks/build/index.js', __FILE__ ), array( 'wp-element' ) ); + wp_register_script( 'wp-element', plugins_url( 'element/build/index.js', __FILE__ ), array( 'react', 'react-dom' ) ); + wp_register_script( 'wp-blocks', plugins_url( 'blocks/build/index.js', __FILE__ ), array( 'wp-element' ) ); } add_action( 'init', 'gutenberg_register_scripts' ); @@ -58,11 +58,11 @@ function gutenberg_scripts_and_styles( $hook ) { if ( 'toplevel_page_gutenberg' === $hook ) { // Scripts wp_register_script( 'gutenberg-content', plugins_url( 'post-content.js', __FILE__ ) ); - wp_enqueue_script( 'wp-editor', plugins_url( 'modules/editor/build/index.js', __FILE__ ), array( 'wp-blocks', 'wp-element', 'gutenberg-content' ), false, true ); + wp_enqueue_script( 'wp-editor', plugins_url( 'editor/build/index.js', __FILE__ ), array( 'wp-blocks', 'wp-element', 'gutenberg-content' ), false, true ); wp_add_inline_script( 'wp-editor', 'wp.editor.createEditorInstance( \'editor\', { content: window.content } );' ); // Styles - wp_enqueue_style( 'wp-editor', plugins_url( 'modules/editor/build/style.css', __FILE__ ) ); + wp_enqueue_style( 'wp-editor', plugins_url( 'editor/build/style.css', __FILE__ ) ); } } diff --git a/package.json b/package.json index e83483807ebff..d72d4786dbffa 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "scripts": { "test-unit": "cross-env NODE_ENV=test webpack && mocha build --require bootstrap-test.js", "build": "cross-env NODE_ENV=production webpack", - "lint": "eslint modules", + "lint": "eslint editor blocks element", "dev": "webpack --watch", "test": "npm run lint && npm run test-unit" }, diff --git a/webpack.config.js b/webpack.config.js index e769726006377..481729d2554d6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,26 +3,18 @@ */ const glob = require( 'glob' ); -const path = require( 'path' ); const webpack = require( 'webpack' ); const ExtractTextPlugin = require( 'extract-text-webpack-plugin' ); -/** - * Base path from which modules are to be discovered. - * - * @type {String} - */ -const BASE_PATH = './modules'; - const config = { entry: { - blocks: BASE_PATH + '/blocks/index.js', - editor: BASE_PATH + '/editor/index.js', - element: BASE_PATH + '/element/index.js' + blocks: './blocks/index.js', + editor: './editor/index.js', + element: './element/index.js' }, output: { filename: '[name]/build/index.js', - path: path.resolve( BASE_PATH ), + path: __dirname, library: [ 'wp', '[name]' ], libraryTarget: 'this' }, @@ -82,7 +74,7 @@ switch ( process.env.NODE_ENV ) { case 'test': config.target = 'node'; - config.entry = glob.sync( BASE_PATH + '/**/test/*.js' ); + config.entry = glob.sync( `./{${ Object.keys( config.entry ).join() }}/test/*.js` ); config.externals = [ require( 'webpack-node-externals' )() ]; config.output = { filename: 'build/test.js', From e161dcabacbe520ccf8234d9a40bfa01a2d686b9 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 24 Mar 2017 10:44:21 -0400 Subject: [PATCH 4/4] Lint top-level directory Ensures errors in e.g. webpack.config.js are flagged --- .eslintignore | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintignore b/.eslintignore index 378eac25d3117..ba2bd1dddf6cf 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ build +docs diff --git a/package.json b/package.json index d72d4786dbffa..9f2aeeee53482 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "scripts": { "test-unit": "cross-env NODE_ENV=test webpack && mocha build --require bootstrap-test.js", "build": "cross-env NODE_ENV=production webpack", - "lint": "eslint editor blocks element", + "lint": "eslint .", "dev": "webpack --watch", "test": "npm run lint && npm run test-unit" },