Skip to content

Update build chain for dash 0.32.1 #94

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

Merged
merged 14 commits into from
Dec 12, 2018
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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
26 changes: 10 additions & 16 deletions dash_bootstrap_components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
import os
import sys

import dash

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, "metadata.json")

# Dash automatic class creation from `metadata.json` file.
METADATA_PATH = os.path.join(_current_path, "_components", "metadata.json")

_js_dist = [
{
"relative_package_path": "bundle.js",
"relative_package_path": (
"_components/dash_bootstrap_components.min.js"
),
"namespace": "dash_bootstrap_components",
}
]

_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
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<div id="react-demo-entry-point"></div>
</body>

<script type="text/javascript" src="/lib/bundle.js"></script>
<script type="text/javascript" src="/demo-lib/bundle.js"></script>

</html>
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
"name": "dash-bootstrap-components",
"version": "0.2.3",
"description": "Bootstrap components for Plotly Dash",
"main": "lib/index.js",
"main": "demo-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",
"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-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 --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",
Copy link
Collaborator

@tcbegley tcbegley Dec 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add something like black dash_bootstrap_components/_components to this? Otherwise the generated Python files are going to fail the build once they get added to version control.

Actually ignore this, I think we're not keeping these under version control right? We're just generating them for inclusion in the distribution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we don't keep the generated sources under version control (unlike, for instance, dash-core-components).

While we could still reformat them with black, I'd vote against because:

  • it makes building a little bit longer for no benefit
  • it adds more point of failures in the build chain.

"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"
Expand All @@ -32,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",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def _get_long_description():
author_email="[email protected]",
url="https://github.com/ASIDataScience/dash-bootstrap-components",
packages=find_packages(),
install_requires=["dash"],
install_requires=["dash>=0.32.1"],
include_package_data=True,
)
5 changes: 3 additions & 2 deletions webpack.config.demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -62,13 +62,14 @@ module.exports = {
},
devServer: {
public: publicHost,
contentBase: 'demo'
},
output: {
library: LIBRARY_NAME,
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'
}
};
21 changes: 14 additions & 7 deletions webpack.config.dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -49,7 +49,14 @@ module.exports = {
},
{
test: /\.css$/,
use: [{loader: 'style-loader'}, {loader: 'css-loader'}]
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader'
}
]
}
]
},
Expand All @@ -58,12 +65,12 @@ module.exports = {
minimize: true
},
entry: {
bundle: ['./index.js']
main: './index.js'
},
output: {
library: LIBRARY_NAME,
libraryTarget: 'this', // Could be 'umd'
library: LIBRARY_NAME + '/_components',
libraryTarget: 'window',
path: BUILD_PATH,
filename: '[name].js'
filename: LIBRARY_NAME + '.min.js'
}
};