Skip to content

Commit

Permalink
Ready to deploy.
Browse files Browse the repository at this point in the history
  • Loading branch information
Empowerful committed Oct 25, 2019
1 parent e0c603e commit 5a3524f
Show file tree
Hide file tree
Showing 13 changed files with 805 additions and 531 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
"coverage:core": "yarn workspace blockchain-wallet-v4 coverage",
"coverage:main": "yarn workspace main-process coverage",
"coverage:security": "yarn workspace security-process coverage",
"debug:dev": "yarn workspace root-process debug:dev",
"debug:prod": "yarn workspace root-process debug:prod",
"debug:staging": "yarn workspace root-process debug:staging",
"fix": "cross-env yarn prettier && yarn lint:fix && yarn test:components:update && yarn test:frontend:update",
"link:resolved:paths": "yarn wsrun link:resolved:paths --exclude-missing",
"lint": "eslint --cache './packages/*/src/**/*.js'",
Expand Down Expand Up @@ -178,6 +180,7 @@
"file-loader": "3.0.1",
"generate-changelog": "1.7.1",
"html-webpack-plugin": "3.2.0",
"http-proxy": "1.18.0",
"husky": "2.3.0",
"identity-obj-proxy": "3.0.0",
"istanbul": "github:Xesenix/istanbul",
Expand Down
4 changes: 4 additions & 0 deletions packages/main-process/webpack.config.dev.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* eslint no-console: "off" */

'use strict'

const CleanWebpackPlugin = require('clean-webpack-plugin')
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
Expand Down
177 changes: 101 additions & 76 deletions packages/main-process/webpack.debug.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* eslint no-console: "off" */

'use strict'

const CleanWebpackPlugin = require('clean-webpack-plugin')
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
Expand All @@ -8,35 +12,110 @@ const fs = require('fs')

const babelConfig = require(`./babel.config.js`)

const src = path.join(__dirname, `src`)
const ContentSecurityPolicy = ({
api,
bitpay,
coinify,
coinifyPaymentDomain,
comWalletApp,
horizon,
i_sign_this_domain,
ledger,
ledgerSocket,
localhostUrl,
root,
sfox_kyc_url,
sfox_quote_url,
sfox_url,
shapeshift_url,
veriff,
walletHelper,
webpackHttp,
webpackWebSocket,
webSocket
}) => ({
'child-src': [
coinifyPaymentDomain,
i_sign_this_domain,
root,
veriff,
walletHelper
],
'connect-src': [
api,
bitpay,
coinify,
horizon,
ledgerSocket,
ledger,
localhostUrl,
root,
sfox_kyc_url,
sfox_quote_url,
sfox_url,
shapeshift_url,
webpackHttp,
webpackWebSocket,
webSocket,
'https://horizon.stellar.org',
'https://www.unocoin.com'
],
'default-src': [localhostUrl],
'font-src': [localhostUrl],
'form-action': [localhostUrl],
'frame-ancestors': [comWalletApp],
'frame-src': [
coinifyPaymentDomain,
i_sign_this_domain,
root,
veriff,
walletHelper
],
'img-src': [
localhostUrl,
root,
'android-webview-video-poster:',
'blob:',
'data:'
],
'media-src': [
localhostUrl,
'blob:',
'data:',
'https://storage.googleapis.com/bc_public_assets/',
'mediastream:'
],
'object-src': ["'none'"],
'script-src': [localhostUrl, "'unsafe-eval'"],
'style-src': ["'unsafe-inline'", localhostUrl],
'worker-src': ['blob:;']
})

const cspToString = policy =>
Object.entries(policy)
.map(([key, value]) => `${key} ${value.join(' ')}`)
.join(`; `)

const src = path.join(__dirname, `src`)

