From 1caa85f823b3c98964dd08ece9fb4e59c87344bc Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 14 May 2018 13:01:23 +0200 Subject: [PATCH 1/9] Use commander instead of yargs --- electron/cli/index.js | 77 +++++--------------------------- electron/index.js | 13 +----- electron/operations/runParity.js | 17 ++++--- package.json | 4 +- yarn.lock | 19 +------- 5 files changed, 27 insertions(+), 103 deletions(-) diff --git a/electron/cli/index.js b/electron/cli/index.js index 41caeb0b..84198702 100644 --- a/electron/cli/index.js +++ b/electron/cli/index.js @@ -3,79 +3,24 @@ // // SPDX-License-Identifier: MIT -/* eslint-disable */ -const dynamicRequire = - typeof __non_webpack_require__ === 'undefined' - ? require - : __non_webpack_require__; // Dynamic require https://github.com/yargs/yargs/issues/781 -/* eslint-enable */ - const { app } = require('electron'); +const cli = require('commander'); const fs = require('fs'); const omit = require('lodash/omit'); const { spawn } = require('child_process'); -const argv = dynamicRequire('yargs').argv; const parityPath = require('../utils/parityPath'); const { version } = require('../../package.json'); -let parityArgv = null; // Args to pass to `parity` command - -/** - * Show output of `parity` command with args. The args are supposed to make - * parity stop, so that the output can be immediately shown on the terminal. - * - * @param {Array} args - The arguments to pass to `parity`. - */ -const showParityOutput = args => { - if (fs.existsSync(parityPath())) { - const parityHelp = spawn(parityPath(), args); - - parityHelp.stdout.on('data', data => console.log(data.toString())); - parityHelp.on('close', () => app.quit()); - } else { - console.log( - 'Please run Parity Light Wallet once to install Parity Light Client. This help message will then show all available commands.' - ); - app.quit(); - } - - return false; -}; - -module.exports = () => { - if (argv.help || argv.h) { - return showParityOutput(['--help']); - } +cli + .version(version) + .allowUnknownOption() + .option( + '--ui-dev', + 'The Light Wallet will load http://localhost:3000. WARNING: Only use this is you plan on developing on Parity UI.' + ) + .parse(process.argv); - if (argv.version || argv.v) { - console.log(`Parity UI version ${version}.`); - return showParityOutput(['--version']); - } - - // Used cached value if it exists - if (parityArgv) { - return [argv, parityArgv]; - } - - // Args to pass to `parity` command - parityArgv = omit(argv, '_', '$0', 'help', 'version'); - - // Sanitize args to be easily used by parity - Object.keys(parityArgv).forEach(key => { - // Delete all keys starting with --ui* from parityArgv. - // They will be handled directly by the UI. - if (key.startsWith('ui')) { - delete parityArgv[key]; - } - - // yargs create camelCase keys for each arg, e.g. "--ws-origins all" will - // create { wsOrigins: 'all' }. For parity, we remove all those that have - // a capital letter - if (/[A-Z]/.test(key)) { - delete parityArgv[key]; - } - }); +let parityArgv = null; // Args to pass to `parity` command - return [argv, parityArgv]; -}; +module.exports = cli; diff --git a/electron/index.js b/electron/index.js index d559aa30..70af3c49 100644 --- a/electron/index.js +++ b/electron/index.js @@ -18,16 +18,7 @@ const { runParity, killParity } = require('./operations/runParity'); const { app, BrowserWindow, ipcMain, session } = electron; let mainWindow; -// Get arguments from cli -const [argv] = cli(); - -function createWindow () { - // If cli() returns false, then it means that the arguments are stopping the - // app (e.g. --help or --version). We don't do anything more in this case. - if (!argv) { - return; - } - +function createWindow() { mainWindow = new BrowserWindow({ height: 800, width: 1200 @@ -38,7 +29,7 @@ function createWindow () { .then(() => runParity(mainWindow)) .catch(handleError); // Errors should be handled before, this is really just in case - if (argv['ui-dev'] === true) { + if (cli.uiDev === true) { // Opens http://127.0.0.1:3000 in --ui-dev mode mainWindow.loadURL('http://127.0.0.1:3000'); mainWindow.webContents.openDevTools(); diff --git a/electron/operations/runParity.js b/electron/operations/runParity.js index 8e076749..a6c0272b 100644 --- a/electron/operations/runParity.js +++ b/electron/operations/runParity.js @@ -12,7 +12,6 @@ const cli = require('../cli'); const handleError = require('./handleError'); const parityPath = require('../utils/parityPath'); -const [, parityArgv] = cli(); const fsExists = util.promisify(fs.stat); const fsReadFile = util.promisify(fs.readFile); const fsUnlink = util.promisify(fs.unlink); @@ -20,15 +19,18 @@ const fsUnlink = util.promisify(fs.unlink); let parity = null; // Will hold the running parity instance module.exports = { - runParity (mainWindow) { + runParity(mainWindow) { // Create a logStream to save logs const logFile = `${parityPath()}.log`; + console.log(cli); + fsExists(logFile) .then(() => fsUnlink(logFile)) .catch(() => {}) .then(() => { - var logStream = fs.createWriteStream(logFile, { flags: 'a' }); + const logStream = fs.createWriteStream(logFile, { flags: 'a' }); + const parityArgv = []; // Run an instance of parity if we receive the `run-parity` message parity = spawn( @@ -43,7 +45,7 @@ module.exports = { parity.stdout.pipe(logStream); parity.stderr.pipe(logStream); parity.on('error', err => { - throw new Error(err); + handleError(err, 'An error occured while running parity.'); }); parity.on('close', (exitCode, signal) => { if (exitCode === 0) { @@ -58,7 +60,10 @@ module.exports = { console.log(data.toString()) ); } else { - throw new Error(`Exit code ${exitCode}, with signal ${signal}.`); + handleError( + new Error(`Exit code ${exitCode}, with signal ${signal}.`), + 'An error occured while running parity.' + ); } }); }) @@ -71,7 +76,7 @@ module.exports = { handleError(err, 'An error occured while running parity.'); }); }, - killParity () { + killParity() { if (parity) { console.log('Stopping parity.'); parity.kill(); diff --git a/package.json b/package.json index 71d545db..8391b1bc 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "@parity/api": "^2.1.22", "@parity/light.js": "https://github.com/parity-js/light.js#c531c68b5268a1bf7aba1f43424f440b2bde7828", "axios": "^0.18.0", + "commander": "^2.15.1", "electron": "^2.0.0", "electron-dl": "^1.11.0", "is-electron": "^2.1.0", @@ -55,8 +56,7 @@ "react-dom": "^16.3.2", "react-router-dom": "^4.2.2", "react-scripts": "1.1.4", - "rxjs": "^6.1.0", - "yargs": "^11.0.0" + "rxjs": "^6.1.0" }, "devDependencies": { "babel-eslint": "^8.2.3", diff --git a/yarn.lock b/yarn.lock index 1c2a7152..c3d682be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2018,7 +2018,7 @@ combined-stream@1.0.6, combined-stream@^1.0.5, combined-stream@~1.0.5: dependencies: delayed-stream "~1.0.0" -commander@2.15.x, commander@^2.11.0, commander@^2.9.0, commander@~2.15.0: +commander@2.15.x, commander@^2.11.0, commander@^2.15.1, commander@^2.9.0, commander@~2.15.0: version "2.15.1" resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" @@ -9487,23 +9487,6 @@ yargs-parser@^9.0.2: dependencies: camelcase "^4.1.0" -yargs@^11.0.0: - version "11.0.0" - resolved "https://registry.yarnpkg.com/yargs/-/yargs-11.0.0.tgz#c052931006c5eee74610e5fc0354bedfd08a201b" - dependencies: - cliui "^4.0.0" - decamelize "^1.1.1" - find-up "^2.1.0" - get-caller-file "^1.0.1" - os-locale "^2.0.0" - require-directory "^2.1.1" - require-main-filename "^1.0.1" - set-blocking "^2.0.0" - string-width "^2.0.0" - which-module "^2.0.0" - y18n "^3.2.1" - yargs-parser "^9.0.2" - yargs@^11.1.0: version "11.1.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-11.1.0.tgz#90b869934ed6e871115ea2ff58b03f4724ed2d77" -- GitLab From ea6986d9225dedc3d0f091147160944d245734a3 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 15 May 2018 09:33:35 +0200 Subject: [PATCH 2/9] Find out parityArgv --- electron/cli/index.js | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/electron/cli/index.js b/electron/cli/index.js index 84198702..c3b38586 100644 --- a/electron/cli/index.js +++ b/electron/cli/index.js @@ -21,6 +21,44 @@ cli ) .parse(process.argv); -let parityArgv = null; // Args to pass to `parity` command +/** + * Camel-case the given `flag` + * + * @param {String} flag + * @return {String} + * @see https://github.com/tj/commander.js/blob/dcddf698c5463795401ad3d6382f5ec5ec060478/index.js#L1160-L1172 + */ +const camelcase = flag => + flag + .split('-') + .reduce((str, word) => str + word[0].toUpperCase() + word.slice(1)); -module.exports = cli; +// Now we must think which arguments passed to cli must be passed down to +// parity. +const parityArgv = cli.rawArgs + .splice(cli.rawArgs.findIndex(item => item.startsWith('--'))) // Remove all arguments until one --option + .filter((item, index, array) => { + const key = camelcase(item.substring(2)); // Remove first 2 '--' and then camelCase + + if (key in cli) { + // If the option is consumed by commander.js, then we skip it + return false; + } + + // If it's not consumed by commander.js, and starts with '--', then we keep + // it. This step is optional, used for optimization only. + if (item.startsWith('--')) { + return true; + } + + const previousKey = camelcase(array[index - 1].substring(2)); + if (cli[previousKey] === item) { + // If it's an argument of an option consumed by commander.js, then we + // skip it too + return false; + } + + return true; + }); + +module.exports = { cli, parityArgv }; -- GitLab From 30737e608d03838dccf6af11716def05c7128e3e Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 15 May 2018 10:02:09 +0200 Subject: [PATCH 3/9] Fix bug runParity when other instance is running --- electron/cli/index.js | 5 --- electron/index.js | 2 +- electron/operations/runParity.js | 58 +++++++++++++++++++------------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/electron/cli/index.js b/electron/cli/index.js index c3b38586..fefb58b9 100644 --- a/electron/cli/index.js +++ b/electron/cli/index.js @@ -3,13 +3,8 @@ // // SPDX-License-Identifier: MIT -const { app } = require('electron'); const cli = require('commander'); -const fs = require('fs'); -const omit = require('lodash/omit'); -const { spawn } = require('child_process'); -const parityPath = require('../utils/parityPath'); const { version } = require('../../package.json'); cli diff --git a/electron/index.js b/electron/index.js index 70af3c49..c35eb361 100644 --- a/electron/index.js +++ b/electron/index.js @@ -18,7 +18,7 @@ const { runParity, killParity } = require('./operations/runParity'); const { app, BrowserWindow, ipcMain, session } = electron; let mainWindow; -function createWindow() { +function createWindow () { mainWindow = new BrowserWindow({ height: 800, width: 1200 diff --git a/electron/operations/runParity.js b/electron/operations/runParity.js index a6c0272b..014a31b9 100644 --- a/electron/operations/runParity.js +++ b/electron/operations/runParity.js @@ -3,47 +3,44 @@ // // SPDX-License-Identifier: MIT -const flatten = require('lodash/flatten'); +const { app } = require('electron'); const fs = require('fs'); +const noop = require('lodash/noop'); const { spawn } = require('child_process'); const util = require('util'); -const cli = require('../cli'); +const { parityArgv } = require('../cli'); const handleError = require('./handleError'); const parityPath = require('../utils/parityPath'); const fsExists = util.promisify(fs.stat); -const fsReadFile = util.promisify(fs.readFile); const fsUnlink = util.promisify(fs.unlink); let parity = null; // Will hold the running parity instance module.exports = { - runParity(mainWindow) { + runParity (mainWindow) { // Create a logStream to save logs const logFile = `${parityPath()}.log`; - console.log(cli); - fsExists(logFile) - .then(() => fsUnlink(logFile)) - .catch(() => {}) + .then(() => fsUnlink(logFile)) // Delete logFile and create a fresh one on each launch + .catch(noop) .then(() => { const logStream = fs.createWriteStream(logFile, { flags: 'a' }); - const parityArgv = []; + let logLastLine; // Always contains last line of the logFile - // Run an instance of parity if we receive the `run-parity` message - parity = spawn( - parityPath(), - flatten( - Object.keys(parityArgv).map(key => [`--${key}`, parityArgv[key]]) // Transform {arg: value} into [--arg, value] - ) - .concat('--light') - .filter(value => value !== true) // --arg true is equivalent to --arg - ); + // Run an instance of parity with the correct args + parity = spawn(parityPath(), parityArgv.concat('--light')); + // Pipe all parity command output into the logFile parity.stdout.pipe(logStream); parity.stderr.pipe(logStream); + // Save in memory the last line of the log file, for handling error + const callback = data => (logLastLine = data.toString()); + parity.stdout.on('data', callback); + parity.stderr.on('data', callback); + parity.on('error', err => { handleError(err, 'An error occured while running parity.'); }); @@ -52,13 +49,28 @@ module.exports = { return; } + // When there's already an instance of parity running, then the log + // is logging a particular line, see below. In this case, we just + // silently ignore our local instance, and let the 1st parity + // instance be the main one. + if ( + logLastLine.includes( + 'is already in use, make sure that another instance of an Ethereum client is not running or change the address using the --ws-port and --ws-interface options.' + ) + ) { + console.log( + 'Another instance of parity is running, closing local instance.' + ); + return; + } + // If the exit code is not 0, then we show some error message - if (Object.keys(parityArgv).length) { + if (Object.keys(parityArgv).length > 1) { // If parity has been launched with some args, then most likely the // args are wrong, so we show the output of parity. - return fsReadFile(logFile).then(data => - console.log(data.toString()) - ); + const log = fs.readFileSync(logFile); + console.log(log.toString()); + app.exit(1); } else { handleError( new Error(`Exit code ${exitCode}, with signal ${signal}.`), @@ -76,7 +88,7 @@ module.exports = { handleError(err, 'An error occured while running parity.'); }); }, - killParity() { + killParity () { if (parity) { console.log('Stopping parity.'); parity.kill(); -- GitLab From edff79277051625dc35929158d65069d15d3a97d Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 15 May 2018 10:27:04 +0200 Subject: [PATCH 4/9] Make parity a+x just before run (to be sure) --- electron/operations/runParity.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/electron/operations/runParity.js b/electron/operations/runParity.js index 014a31b9..02b07ef6 100644 --- a/electron/operations/runParity.js +++ b/electron/operations/runParity.js @@ -13,6 +13,7 @@ const { parityArgv } = require('../cli'); const handleError = require('./handleError'); const parityPath = require('../utils/parityPath'); +const fsChmod = util.promisify(fs.chmod); const fsExists = util.promisify(fs.stat); const fsUnlink = util.promisify(fs.unlink); @@ -26,6 +27,7 @@ module.exports = { fsExists(logFile) .then(() => fsUnlink(logFile)) // Delete logFile and create a fresh one on each launch .catch(noop) + .then(() => fsChmod(parityPath(), '755')) // Should already be 755 after download, just to be sure .then(() => { const logStream = fs.createWriteStream(logFile, { flags: 'a' }); let logLastLine; // Always contains last line of the logFile -- GitLab From f3ffaa9152fca0283c0788c67c35d88c02c23479 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 15 May 2018 16:06:06 +0200 Subject: [PATCH 5/9] Add some options on cli --- electron/cli/index.js | 14 +++++++++++++- electron/operations/runParity.js | 27 ++++++++++++++++++++------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/electron/cli/index.js b/electron/cli/index.js index fefb58b9..b9cad13f 100644 --- a/electron/cli/index.js +++ b/electron/cli/index.js @@ -10,10 +10,22 @@ const { version } = require('../../package.json'); cli .version(version) .allowUnknownOption() + .option( + '--no-run-parity', + 'Parity UI will not attempt to run the locally installed parity.' + ) .option( '--ui-dev', 'The Light Wallet will load http://localhost:3000. WARNING: Only use this is you plan on developing on Parity UI.' ) + .option( + '--ws-interface', + "Specify the hostname portion of the WebSockets server Parity UI will connect to. IP should be an interface's IP address. (default: 127.0.0.1)" + ) + .option( + '--ws-port', + 'Specify the port portion of the WebSockets server Parity UI will connect to. (default: 8546)' + ) .parse(process.argv); /** @@ -33,7 +45,7 @@ const camelcase = flag => const parityArgv = cli.rawArgs .splice(cli.rawArgs.findIndex(item => item.startsWith('--'))) // Remove all arguments until one --option .filter((item, index, array) => { - const key = camelcase(item.substring(2)); // Remove first 2 '--' and then camelCase + const key = camelcase(item.replace('--', '').replace('no-', '')); // Remove first 2 '--' and then camelCase if (key in cli) { // If the option is consumed by commander.js, then we skip it diff --git a/electron/operations/runParity.js b/electron/operations/runParity.js index 02b07ef6..73bfde2a 100644 --- a/electron/operations/runParity.js +++ b/electron/operations/runParity.js @@ -9,7 +9,7 @@ const noop = require('lodash/noop'); const { spawn } = require('child_process'); const util = require('util'); -const { parityArgv } = require('../cli'); +const { cli, parityArgv } = require('../cli'); const handleError = require('./handleError'); const parityPath = require('../utils/parityPath'); @@ -19,8 +19,21 @@ const fsUnlink = util.promisify(fs.unlink); let parity = null; // Will hold the running parity instance +// These are errors output by parity, which Parity UI ignores (i.e. doesn't +// panic). They happen when an instance of parity is already running, and +// parity-ui tries to launch another one. +const catchableErrors = [ + 'is already in use, make sure that another instance of an Ethereum client is not running or change the address using the --ws-port and --ws-interface options.', + 'Error(Msg("IO error: While lock file:' +]; + module.exports = { runParity (mainWindow) { + // Do not run parity with --no-run-parity + if (cli.runParity === false) { + return; + } + // Create a logStream to save logs const logFile = `${parityPath()}.log`; @@ -39,7 +52,11 @@ module.exports = { parity.stdout.pipe(logStream); parity.stderr.pipe(logStream); // Save in memory the last line of the log file, for handling error - const callback = data => (logLastLine = data.toString()); + const callback = data => { + if (data && data.length) { + logLastLine = data.toString(); + } + }; parity.stdout.on('data', callback); parity.stderr.on('data', callback); @@ -55,11 +72,7 @@ module.exports = { // is logging a particular line, see below. In this case, we just // silently ignore our local instance, and let the 1st parity // instance be the main one. - if ( - logLastLine.includes( - 'is already in use, make sure that another instance of an Ethereum client is not running or change the address using the --ws-port and --ws-interface options.' - ) - ) { + if (catchableErrors.some(error => logLastLine.includes(error))) { console.log( 'Another instance of parity is running, closing local instance.' ); -- GitLab From 0e8a5b9f850bb28d243b96a25615b45ed6c4d9b9 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 15 May 2018 16:26:01 +0200 Subject: [PATCH 6/9] Fix bug no options --- electron/cli/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/electron/cli/index.js b/electron/cli/index.js index b9cad13f..68f564ac 100644 --- a/electron/cli/index.js +++ b/electron/cli/index.js @@ -43,7 +43,7 @@ const camelcase = flag => // Now we must think which arguments passed to cli must be passed down to // parity. const parityArgv = cli.rawArgs - .splice(cli.rawArgs.findIndex(item => item.startsWith('--'))) // Remove all arguments until one --option + .splice(Math.max(cli.rawArgs.findIndex(item => item.startsWith('--'))), 0) // Remove all arguments until one --option .filter((item, index, array) => { const key = camelcase(item.replace('--', '').replace('no-', '')); // Remove first 2 '--' and then camelCase @@ -58,7 +58,9 @@ const parityArgv = cli.rawArgs return true; } - const previousKey = camelcase(array[index - 1].substring(2)); + const previousKey = camelcase( + array[index - 1].replace('--', '').replace('no-', '') + ); if (cli[previousKey] === item) { // If it's an argument of an option consumed by commander.js, then we // skip it too -- GitLab From 108aed07d88f18aa6cb6201e128ca23aa9b6ab87 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 15 May 2018 17:26:26 +0200 Subject: [PATCH 7/9] Fix bug bundled app --- electron/cli/index.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/electron/cli/index.js b/electron/cli/index.js index 68f564ac..fb5e5dd7 100644 --- a/electron/cli/index.js +++ b/electron/cli/index.js @@ -5,26 +5,38 @@ const cli = require('commander'); +const { productName } = require('../config.json'); const { version } = require('../../package.json'); +/** + * Process.argv arguments length is different in electron mode and in packaged + * mode. This small line is to harmonize the behavior for consistent parsing. + * + * @see https://github.com/tj/commander.js/issues/512 + * @see https://github.com/electron/electron/issues/4690#issuecomment-217435222 + */ +if (process.defaultApp !== true) { + process.argv.unshift(null); +} + cli .version(version) .allowUnknownOption() .option( '--no-run-parity', - 'Parity UI will not attempt to run the locally installed parity.' + `${productName} will not attempt to run the locally installed parity.` ) .option( '--ui-dev', - 'The Light Wallet will load http://localhost:3000. WARNING: Only use this is you plan on developing on Parity UI.' + `${productName} will load http://localhost:3000. WARNING: Only use this is you plan on developing on ${productName}.` ) .option( '--ws-interface', - "Specify the hostname portion of the WebSockets server Parity UI will connect to. IP should be an interface's IP address. (default: 127.0.0.1)" + `Specify the hostname portion of the WebSockets server ${productName} will connect to. IP should be an interface's IP address. (default: 127.0.0.1)` ) .option( '--ws-port', - 'Specify the port portion of the WebSockets server Parity UI will connect to. (default: 8546)' + `Specify the port portion of the WebSockets server ${productName} will connect to. (default: 8546)` ) .parse(process.argv); -- GitLab From 98ef3ac2e257912a15e8741cc19e1d7ba441426a Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 15 May 2018 17:45:56 +0200 Subject: [PATCH 8/9] Fix small bugs --- electron/cli/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/electron/cli/index.js b/electron/cli/index.js index fb5e5dd7..ebfcecdd 100644 --- a/electron/cli/index.js +++ b/electron/cli/index.js @@ -16,7 +16,7 @@ const { version } = require('../../package.json'); * @see https://github.com/electron/electron/issues/4690#issuecomment-217435222 */ if (process.defaultApp !== true) { - process.argv.unshift(null); + process.argv.unshift(''); } cli @@ -31,11 +31,11 @@ cli `${productName} will load http://localhost:3000. WARNING: Only use this is you plan on developing on ${productName}.` ) .option( - '--ws-interface', + '--ws-interface ', `Specify the hostname portion of the WebSockets server ${productName} will connect to. IP should be an interface's IP address. (default: 127.0.0.1)` ) .option( - '--ws-port', + '--ws-port ', `Specify the port portion of the WebSockets server ${productName} will connect to. (default: 8546)` ) .parse(process.argv); -- GitLab From 655238bc0e52b6c04a47adcca31c8fed21fb54cd Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 16 May 2018 10:11:28 +0200 Subject: [PATCH 9/9] Small tweaks --- electron/cli/index.js | 2 +- electron/operations/runParity.js | 5 +++-- package.json | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/electron/cli/index.js b/electron/cli/index.js index ebfcecdd..498a5a39 100644 --- a/electron/cli/index.js +++ b/electron/cli/index.js @@ -55,7 +55,7 @@ const camelcase = flag => // Now we must think which arguments passed to cli must be passed down to // parity. const parityArgv = cli.rawArgs - .splice(Math.max(cli.rawArgs.findIndex(item => item.startsWith('--'))), 0) // Remove all arguments until one --option + .splice(Math.max(cli.rawArgs.findIndex(item => item.startsWith('--')), 0)) // Remove all arguments until one --option .filter((item, index, array) => { const key = camelcase(item.replace('--', '').replace('no-', '')); // Remove first 2 '--' and then camelCase diff --git a/electron/operations/runParity.js b/electron/operations/runParity.js index 73bfde2a..ff6796c4 100644 --- a/electron/operations/runParity.js +++ b/electron/operations/runParity.js @@ -46,11 +46,12 @@ module.exports = { let logLastLine; // Always contains last line of the logFile // Run an instance of parity with the correct args - parity = spawn(parityPath(), parityArgv.concat('--light')); + parity = spawn(parityPath(), parityArgv); // Pipe all parity command output into the logFile parity.stdout.pipe(logStream); parity.stderr.pipe(logStream); + // Save in memory the last line of the log file, for handling error const callback = data => { if (data && data.length) { @@ -80,7 +81,7 @@ module.exports = { } // If the exit code is not 0, then we show some error message - if (Object.keys(parityArgv).length > 1) { + if (Object.keys(parityArgv).length > 0) { // If parity has been launched with some args, then most likely the // args are wrong, so we show the output of parity. const log = fs.readFileSync(logFile); diff --git a/package.json b/package.json index 8391b1bc..f96d9dd7 100644 --- a/package.json +++ b/package.json @@ -31,11 +31,11 @@ "build-css": "node-sass-chokidar src/ -o src/", "build-electron": "webpack --config electron/webpack.config.js", "build-js": "react-app-rewired build", - "electron": "npm run build && electron build/electron.js", + "electron": "npm run build && electron build/electron.js --light", "lint": "semistandard 'src/**/*.js' 'electron/**/*.js' --parser babel-eslint", "prebuild": "rimraf build/", "start": "npm-run-all -p watch-css start-js", - "start-electron": "electron electron/ --ui-dev --ws-origins all", + "start-electron": "electron electron/ --ui-dev --light --ws-origins all", "start-js": "react-app-rewired start", "test": "echo Skipped.", "watch-css": "npm run build-css -- --watch --recursive" -- GitLab