Require the config as CLI arg for watch, build and production-build

The mqtt control map now loads the config provided via cli. It is no longer required to modify the src/config.js to load a different config.
This commit is contained in:
uwap 2018-02-02 07:45:00 +01:00
parent 3975518f6e
commit c7ca716802
8 changed files with 34 additions and 22 deletions

View file

@ -1,16 +1,17 @@
# Space Map # MQTT Control Map
## How to set up ## Development / Configuration
1. run `yarn` to install all dependencies. 1. run `yarn` to install all dependencies.
2. run `yarn build` to compile everything 2. run `yarn watch CONFIG` to run a local build server that automatically builds
3. open the `index.html` your the mqtt control map for the given CONFIG everytime something changes.
4. ??? 3. run `yarn build CONFIG` to create just a single build of the mqtt control map
5. profit for the given config.
4. run `yarn production-build CONFIG` to generate all files for production use.
## Config ## Config
See `src/config.js`. See `config/`.
The Config format consists out of two sections. Topics and Controls. The Config format consists out of two sections. Topics and Controls.

View file

@ -60,4 +60,4 @@ const config : Config = {
] ]
}; };
export default config; window.config = config;

View file

@ -533,4 +533,4 @@ const config : Config = {
] ]
}; };
export default config; window.config = config;

View file

@ -4,9 +4,9 @@
"author": "uwap <me+mqttmap.package.json@uwap.name>", "author": "uwap <me+mqttmap.package.json@uwap.name>",
"description": "control devices via mqtt on a beautiful map of your space", "description": "control devices via mqtt on a beautiful map of your space",
"scripts": { "scripts": {
"build": "webpack --bail --config webpack.dev.js", "build": "webpack --bail --config webpack.dev.js --env",
"production-build": "webpack --bail --config webpack.prod.js", "production-build": "webpack --bail --config webpack.prod.js --env",
"watch": "webpack-dev-server --open --config webpack.dev.js", "watch": "webpack-dev-server --open --config webpack.dev.js --env",
"travis": "yarn lint && yarn build && yarn production-build", "travis": "yarn lint && yarn build && yarn production-build",
"lint": "eslint -- --ext js --ext jsx src/", "lint": "eslint -- --ext js --ext jsx src/",
"precommit": "yarn lint" "precommit": "yarn lint"

View file

@ -1,4 +0,0 @@
// @flow
import config from "../config/entropia";
export default config;

View file

@ -5,11 +5,10 @@ import injectTapEventPlugin from "react-tap-event-plugin";
import App from "components/App"; import App from "components/App";
import Config from "./config";
import "../node_modules/mdi/css/materialdesignicons.min.css"; import "../node_modules/mdi/css/materialdesignicons.min.css";
import "../css/styles.css"; import "../css/styles.css";
const Config = window.config;
injectTapEventPlugin(); injectTapEventPlugin();
document.title = `${Config.space.name} Map`; document.title = `${Config.space.name} Map`;

View file

@ -10,9 +10,17 @@ const extractCSS = ExtractTextPlugin.extract({
} }
}); });
module.exports = merge(common, { const configPath = env => {
if (env === true) {
throw "No config file was provided.";
}
return path.resolve(__dirname, `config/${env}`);
};
module.exports = env => merge(common, {
entry: { entry: {
main: path.resolve(__dirname, 'src/index.jsx') main: [configPath(env),
path.resolve(__dirname, 'src/index.jsx')]
}, },
module: { module: {
loaders: [ loaders: [

View file

@ -15,9 +15,17 @@ const extractCSS = ExtractTextPlugin.extract({
} }
}); });
module.exports = merge(common, { const configPath = env => {
if (env === true) {
throw "No config file was provided.";
}
return path.resolve(__dirname, `config/${env}`);
};
module.exports = env => merge(common, {
entry: { entry: {
main: path.resolve(__dirname, 'src/index.jsx'), main: [configPath(env),
path.resolve(__dirname, 'src/index.jsx')]
vendor: ['react', 'material-ui', 'mqtt', 'lodash'] vendor: ['react', 'material-ui', 'mqtt', 'lodash']
}, },
module: { module: {