module.exports = ({
envConfig,
domains,
localhostUrl,
manifestCacheBust,
PATHS,
port,
rootProcessUrl,
sslEnabled
}) => {
const webSocketProtocol = sslEnabled ? `wss` : `ws`
const webSocketUrl = `${webSocketProtocol}://localhost:${port}`
const webpackHttpProtocol = sslEnabled ? `https` : `http`
const webpackUrlProtocol = sslEnabled ? `wss` : `ws`

return {
mode: 'production',
node: {
fs: 'empty'
},
entry: {
app: ['@babel/polyfill', src + '/index.js']
},
entry: ['@babel/polyfill', src + '/index.js'],
output: {
path: PATHS.ciBuild,
path: path.join(PATHS.ciBuild, `main`),
chunkFilename: '[name].[chunkhash:10].js',
publicPath: '/',
crossOriginLoading: 'anonymous'
Expand Down Expand Up @@ -90,8 +169,7 @@ module.exports = ({
new CleanWebpackPlugin(),
new CaseSensitivePathsPlugin(),
new Webpack.DefinePlugin({
APP_VERSION: JSON.stringify(require(PATHS.pkgJson).version),
NETWORK_TYPE: JSON.stringify(envConfig.NETWORK_TYPE)
APP_VERSION: JSON.stringify(require(PATHS.pkgJson).version)
}),
new HtmlWebpackPlugin({
template: src + '/index.html',
Expand Down Expand Up @@ -131,86 +209,33 @@ module.exports = ({
: '',
contentBase: src,
disableHostCheck: true,
host: 'localhost',
https: sslEnabled,
key: sslEnabled
? fs.readFileSync(PATHS.sslConfig + '/key.pem', 'utf8')
: '',
liveReload: false,
hot: false,
historyApiFallback: true,
proxy: {
'/ledger': {
target: envConfig.LEDGER_URL,
target: domains.ledger,
secure: false,
changeOrigin: true,
pathRewrite: { '^/ledger': '' }
}
},
overlay: {
warnings: true,
errors: true
},
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Security-Policy': cspToString({
'base-uri': [localhostUrl],
'connect-src': [
localhostUrl,
webSocketUrl,
envConfig.COINIFY_URL,
envConfig.WEB_SOCKET_URL,
envConfig.WALLET_HELPER_DOMAIN,
envConfig.LEDGER_URL,
envConfig.LEDGER_SOCKET_URL,
envConfig.HORIZON_URL,
envConfig.VERIFF_URL,
'https://app-api.sandbox.coinify.com',
'https://api.sfox.com',
'https://api.staging.sfox.com',
'https://api.testnet.blockchain.info',
`https://bitpay.com`,
'https://friendbot.stellar.org',
`https://horizon.blockchain.info`,
'https://quotes.sfox.com',
`https://quotes.staging.sfox.com`,
'https://sfox-kyc.s3.amazonaws.com',
'https://sfox-kyctest.s3.amazonaws.com',
'https://shapeshift.io',
'https://testnet5.blockchain.info',
`https://www.unocoin.com`,
`wss://api.ledgerwallet.com`,
`wss://ws.testnet.blockchain.info/inv`
],
'default-src': [localhostUrl],
'form-action': [localhostUrl],
'frame-ancestors': [rootProcessUrl],
'frame-src': [
envConfig.COINIFY_PAYMENT_DOMAIN,
envConfig.WALLET_HELPER_DOMAIN,
envConfig.ROOT_URL,
envConfig.VERIFF_URL,
`https://verify.isignthis.com/`
],
'img-src': [
localhostUrl,
`https://blockchain.info/`,
`data:`,
`blob:`,
`android-webview-video-poster:`
],
'media-src': [
'Content-Security-Policy': cspToString(
ContentSecurityPolicy({
...domains,
localhostUrl,
`blob:`,
`data:`,
`mediastream:`,
`https://storage.googleapis.com/bc_public_assets/`
],
'object-src': [`'none'`],
'script-src': [localhostUrl, `'unsafe-eval'`],
'style-src': [localhostUrl, `'unsafe-inline'`],
'worker-src': [`blob:`]
})
}
webpackHttp: `${webpackHttpProtocol}://localhost:8080`,
webpackWebSocket: `${webpackUrlProtocol}://localhost:8080`
})
)
},
writeToDisk: true
}
}
}
12 changes: 7 additions & 5 deletions packages/root-process/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
"main": "index.js",
"license": "MIT",
"scripts": {
"debug:prod": "cross-env-shell NODE_ENV=production webpack-dev-server --config webpack.debug.js --progress --colors",
"start:dev": "cross-env-shell NODE_ENV=development webpack-dev-server --config webpack.config.dev.js --progress --colors --watch --devtool cheap-module-source-map",
"start:prod": "cross-env-shell DISABLE_SSL=true NODE_ENV=production webpack-dev-server --config webpack.config.dev.js --progress --colors --watch --devtool cheap-module-source-map",
"start:staging": "cross-env-shell NODE_ENV=staging webpack-dev-server --config webpack.config.dev.js --progress --colors --watch --devtool cheap-module-source-map",
"start:testnet": "cross-env-shell NODE_ENV=testnet webpack-dev-server --config webpack.config.dev.js --progress --colors --watch --devtool cheap-module-source-map",
"debug:dev": "cross-env-shell BACKEND_ENV=development NODE_ENV=production webpack-dev-server --config webpack.debug.js --progress --colors",
"debug:prod": "cross-env-shell BACKEND_ENV=production NODE_ENV=production webpack-dev-server --config webpack.debug.js --progress --colors",
"debug:staging": "cross-env-shell BACKEND_ENV=staging NODE_ENV=production webpack-dev-server --config webpack.debug.js --progress --colors",
"start:dev": "cross-env-shell NODE_ENV=development NODE_OPTIONS=--max-old-space-size=8192 webpack-dev-server --config webpack.config.dev.js --progress --colors --watch --devtool cheap-module-source-map",
"start:prod": "cross-env-shell DISABLE_SSL=true NODE_ENV=production NODE_OPTIONS=--max-old-space-size=8192 webpack-dev-server --config webpack.config.dev.js --progress --colors --watch --devtool cheap-module-source-map",
"start:staging": "cross-env-shell NODE_ENV=staging NODE_OPTIONS=--max-old-space-size=8192 webpack-dev-server --config webpack.config.dev.js --progress --colors --watch --devtool cheap-module-source-map",
"start:testnet": "cross-env-shell NODE_ENV=testnet NODE_OPTIONS=--max-old-space-size=8192 webpack-dev-server --config webpack.config.dev.js --progress --colors --watch --devtool cheap-module-source-map",
"test": "echo 'No tests to execute.'",
"test:build": "echo 'No precomplilation required for tests to execute.'"
},
Expand Down
90 changes: 90 additions & 0 deletions packages/root-process/webpack.ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* eslint no-console: "off" */

'use strict'

const CleanWebpackPlugin = require('clean-webpack-plugin')
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const path = require('path')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')

const babelConfig = require(`./babel.config`)
const PATHS = require('../../config/paths')
const ProcessConfiguration = require(`./webpack.ci.process`)

let manifestCacheBust = new Date().getTime()
const src = path.join(__dirname, `src`)

const rootProcess = {
mode: 'production',
name: `root`,
node: {
fs: 'empty'
},
entry: ['@babel/polyfill', src + '/index.js'],
output: {
path: path.join(PATHS.ciBuild, `root`),
chunkFilename: '[name].[chunkhash:10].js',
publicPath: '/',
crossOriginLoading: 'anonymous'
},
module: {
rules: [
{
test: /\.js$/,
use: [
{ loader: 'thread-loader', options: { workerParallelJobs: 50 } },
{ loader: 'babel-loader', options: babelConfig }
]
},
{
test: /\.(png|jpg|gif|svg|ico|webmanifest|xml)$/,
use: {
loader: 'file-loader',
options: {
name: 'img/[name].[ext]'
}
}
}
]
},
performance: {
hints: false
},
plugins: [
new CleanWebpackPlugin(),
new CaseSensitivePathsPlugin(),
new HtmlWebpackPlugin({
template: src + '/index.html',
filename: 'index.html'
})
],
optimization: {
namedModules: true,
minimizer: [
new UglifyJSPlugin({
uglifyOptions: {
warnings: false,
compress: {
keep_fnames: true
},
mangle: {
keep_fnames: true
}
},
parallel: true,
cache: false
})
],
concatenateModules: true,
runtimeChunk: {
name: `manifest.${manifestCacheBust}`
}
}
}

module.exports = () => [
rootProcess,
ProcessConfiguration({ manifestCacheBust, PATHS }, `main`),
ProcessConfiguration({ manifestCacheBust, PATHS }, `security`)
]
Loading

0 comments on commit 5a3524f

Please sign in to comment.