diff --git a/lib/gui/etcher.js b/lib/gui/etcher.js index 9a73fe9b..7b2d1e9a 100644 --- a/lib/gui/etcher.js +++ b/lib/gui/etcher.js @@ -81,7 +81,13 @@ const createMainWindow = () => { event.preventDefault() }) - mainWindow.loadURL(`file://${path.join(__dirname, 'app', 'index.html')}`) + const dir = __dirname.split(path.sep).pop() + + if (dir === 'generated') { + mainWindow.loadURL(`file://${path.join(__dirname, '..', 'lib', 'gui', 'app', 'index.html')}`) + } else { + mainWindow.loadURL(`file://${path.join(__dirname, 'app', 'index.html')}`) + } } electron.app.on('window-all-closed', electron.app.quit) diff --git a/lib/start.js b/lib/start.js index 32f470d6..562e6ec1 100644 --- a/lib/start.js +++ b/lib/start.js @@ -29,5 +29,5 @@ if (process.env.ELECTRON_RUN_AS_NODE || process.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE) { require('./gui/modules/child-writer') } else { - require('./gui/etcher') + require('../generated/etcher') } diff --git a/package.json b/package.json index 82f1a3dc..069b83e4 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "concourse-build-electron": "make webpack", "concourse-test": "npm test", "concourse-test-electron": "npm test", - "concourse-test-node-cli": "make lint-js lint-cpp lint-spell test-cli" + "concourse-test-node-cli": "make webpack lint-js lint-cpp lint-spell test-cli" }, "author": "Resin Inc. ", "license": "Apache-2.0", diff --git a/scripts/ci/install.sh b/scripts/ci/install.sh index fb536804..8c2b3133 100755 --- a/scripts/ci/install.sh +++ b/scripts/ci/install.sh @@ -75,4 +75,5 @@ else export TARGET_ARCH="$ARGV_ARCHITECTURE" make info make electron-develop + make webpack fi diff --git a/webpack.config.js b/webpack.config.js index 26cbbaa6..255f565b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -16,52 +16,14 @@ 'use strict' +const _ = require('lodash') const webpack = require('webpack') const path = require('path') const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin') const nodeExternals = require('webpack-node-externals') -module.exports = { +const commonConfig = { target: 'electron-main', - node: { - __dirname: true, - __filename: true - }, - entry: { - gui: path.join(__dirname, 'lib', 'gui', 'app', 'app.js') - }, - output: { - path: path.join(__dirname, 'generated'), - filename: '[name].js' - }, - externals: [ - nodeExternals(), - (context, request, callback) => { - // eslint-disable-next-line lodash/prefer-lodash-method - const absoluteContext = path.resolve(context) - const absoluteNodeModules = path.resolve('node_modules') - - // We shouldn't rewrite any node_modules import paths - // eslint-disable-next-line lodash/prefer-lodash-method - if (!path.relative(absoluteNodeModules, absoluteContext).startsWith('..')) { - return callback() - } - - // We want to keep the SDK code outside the GUI bundle. - // This piece of code allows us to run the GUI directly - // on the tree (for testing purposes) or inside a generated - // bundle (for production purposes), by translating - // relative require paths within the bundle. - if (/\/(sdk|shared)/i.test(request) || /package\.json$/.test(request)) { - const output = path.join(__dirname, 'generated') - const dirname = path.join(context, request) - const relative = path.relative(output, dirname) - return callback(null, `commonjs ${path.join('..', '..', relative)}`) - } - - return callback() - } - ], module: { rules: [ { @@ -96,3 +58,92 @@ module.exports = { }) ] } + +const guiConfig = _.assign({ + node: { + __dirname: true, + __filename: true + }, + externals: [ + nodeExternals(), + (context, request, callback) => { + // eslint-disable-next-line lodash/prefer-lodash-method + const absoluteContext = path.resolve(context) + const absoluteNodeModules = path.resolve('node_modules') + + // We shouldn't rewrite any node_modules import paths + // eslint-disable-next-line lodash/prefer-lodash-method + if (!path.relative(absoluteNodeModules, absoluteContext).startsWith('..')) { + return callback() + } + + // We want to keep the SDK code outside the GUI bundle. + // This piece of code allows us to run the GUI directly + // on the tree (for testing purposes) or inside a generated + // bundle (for production purposes), by translating + // relative require paths within the bundle. + if (/\/(sdk|shared)/i.test(request) || /package\.json$/.test(request)) { + const output = path.join(__dirname, 'generated') + const dirname = path.join(context, request) + const relative = path.relative(output, dirname) + return callback(null, `commonjs ${path.join('..', '..', relative)}`) + } + + return callback() + } + ], + entry: { + gui: path.join(__dirname, 'lib', 'gui', 'app', 'app.js') + }, + output: { + path: path.join(__dirname, 'generated'), + filename: '[name].js' + } +}, commonConfig) + +const etcherConfig = _.assign({ + node: { + __dirname: false, + __filename: true + }, + externals: [ + nodeExternals(), + (context, request, callback) => { + // eslint-disable-next-line lodash/prefer-lodash-method + const absoluteContext = path.resolve(context) + const absoluteNodeModules = path.resolve('node_modules') + + // We shouldn't rewrite any node_modules import paths + // eslint-disable-next-line lodash/prefer-lodash-method + if (!path.relative(absoluteNodeModules, absoluteContext).startsWith('..')) { + return callback() + } + + // We want to keep the SDK code outside the GUI bundle. + // This piece of code allows us to run the GUI directly + // on the tree (for testing purposes) or inside a generated + // bundle (for production purposes), by translating + // relative require paths within the bundle. + if (/\/(sdk|shared)/i.test(request) || /package\.json$/.test(request)) { + const output = path.join(__dirname, 'generated') + const dirname = path.join(context, request) + const relative = path.relative(output, dirname) + return callback(null, `commonjs ${path.join('..', 'lib', relative)}`) + } + + return callback() + } + ], + entry: { + etcher: path.join(__dirname, 'lib', 'gui', 'etcher.js') + }, + output: { + path: path.join(__dirname, 'generated'), + filename: '[name].js' + } +}, commonConfig) + +module.exports = [ + guiConfig, + etcherConfig +]