Skip to content

Commit

Permalink
Updated the build system so the right config files get added in with …
Browse files Browse the repository at this point in the history
…initial development
  • Loading branch information
ray-millward-tessella committed Jun 14, 2018
1 parent d7f2f0b commit df1ad7a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 27 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ install:
- npm install -g codecov
- npm install
script:
- chmod +x $TRAVIS_BUILD_DIR/continuous_integration/make_settings.sh
- "$TRAVIS_BUILD_DIR/continuous_integration/make_settings.sh $TRAVIS_BUILD_DIR"
- npm run lint:css
- npm run lint:js
- npm run build
- npm run test
- codecov
- npm run e2e
before_deploy:
- npm run config:prod
- chmod +x $TRAVIS_BUILD_DIR/continuous_integration/package_artifacts.sh
- "$TRAVIS_BUILD_DIR/continuous_integration/package_artifacts.sh $TRAVIS_BUILD_DIR"
deploy:
Expand Down
13 changes: 0 additions & 13 deletions continuous_integration/make_settings.sh

This file was deleted.

21 changes: 21 additions & 0 deletions continuous_integration/update_settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { execSync } = require('child_process');
var fs = require('fs');

console.log(process.argv)
if (process.argv[2] === 'dev') {
console.log('checking if settings already exist...');
if (!fs.existsSync('./public/settings.json')) {
console.log('copying dev settings over');
fs.copyFileSync('./settings.dev.json', './public/settings.json');
} else {
console.log('settings exist...doing nothing')
}
} else if (process.argv[2] === 'prod') {
const gitInfo = execSync('git describe --tags --long').toString();
console.log('Packaging version ' + gitInfo);

let prodConfig = JSON.parse(fs.readFileSync('./settings.prod.json', 'utf8'));
prodConfig.version = gitInfo.replace('\r', '').replace('\n', '');

fs.writeFileSync('./build/settings.json', JSON.stringify(prodConfig, null, 2), 'utf8');
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@
"precommit": "lint-staged",
"server": "node ./server/test-malcolm-server.js",
"server:dev": "nodemon ./server/test-malcolm-server.js",
"start": "concurrently \"npm run server:dev\" \"react-scripts start\"",
"build": "react-scripts build",
"start": "npm run config:dev & concurrently \"npm run server:dev\" \"react-scripts start\"",
"build": "npm run config:dev & react-scripts build",
"build:prod": "npm run build & npm run config:prod",
"test": "react-scripts test --env=jsdom --coverage",
"test:watch": "react-scripts test --env=jsdom --watch",
"eject": "react-scripts eject",
Expand All @@ -77,7 +78,9 @@
"storybook": "start-storybook -p 9009 -s public",
"build-storybook": "build-storybook -s public",
"build-docs": "sphinx-build -b html docs/source docs/build/html",
"sonarqube": "sonar-scanner"
"sonarqube": "sonar-scanner",
"config:dev": "node ./continuous_integration/update_settings.js dev",
"config:prod": "node ./continuous_integration/update_settings.js prod"
},
"devDependencies": {
"babel-core": "^6.26.0",
Expand Down
4 changes: 4 additions & 0 deletions settings.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"malcolmSocket": "ws://localhost:8000/ws",
"version": "1.0.0"
}
File renamed without changes.
12 changes: 8 additions & 4 deletions src/malcolm/actions/socket.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ export const registerSocketAndConnect = (socketContainer, socketUrl) => ({
});

export const configureSocket = socketContainer => dispatch => {
const baseUrl = `${window.location.protocol}//${window.location.host}/`;
const baseUrl = `${window.location.protocol}//${window.location.host}`;
axios.get(`${baseUrl}/settings.json`).then(res => {
const settings = res.data;
console.log(settings);
dispatch(updateVersionNumber(settings.version));

const malcolmSocket =
settings.malcolmSocket || `ws://${window.location.host}/ws`;
dispatch(registerSocketAndConnect(socketContainer, malcolmSocket));
// in production no socket will be defined and it will default to ws://{{host}}/ws
if (settings.malcolmSocket) {
dispatch(
registerSocketAndConnect(socketContainer, settings.malcolmSocket)
);
}
});
};

export default {
configureSocket,
registerSocketAndConnect,
};
4 changes: 0 additions & 4 deletions src/malcolm/malcolmSocketHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import handleLocationChange from './middleware/malcolmRouting';
const configureMalcolmSocketHandlers = (inputSocketContainer, store) => {
const socketContainer = inputSocketContainer;

if (socketContainer.socket instanceof MalcolmReconnector) {
// setTimeout(socketContainer.socket.connect, 0, socketContainer.socket);
}

socketContainer.socket.onerror = error => {
const errorString = JSON.stringify(error);
store.dispatch(
Expand Down
3 changes: 2 additions & 1 deletion src/navbar/navcontrol.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('NavControl', () => {

wrapper.find('IconButton').simulate('click');

expect(wrapper.state.anchorEl).toEqual('werwer');
console.log(wrapper.state());
expect(wrapper.state('anchorEl')).toEqual('werwer');
});
});

0 comments on commit df1ad7a

Please sign in to comment.