Skip to content

Commit

Permalink
Merge pull request #538 from LiskHQ/491-move-the-default-network-sett…
Browse files Browse the repository at this point in the history
…ing-outside

Move the default network setting outside of built bundles - Closes #491
  • Loading branch information
faival authored Mar 13, 2018
2 parents 9d67763 + e74b13f commit c82683d
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist
node_modules
coverage
app/build
app/build-testnet
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"beforeEach": true,
"afterEach": true,
"ipc": true,
"DEFAULT_NEWTORK": true,
"PRODUCTION": true,
"TEST": true
},
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ e2e-test-screenshots
app/report.html
app/*.map
app/build
app/build-testnet
*.sw[pon]
app/app.js
.vscode
Expand Down
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ node('lisk-hub') {
sh '''
cp ~/.coveralls.yml-hub .coveralls.yml
npm run --silent build
npm run --silent build:testnet
rsync -axl --delete --rsync-path="mkdir -p /var/www/test/${JOB_NAME%/*}/$BRANCH_NAME/ && rsync" $WORKSPACE/app/build/ jenkins@master-01:/var/www/test/${JOB_NAME%/*}/$BRANCH_NAME/
npm run --silent bundlesize
'''
Expand Down
5 changes: 1 addition & 4 deletions config/webpack.config.react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable import/no-extraneous-dependencies */
const { resolve } = require('path');
const { ContextReplacementPlugin, DefinePlugin } = require('webpack');
const { ContextReplacementPlugin } = require('webpack');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
Expand Down Expand Up @@ -97,9 +97,6 @@ module.exports = {
historyApiFallback: true,
},
plugins: [
new DefinePlugin({
DEFAULT_NEWTORK: JSON.stringify(process.env.TESTNET ? 'testnet' : 'mainnet'),
}),
new StyleLintPlugin({
context: `${resolve(__dirname, '../src')}/`,
files: '**/*.css',
Expand Down
1 change: 1 addition & 0 deletions config/webpack.config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ module.exports = merge(baseConfig, reactConfig, {
],
externals,
});

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"main": "main.js",
"scripts": {
"build": "npm run clean-build && npm run copy-files && npm run build-prod && npm run build-electron",
"build:testnet": "export TESTNET=true && npm run build",
"build:testnet": "npm run build:testnet:pre",
"build:testnet:pre": "cpx \"./app/build/**\" ./app/build-testnet && npm run build:testnet:post",
"build:testnet:post": "replace '\"mainnet\";//defaultNetwork' '\"testnet\";//defaultNetwork' ./app/build-testnet/index.html ",
"dev": "webpack-dev-server --config ./config/webpack.config.dev --env.dev --hot",
"build-prod": "webpack --config ./config/webpack.config.prod --env.prod",
"build-electron": "webpack --config ./config/webpack.config.electron",
Expand Down Expand Up @@ -159,6 +161,7 @@
"react-hot-loader": "=1.3.1",
"react-test-renderer": "=16.0.0",
"redux-mock-store": "1.3.0",
"replace": "0.3.0",
"should": "13.1.0",
"simulant": "0.2.2",
"sinon": "3.3.0",
Expand Down
3 changes: 2 additions & 1 deletion src/components/register/register.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { spy, match } from 'sinon';
import PropTypes from 'prop-types';
import configureMockStore from 'redux-mock-store';

import networks from '../../constants/networks';
import accounts from '../../../test/constants/accounts';
import i18n from '../../i18n';
import Register from './register';
Expand Down Expand Up @@ -61,7 +62,7 @@ describe('Register', () => {
it('should call activePeerSet with network and passphrase', () => {
wrapper.find('MultiStep').props().finalCallback(passphrase);
expect(prop.activePeerSet).to.have.been.calledWith(match({
network: { code: 0, name: 'Mainnet', port: 443, ssl: true },
network: networks.mainnet,
passphrase,
}));
});
Expand Down
3 changes: 1 addition & 2 deletions src/constants/env.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const env = {
production: PRODUCTION,
test: TEST,
development: (!PRODUCTION && !TEST),
defaultNetwork: DEFAULT_NEWTORK,
test: TEST,
};

export default env;
5 changes: 1 addition & 4 deletions src/constants/networks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import env from './env';

const networks = {
mainnet: { // network name translation t('Mainnet');
name: 'Mainnet',
Expand All @@ -22,6 +20,5 @@ const networks = {
},
};

networks.default = networks[env.defaultNetwork];

networks.default = networks[window.localStorage && window.localStorage.getItem('defaultNetwork')] || networks.mainnet;
module.exports = networks;
9 changes: 9 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
<%= compilation.assets['head.css'].source() %>
</style>
<link rel="icon" type="image/png" href="./assets/images/LISK.png" />
<script type="text/javascript">
/* Following comment is a placeholder used by `npm run build:testnet`, do not remove */
var defaultNet = "mainnet";//defaultNetwork
(function(targetNet) {
if (window.localStorage && !window.localStorage.getItem('defaultNetwork')){
window.localStorage.setItem('defaultNetwork', defaultNet);
}
})(defaultNet);
</script>
</head>
<body>
<div id="app"></div>
Expand Down

0 comments on commit c82683d

Please sign in to comment.