From d02dd2a18ecd49e0a9c5bc6c89094289dd62dd78 Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 08:57:14 +0000 Subject: [PATCH 01/14] Update build step to use dash-generate-components With dash 0.31.1, the components are generated at build time, not at run time. This integrates the new build step in the tool chain. --- package.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index acad3f7d6..cc27e254a 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,10 @@ "description": "Bootstrap components for Plotly Dash", "main": "lib/index.js", "scripts": { - "build-dist": "npm run clean-lib && npm run extract-metadata && webpack --config=webpack.config.dist.js", - "clean-lib": "mkdirp lib && rimraf lib/*", - "copy-lib": "copyfiles -u 1 lib/* dash_bootstrap_components", + "build-dist": "npm run clean:py && mkdirp dash_bootstrap_components && npm run build:py && webpack --config=webpack.config.dist.js", + "clean:py": "mkdirp dash_bootstrap_components && rimraf dash_bootstrap_components", "demo": "webpack-dev-server --hot --inline --port=8888 --content-base=demo --config=webpack.config.demo.js", - "extract-metadata": "mkdirp lib && react-docgen --pretty -o lib/metadata.json src/components && node -e \"const fs = require('fs'); const path = require('path'); const m = JSON.parse(fs.readFileSync('./lib/metadata.json')); const r = {}; Object.keys(m).forEach(k => r[k.split(path.sep).join('/')] = m[k]); fs.writeFileSync('./lib/metadata.json', JSON.stringify(r, '\t', 2));\"", + "build:py": "dash-generate-components ./src/components dash_bootstrap_components", "format": "prettier src/**/*.js --write", "lint": "prettier src/**/*.js --list-different", "prepublish": "NODE_ENV=production npm run build-dist && npm run copy-lib", From 5e0bbedcbd946750f760cd0259e9f2a59d42a6ef Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 11:07:40 +0000 Subject: [PATCH 02/14] Build components into dbc.components --- dash_bootstrap_components/__init__.py | 23 +++++++---------------- package.json | 11 ++++++----- webpack.config.dist.js | 8 ++++---- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/dash_bootstrap_components/__init__.py b/dash_bootstrap_components/__init__.py index eefa91c57..93509988d 100644 --- a/dash_bootstrap_components/__init__.py +++ b/dash_bootstrap_components/__init__.py @@ -5,16 +5,11 @@ from . import themes # noqa from ._version import __version__ # noqa - -_current_path = os.path.dirname(os.path.abspath(__file__)) - -METADATA_PATH = os.path.join(_current_path, "metadata.json") - -# Dash automatic class creation from `metadata.json` file. +from . import components _js_dist = [ { - "relative_package_path": "bundle.js", + "relative_package_path": "dash_bootstrap_components.min.js", "namespace": "dash_bootstrap_components", } ] @@ -22,14 +17,10 @@ _css_dist = [] -def _setup_js_components(module, path_to_metadata): - components = dash.development.component_loader.load_components( - path_to_metadata, "dash_bootstrap_components" - ) - for component in components: - setattr(module, component.__name__, component) - component._js_dist = _js_dist - component._css_dist = _css_dist +for _component_name in components.__all__: + _component = getattr(components, _component_name) + _component._js_dist = _js_dist + _component._css_dist = _css_dist -_setup_js_components(sys.modules[__name__], METADATA_PATH) +from .components import * # noqa diff --git a/package.json b/package.json index cc27e254a..7d39bf16d 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,15 @@ "name": "dash-bootstrap-components", "version": "0.2.3", "description": "Bootstrap components for Plotly Dash", - "main": "lib/index.js", + "main": "src/index.js", "scripts": { - "build-dist": "npm run clean:py && mkdirp dash_bootstrap_components && npm run build:py && webpack --config=webpack.config.dist.js", - "clean:py": "mkdirp dash_bootstrap_components && rimraf dash_bootstrap_components", + "build-dist": "npm run clean:py && npm run build:py && webpack --config=webpack.config.dist.js", + "clean:py": "mkdirp dash_bootstrap_components/components && rimraf dash_bootstrap_components/components", "demo": "webpack-dev-server --hot --inline --port=8888 --content-base=demo --config=webpack.config.demo.js", - "build:py": "dash-generate-components ./src/components dash_bootstrap_components", + "build:py": "mkdirp dash_bootstrap_components/components && dash-generate-components ./src/components dash_bootstrap_components/components && move-cli dash_bootstrap_components/components/_imports_.py dash_bootstrap_components/components/__init__.py", "format": "prettier src/**/*.js --write", "lint": "prettier src/**/*.js --list-different", - "prepublish": "NODE_ENV=production npm run build-dist && npm run copy-lib", + "prepublish": "NODE_ENV=production npm run build-dist", "test": "jest", "test:demo": "webpack --content-base=demo --config=webpack.config.demo.js", "test:watch": "jest --watch" @@ -31,6 +31,7 @@ "jest": "^23.6.0", "jest-environment-jsdom-global": "^1.1.0", "jsdom": "^12.0.0", + "move-cli": "^1.2.0", "prettier": "^1.14.3", "react-docgen": "^2.21.0", "style-loader": "^0.23.1", diff --git a/webpack.config.dist.js b/webpack.config.dist.js index b6144b2f4..93abfc866 100644 --- a/webpack.config.dist.js +++ b/webpack.config.dist.js @@ -13,7 +13,7 @@ var NODE_ENV = process.env.NODE_ENV || 'development'; var environment = JSON.stringify(NODE_ENV); var LIBRARY_NAME = 'dash_bootstrap_components'; -var BUILD_PATH = path.join(ROOT, 'lib'); +var BUILD_PATH = path.join(ROOT, LIBRARY_NAME, 'components'); /* eslint-disable no-console */ console.log('Current environment: ' + environment); @@ -25,7 +25,7 @@ module.exports = { mode: NODE_ENV, externals: { react: 'React', - 'react-dom': 'ReactDOM' + 'react-dom': 'ReactDOM', }, module: { noParse: /node_modules\/json-schema\/lib\/validate\.js/, // used to get `request` to work: https://github.com/request/request/issues/1920#issuecomment-171246043 @@ -58,12 +58,12 @@ module.exports = { minimize: true }, entry: { - bundle: ['./index.js'] + main: './index.js' }, output: { library: LIBRARY_NAME, libraryTarget: 'this', // Could be 'umd' path: BUILD_PATH, - filename: '[name].js' + filename: LIBRARY_NAME + '.min.js' } }; From 80deb358fc57b44247d605c3fe56115459941b5e Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 11:14:51 +0000 Subject: [PATCH 03/14] Make _components package private --- dash_bootstrap_components/__init__.py | 12 ++++-------- package.json | 4 ++-- webpack.config.dist.js | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/dash_bootstrap_components/__init__.py b/dash_bootstrap_components/__init__.py index 93509988d..77763d8e1 100644 --- a/dash_bootstrap_components/__init__.py +++ b/dash_bootstrap_components/__init__.py @@ -1,11 +1,7 @@ -import os -import sys - -import dash from . import themes # noqa from ._version import __version__ # noqa -from . import components +from . import _components _js_dist = [ { @@ -17,10 +13,10 @@ _css_dist = [] -for _component_name in components.__all__: - _component = getattr(components, _component_name) +for _component_name in _components.__all__: + _component = getattr(_components, _component_name) _component._js_dist = _js_dist _component._css_dist = _css_dist -from .components import * # noqa +from ._components import * # noqa diff --git a/package.json b/package.json index 7d39bf16d..c9af01b2a 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "main": "src/index.js", "scripts": { "build-dist": "npm run clean:py && npm run build:py && webpack --config=webpack.config.dist.js", - "clean:py": "mkdirp dash_bootstrap_components/components && rimraf dash_bootstrap_components/components", + "clean:py": "mkdirp dash_bootstrap_components/_components && rimraf dash_bootstrap_components/_components", "demo": "webpack-dev-server --hot --inline --port=8888 --content-base=demo --config=webpack.config.demo.js", - "build:py": "mkdirp dash_bootstrap_components/components && dash-generate-components ./src/components dash_bootstrap_components/components && move-cli dash_bootstrap_components/components/_imports_.py dash_bootstrap_components/components/__init__.py", + "build:py": "mkdirp dash_bootstrap_components/_components && dash-generate-components ./src/components dash_bootstrap_components/_components && move-cli dash_bootstrap_components/_components/_imports_.py dash_bootstrap_components/_components/__init__.py", "format": "prettier src/**/*.js --write", "lint": "prettier src/**/*.js --list-different", "prepublish": "NODE_ENV=production npm run build-dist", diff --git a/webpack.config.dist.js b/webpack.config.dist.js index 93abfc866..27a4fe707 100644 --- a/webpack.config.dist.js +++ b/webpack.config.dist.js @@ -13,7 +13,7 @@ var NODE_ENV = process.env.NODE_ENV || 'development'; var environment = JSON.stringify(NODE_ENV); var LIBRARY_NAME = 'dash_bootstrap_components'; -var BUILD_PATH = path.join(ROOT, LIBRARY_NAME, 'components'); +var BUILD_PATH = path.join(ROOT, LIBRARY_NAME, '_components'); /* eslint-disable no-console */ console.log('Current environment: ' + environment); From bebe576b40e34ac9ab6fae617d8538c5439ed99f Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 12:00:07 +0000 Subject: [PATCH 04/14] Restore METADATA_PATH variable for docs --- dash_bootstrap_components/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dash_bootstrap_components/__init__.py b/dash_bootstrap_components/__init__.py index 77763d8e1..8f71ee98d 100644 --- a/dash_bootstrap_components/__init__.py +++ b/dash_bootstrap_components/__init__.py @@ -1,8 +1,13 @@ +import os from . import themes # noqa from ._version import __version__ # noqa from . import _components +_current_path = os.path.dirname(os.path.abspath(__file__)) + +METADATA_PATH = os.path.join(_current_path, "_components", "metadata.json") + _js_dist = [ { "relative_package_path": "dash_bootstrap_components.min.js", From 43ad698daa821e5b79416e6e0a5d01f355d9d4c0 Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 12:00:48 +0000 Subject: [PATCH 05/14] Correct bundling of components --- webpack.config.dist.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webpack.config.dist.js b/webpack.config.dist.js index 27a4fe707..5e2c250b0 100644 --- a/webpack.config.dist.js +++ b/webpack.config.dist.js @@ -13,7 +13,7 @@ var NODE_ENV = process.env.NODE_ENV || 'development'; var environment = JSON.stringify(NODE_ENV); var LIBRARY_NAME = 'dash_bootstrap_components'; -var BUILD_PATH = path.join(ROOT, LIBRARY_NAME, '_components'); +var BUILD_PATH = path.join(ROOT, LIBRARY_NAME); /* eslint-disable no-console */ console.log('Current environment: ' + environment); @@ -61,8 +61,8 @@ module.exports = { main: './index.js' }, output: { - library: LIBRARY_NAME, - libraryTarget: 'this', // Could be 'umd' + library: LIBRARY_NAME + "/_components", + libraryTarget: 'window', path: BUILD_PATH, filename: LIBRARY_NAME + '.min.js' } From ba3fc9431b25539fe909c17e45eb4c8cd4a3a452 Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 12:07:11 +0000 Subject: [PATCH 06/14] MOve build artefacts to _components/ --- dash_bootstrap_components/__init__.py | 2 +- webpack.config.dist.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dash_bootstrap_components/__init__.py b/dash_bootstrap_components/__init__.py index 8f71ee98d..d3ca9df04 100644 --- a/dash_bootstrap_components/__init__.py +++ b/dash_bootstrap_components/__init__.py @@ -10,7 +10,7 @@ _js_dist = [ { - "relative_package_path": "dash_bootstrap_components.min.js", + "relative_package_path": "_components/dash_bootstrap_components.min.js", "namespace": "dash_bootstrap_components", } ] diff --git a/webpack.config.dist.js b/webpack.config.dist.js index 5e2c250b0..fcfc51646 100644 --- a/webpack.config.dist.js +++ b/webpack.config.dist.js @@ -13,7 +13,7 @@ var NODE_ENV = process.env.NODE_ENV || 'development'; var environment = JSON.stringify(NODE_ENV); var LIBRARY_NAME = 'dash_bootstrap_components'; -var BUILD_PATH = path.join(ROOT, LIBRARY_NAME); +var BUILD_PATH = path.join(ROOT, LIBRARY_NAME, '_components'); /* eslint-disable no-console */ console.log('Current environment: ' + environment); @@ -61,7 +61,7 @@ module.exports = { main: './index.js' }, output: { - library: LIBRARY_NAME + "/_components", + library: LIBRARY_NAME + '/_components', libraryTarget: 'window', path: BUILD_PATH, filename: LIBRARY_NAME + '.min.js' From f211c727a3943b7c38358ee5f58d9f21a9201493 Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 12:07:44 +0000 Subject: [PATCH 07/14] Consistent indentation of loaders --- webpack.config.dist.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/webpack.config.dist.js b/webpack.config.dist.js index fcfc51646..a2b586b85 100644 --- a/webpack.config.dist.js +++ b/webpack.config.dist.js @@ -49,7 +49,14 @@ module.exports = { }, { test: /\.css$/, - use: [{loader: 'style-loader'}, {loader: 'css-loader'}] + use: [ + { + loader: 'style-loader' + }, + { + loader: 'css-loader' + } + ] } ] }, From 2b6b1c76cffa2e7025ee5b17a6f6a5f5302f9218 Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 13:05:49 +0000 Subject: [PATCH 08/14] Bundle demo code into demo-lib --- demo/index.html | 2 +- package.json | 2 +- webpack.config.demo.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/demo/index.html b/demo/index.html index c6a228f9d..76b49b6e9 100644 --- a/demo/index.html +++ b/demo/index.html @@ -14,6 +14,6 @@
- + diff --git a/package.json b/package.json index c9af01b2a..4cf414da3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "dash-bootstrap-components", "version": "0.2.3", "description": "Bootstrap components for Plotly Dash", - "main": "src/index.js", + "main": "demo-lib/index.js", "scripts": { "build-dist": "npm run clean:py && npm run build:py && webpack --config=webpack.config.dist.js", "clean:py": "mkdirp dash_bootstrap_components/_components && rimraf dash_bootstrap_components/_components", diff --git a/webpack.config.demo.js b/webpack.config.demo.js index aa66e7d2d..e0c0ba978 100644 --- a/webpack.config.demo.js +++ b/webpack.config.demo.js @@ -11,7 +11,7 @@ var NODE_ENV = process.env.NODE_ENV || 'development'; var environment = JSON.stringify(NODE_ENV); var LIBRARY_NAME = 'dash_bootstrap_components'; -var BUILD_PATH = path.join(ROOT, 'lib'); +var BUILD_PATH = path.join(ROOT, 'demo-lib'); var publicHost = process.env.DEMO_PUBLIC_HOST || undefined; @@ -68,7 +68,7 @@ module.exports = { libraryTarget: 'this', // Could be 'umd' path: BUILD_PATH, pathinfo: true, - publicPath: '/lib/', // For loading from webpack dev server + publicPath: '/demo-lib/', // For loading from webpack dev server filename: '[name].js' } }; From 4e753a597ac0cd6dbaf32eadc8043dd6db3ea537 Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 13:07:47 +0000 Subject: [PATCH 09/14] Migrate content-base to configuration --- package.json | 2 +- webpack.config.demo.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4cf414da3..d14c54372 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "build-dist": "npm run clean:py && npm run build:py && webpack --config=webpack.config.dist.js", "clean:py": "mkdirp dash_bootstrap_components/_components && rimraf dash_bootstrap_components/_components", - "demo": "webpack-dev-server --hot --inline --port=8888 --content-base=demo --config=webpack.config.demo.js", + "demo": "webpack-dev-server --hot --inline --port=8888 --config=webpack.config.demo.js", "build:py": "mkdirp dash_bootstrap_components/_components && dash-generate-components ./src/components dash_bootstrap_components/_components && move-cli dash_bootstrap_components/_components/_imports_.py dash_bootstrap_components/_components/__init__.py", "format": "prettier src/**/*.js --write", "lint": "prettier src/**/*.js --list-different", diff --git a/webpack.config.demo.js b/webpack.config.demo.js index e0c0ba978..7794e625f 100644 --- a/webpack.config.demo.js +++ b/webpack.config.demo.js @@ -62,6 +62,7 @@ module.exports = { }, devServer: { public: publicHost, + contentBase: 'demo' }, output: { library: LIBRARY_NAME, From 75120cb3fa5578cce24388400dd3343eb0471f22 Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 14:43:18 +0000 Subject: [PATCH 10/14] Lower bound on Dash version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index dab5ff8d2..35df34d62 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,6 @@ def _get_long_description(): author_email="engineering@asidatascience.com", url="https://github.com/ASIDataScience/dash-bootstrap-components", packages=find_packages(), - install_requires=["dash"], + install_requires=["dash>=0.32.1"], include_package_data=True, ) From a266f5fc39847fac917a877f11ebeb8357e67afc Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 15:22:32 +0000 Subject: [PATCH 11/14] Update manifest with new path to components --- MANIFEST.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index e3fbd8949..dfc9028f0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ -include dash_bootstrap_components/bundle.js -include dash_bootstrap_components/metadata.json +include dash_bootstrap_components/_components/dash-bootstrap-components.min.js +include dash_bootstrap_components/_components/metadata.json \ No newline at end of file From d7c76d7a6fd7f2dfa31bac03554c7170c723ff90 Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 15:25:42 +0000 Subject: [PATCH 12/14] Avoid long lines --- dash_bootstrap_components/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dash_bootstrap_components/__init__.py b/dash_bootstrap_components/__init__.py index d3ca9df04..745e66afc 100644 --- a/dash_bootstrap_components/__init__.py +++ b/dash_bootstrap_components/__init__.py @@ -10,7 +10,9 @@ _js_dist = [ { - "relative_package_path": "_components/dash_bootstrap_components.min.js", + "relative_package_path": ( + "_components/dash_bootstrap_components.min.js" + ), "namespace": "dash_bootstrap_components", } ] From 5ac9cfa958602f2d1e81bb0b9a9379aeec525751 Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 15:26:36 +0000 Subject: [PATCH 13/14] Add dash to JS build chain Dash is now needed to run npm install. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index bdc551a9e..c959342bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ cache: directories: - "node_modules" install: + - "if [[ \"$GROUP\" == js ]] ; then pip install dash ; fi" - "if [[ \"$GROUP\" == js ]] ; then npm -v ; fi" - "if [[ \"$GROUP\" == js ]] ; then npm install ; fi" - "if [[ \"$GROUP\" == python-linting ]] ; then pip install black flake8 isort ; fi" From 11a318a329cded89ceea9a1cd8f3fb310d49f0f1 Mon Sep 17 00:00:00 2001 From: Pascal Bugnion Date: Sun, 9 Dec 2018 15:44:08 +0000 Subject: [PATCH 14/14] Correct path in manifest --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index dfc9028f0..1a578d412 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ -include dash_bootstrap_components/_components/dash-bootstrap-components.min.js +include dash_bootstrap_components/_components/dash_bootstrap_components.min.js include dash_bootstrap_components/_components/metadata.json \ No newline at end of file