From fa8cd1c797d36de85a211b0e3594b0c581343616 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 24 Mar 2017 10:38:56 -0400 Subject: [PATCH] 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 1f6015f87718ec..378eac25d31170 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 139ba71466e6d4..8e62cf3f3db0fe 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 e83483807ebfff..d72d4786dbffa9 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 e7697260063770..481729d2554d6e 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',