From 40a3fe2fce59ccb320b1591cc5d0e3eff75174aa Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Tue, 17 Jul 2018 19:04:01 +0200 Subject: [PATCH 1/9] [WIP] Refactor CLI --- .../src/main/getRemainingArgs.js | 23 +++++++ packages/fether-electron/src/main/index.js | 25 ++++--- packages/parity-electron/README.md | 14 ++-- packages/parity-electron/src/index.ts | 9 +-- .../parity-electron/src/isParityRunning.ts | 27 ++++---- packages/parity-electron/src/runParity.ts | 33 +++++----- packages/parity-electron/src/types.d.ts | 6 -- packages/parity-electron/src/utils/cli.ts | 65 ------------------- 8 files changed, 78 insertions(+), 124 deletions(-) create mode 100644 packages/fether-electron/src/main/getRemainingArgs.js delete mode 100644 packages/parity-electron/src/utils/cli.ts diff --git a/packages/fether-electron/src/main/getRemainingArgs.js b/packages/fether-electron/src/main/getRemainingArgs.js new file mode 100644 index 00000000..0840a9ba --- /dev/null +++ b/packages/fether-electron/src/main/getRemainingArgs.js @@ -0,0 +1,23 @@ +const { Option } = require('commander'); + +export default cli => + cli.rawArgs + .splice(Math.max(cli.rawArgs.findIndex(item => item.startsWith('-')), 0)) // Remove all arguments until one --option + .filter((rawArg, index, rawArgs) => { + // If the option is consumed by commander.js, then we skip it + if (cli.options.find(o => o.is(rawArg))) { + return false; + } + + // If it's an argument of an option consumed by commander.js, then we + // skip it too + const previousRawArg = rawArgs[index - 1]; + if (previousRawArg) { + const previousKey = new Option(previousRawArg).attributeName(); + if (cli[previousKey] === rawArg) { + return false; + } + } + + return true; + }); diff --git a/packages/fether-electron/src/main/index.js b/packages/fether-electron/src/main/index.js index 10d54619..b3d38d38 100644 --- a/packages/fether-electron/src/main/index.js +++ b/packages/fether-electron/src/main/index.js @@ -22,6 +22,9 @@ import Pino from './utils/pino'; import { productName } from '../../electron-builder.json'; import staticPath from './utils/staticPath'; +// @TODO TEMP, will be made a separate module +import getRemainingArgs from './getRemainingArgs'; + const { app, BrowserWindow, ipcMain, session } = electron; let mainWindow; const pino = Pino(); @@ -42,7 +45,6 @@ function createWindow () { // Set options for @parity/electron parityElectron({ - cli, logger: namespace => log => Pino({ name: namespace }).info(log) }); @@ -59,9 +61,14 @@ function createWindow () { ) .then(() => // Run parity when installed - runParity(['--light', '--chain', cli.chain || 'kovan'], err => - handleError(err, 'An error occured with Parity.') - ) + cli.runParity && // only if the user hasn't set the flag --no-run-parity + runParity({ + wsInterface: cli.wsInterface, + wsPort: cli.wsPort, + flags: [...getRemainingArgs(cli), '--light', '--chain', cli.chain || 'kovan'], + onParityError: err => + handleError(err, 'An error occured with Parity.') + }) ) .then(() => { // Notify the renderers @@ -74,11 +81,11 @@ function createWindow () { // passed to ELECTRON_START_URL mainWindow.loadURL( process.env.ELECTRON_START_URL || - url.format({ - pathname: path.join(staticPath, 'build', 'index.html'), - protocol: 'file:', - slashes: true - }) + url.format({ + pathname: path.join(staticPath, 'build', 'index.html'), + protocol: 'file:', + slashes: true + }) ); // Listen to messages from renderer process diff --git a/packages/parity-electron/README.md b/packages/parity-electron/README.md index 48f15512..337e9f62 100644 --- a/packages/parity-electron/README.md +++ b/packages/parity-electron/README.md @@ -15,7 +15,6 @@ import parityElectron, { isParityRunning } from '@parity/electron'; // Optional: override default options parityElectron({ - cli: myOwnCliObject, logger: myCustomLoggerFunction }) @@ -31,7 +30,6 @@ If you don't want to override the default options, there's no need to call this | Option | Default Value | Description | | ---------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `options.cli` | `{}` | An object where key/values are --flags passed to the binary. The `cli` object returned by `yargs` or [`commander.js`](https://github.com/tj/commander.js/) would fit here. | | `options.logger` | `require('debug')` | A function with the same signature as [`debug`](https://github.com/visionmedia/debug). All logs inside `@parity/electron` will then be logged by this function. | #### `fetchParity(mainWindow: BrowserWindow, options: Object): Promise` @@ -56,14 +54,16 @@ Returns the path to the Parity path inside Electron's `userData` folder, even if Resolves to `true` if Parity is currently running, or to `false` if not. -#### `runParity(additionalFlags: Array, onParityError: Function): Promise` +#### `runParity(options: Object): Promise` Spawns a child process to run Parity. If some `cli` flags are passed into the options in `parityElectron`, then those flags will be passed down to Parity itself. -| Option | Type | Description | -| ----------------- | --------------- | --------------------------------------------------------------------------------------------- | -| `additionalFlasg` | `Array` | Addtional flags to pass to Parity, listed as an array, to be passed to `child_process.spawn`. | -| `onParityError` | `Function` | Callback with `error` as argument when Parity encounters an error. | +| Option | Type | Description | +| ------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------ | +| `options.flags` | `Array` | Additional flags to pass to Parity, listed as an array, to be passed to `child_process.spawn`. | +| `options.wsInterface` | `String` | Hostname portion of the WebSockets server Fether will connect to. It should be an interface's IP address. (default: 127.0.0.1) | +| `options.wsPort` | `String` | Port portion of the WebSockets server Fether will connect to. (default: 8546) | +| `options.onParityError` | `Function` | Callback with `error` as argument when Parity encounters an error. | #### `killParity(): Promise` diff --git a/packages/parity-electron/src/index.ts b/packages/parity-electron/src/index.ts index a7852aff..9449c3a6 100644 --- a/packages/parity-electron/src/index.ts +++ b/packages/parity-electron/src/index.ts @@ -3,8 +3,7 @@ // // SPDX-License-Identifier: BSD-3-Clause -import { CliObject, LoggerFunction } from './types'; -import { setCli } from './utils/cli'; +import { LoggerFunction } from './types'; import { setLogger } from './utils/logger'; export * from './checkClockSync'; @@ -17,11 +16,7 @@ export * from './signerNewToken'; /** * Set default options for @parity/electron. */ -export default (opts: { cli: CliObject; logger: LoggerFunction }) => { - if (opts.cli) { - setCli(opts.cli); - } - +export default (opts: { logger: LoggerFunction }) => { if (opts.logger) { setLogger(opts.logger); } diff --git a/packages/parity-electron/src/isParityRunning.ts b/packages/parity-electron/src/isParityRunning.ts index c2f86743..0dbd8ad8 100644 --- a/packages/parity-electron/src/isParityRunning.ts +++ b/packages/parity-electron/src/isParityRunning.ts @@ -6,25 +6,26 @@ import axios from 'axios'; import * as retry from 'async-retry'; -import { cli } from './utils/cli'; import logger from './utils/logger'; -/** - * Try to ping these hosts to test if Parity is running. - */ -const hostsToPing = ['http://127.0.0.1:8545', 'http://127.0.0.1:8546']; -if (cli.wsInterface || cli.wsPort) { - // Also try custom host/port if a --ws-interface or --ws-port flag is passed - hostsToPing.push( - `http://${cli.wsInterface || '127.0.0.1'}:${cli.wsPort || '8546'}` - ); -} - /** * Detect if another instance of parity is already running or not. To achieve * that, we just ping on the common hosts, see {@link hostsToPing} array. */ -export const isParityRunning = async () => { +export const isParityRunning = async ({ + wsInterface = '127.0.0.1', + wsPort = '8546' +}: { + wsInterface: string; + wsPort: string; + }) => { + /** + * Try to ping these hosts to test if Parity is running. + */ + const hostsToPing = [ + `http://${wsInterface}:${wsPort}` + ]; + try { // Retry to ping as many times as there are hosts in `hostsToPing` await retry( diff --git a/packages/parity-electron/src/runParity.ts b/packages/parity-electron/src/runParity.ts index 159bc1ce..11175cf8 100644 --- a/packages/parity-electron/src/runParity.ts +++ b/packages/parity-electron/src/runParity.ts @@ -7,7 +7,6 @@ import { chmod } from 'fs'; import { spawn } from 'child_process'; import { promisify } from 'util'; -import { cli, parityArgv } from './utils/cli'; import { getParityPath } from './getParityPath'; import { isParityRunning } from './isParityRunning'; import logCommand from './utils/logCommand'; @@ -26,21 +25,21 @@ const catchableErrors = [ ]; /** - * Spawns a child process to run Parity. If some cli flags are passed into the - * options in parityElectron, then those flags will be passed down to Parity - * itself. + * Spawns a child process to run Parity. */ -export const runParity = async ( - additionalFlags: string[], - onParityError: (error: Error) => void = () => {} -) => { - // Do not run parity with --no-run-parity - if (cli.runParity === false) { - return; - } - +export const runParity = async ({ + wsInterface = '127.0.0.1', + wsPort = '8546', + flags = [], + onParityError = () => { } +}: { + wsInterface: string; + wsPort: string; + flags: string[]; + onParityError: (error: Error) => void + }) => { // Do not run parity if there is already another instance running - const isRunning = await isParityRunning(); + const isRunning = await isParityRunning({ wsInterface, wsPort }); if (isRunning) { return; } @@ -52,12 +51,12 @@ export const runParity = async ( // have rights to do it). try { await fsChmod(parityPath, '755'); - } catch (e) {} + } catch (e) { } let logLastLine = ''; // Always contains last line of the Parity logs - // Run an instance of parity with the correct args - const args = [...parityArgv(), ...additionalFlags]; + // Run an instance of parity with the correct flags + const args = ['--ws-interface', wsInterface, '--ws-port', wsPort, ...flags]; parity = spawn(parityPath, args); logger()('@parity/electron:main')(logCommand(parityPath, args)); diff --git a/packages/parity-electron/src/types.d.ts b/packages/parity-electron/src/types.d.ts index 4efe9a06..3979f330 100644 --- a/packages/parity-electron/src/types.d.ts +++ b/packages/parity-electron/src/types.d.ts @@ -3,14 +3,8 @@ // // SPDX-License-Identifier: BSD-3-Clause -export type CliObject = { - rawArgs?: string[]; - [key: string]: string | boolean | string[]; -}; - export type LoggerFunction = (namespace: string) => (log: string) => void; export type Options = { - cli: CliObject; logger: LoggerFunction; }; diff --git a/packages/parity-electron/src/utils/cli.ts b/packages/parity-electron/src/utils/cli.ts deleted file mode 100644 index 1f61f8f2..00000000 --- a/packages/parity-electron/src/utils/cli.ts +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. -// -// SPDX-License-Identifier: BSD-3-Clause - -import { CliObject } from '../types'; - -let cli: CliObject = {}; - -/** - * Set custom cli options. - * - * @param {*} cliOptions - */ -export const setCli = (cliObject: CliObject) => { - cli = cliObject; -}; - -/** - * Camel-case the given `flag` - * - * @see https://github.com/tj/commander.js/blob/dcddf698c5463795401ad3d6382f5ec5ec060478/index.js#L1160-L1172 - */ -const camelcase = (flag: string) => - flag - .split('-') - .reduce((str, word) => str + word[0].toUpperCase() + word.slice(1)); - -// Now we must think which arguments passed to cli must be passed down to -// parity. -export const parityArgv = () => - cli.rawArgs - .splice(2) // Remove first 2 arguments which are program path - .filter((item, index, array) => { - const key = camelcase(item.replace('--', '').replace('no-', '')); // Remove '--' and then camelCase - - if (key in cli) { - // If the option is consumed by commander.js, then we don't pass down to parity - return false; - } - - // If it's not consumed by commander.js, and starts with '--', then we keep - // it. - if (item.startsWith('--')) { - return true; - } - - // If it's the 1st argument and did not start with --, then we skip it - if (index === 0) { - return false; - } - - 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 - return false; - } - - return true; - }); - -export { cli }; -- GitLab From bd394dc9082ff80c5a4d6a84bf0f58f5ed277688 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Wed, 18 Jul 2018 18:17:55 +0200 Subject: [PATCH 2/9] Grumbles --- packages/fether-electron/src/main/index.js | 31 ++++++++++++++----- packages/parity-electron/README.md | 11 ++++--- packages/parity-electron/src/index.ts | 2 +- .../parity-electron/src/isParityRunning.ts | 4 ++- packages/parity-electron/src/runParity.ts | 16 ++-------- packages/parity-electron/src/types.d.ts | 4 --- 6 files changed, 37 insertions(+), 31 deletions(-) diff --git a/packages/fether-electron/src/main/index.js b/packages/fether-electron/src/main/index.js index b3d38d38..f28e2fb6 100644 --- a/packages/fether-electron/src/main/index.js +++ b/packages/fether-electron/src/main/index.js @@ -6,6 +6,7 @@ import parityElectron, { getParityPath, fetchParity, + isParityRunning, runParity, killParity } from '@parity/electron'; @@ -59,17 +60,33 @@ function createWindow () { parityChannel: parity.channel }) ) - .then(() => + .then(async () => { // Run parity when installed - cli.runParity && // only if the user hasn't set the flag --no-run-parity - runParity({ + + // Don't run parity if the user ran fether with --no-run-parity + if (!cli.runParity) { + return; + } + + if (await isParityRunning({ wsInterface: cli.wsInterface, - wsPort: cli.wsPort, - flags: [...getRemainingArgs(cli), '--light', '--chain', cli.chain || 'kovan'], + wsPort: cli.wsPort + })) { + return; + } + + return runParity({ + flags: [ + ...getRemainingArgs(cli), + '--light', + '--chain', cli.chain || 'kovan', + '--ws-interface', cli.wsInterface, + '--ws-port', cli.wsPort + ], onParityError: err => handleError(err, 'An error occured with Parity.') - }) - ) + }); + }) .then(() => { // Notify the renderers mainWindow.webContents.send('parity-running', true); diff --git a/packages/parity-electron/README.md b/packages/parity-electron/README.md index 337e9f62..7eec0c66 100644 --- a/packages/parity-electron/README.md +++ b/packages/parity-electron/README.md @@ -50,19 +50,22 @@ Returns the path to Parity. It checks (in this order) if Parity is in `$PATH`, i Returns the path to the Parity path inside Electron's `userData` folder, even if that binary doesn't exist. It's the default download location for [`fetchParity`](#fetchParitymainWindow-BrowserWindow-options-Object-PromiseltStringgt0). -#### `isParityRunning(): Promise` +#### `isParityRunning(options: Object): Promise` + +| Option | Type | Description | +| ------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------- | +| `options.wsInterface` | `String` | Hostname portion of the WebSockets server Fether will try to connect to. It should be an interface's IP address. (default: 127.0.0.1) | +| `options.wsPort` | `Number | String` | Port portion of the WebSockets server Fether will try to connect to. (default: 8546) | Resolves to `true` if Parity is currently running, or to `false` if not. #### `runParity(options: Object): Promise` -Spawns a child process to run Parity. If some `cli` flags are passed into the options in `parityElectron`, then those flags will be passed down to Parity itself. +Spawns a child process to run Parity, with optional additional flags. | Option | Type | Description | | ------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------ | | `options.flags` | `Array` | Additional flags to pass to Parity, listed as an array, to be passed to `child_process.spawn`. | -| `options.wsInterface` | `String` | Hostname portion of the WebSockets server Fether will connect to. It should be an interface's IP address. (default: 127.0.0.1) | -| `options.wsPort` | `String` | Port portion of the WebSockets server Fether will connect to. (default: 8546) | | `options.onParityError` | `Function` | Callback with `error` as argument when Parity encounters an error. | #### `killParity(): Promise` diff --git a/packages/parity-electron/src/index.ts b/packages/parity-electron/src/index.ts index 9449c3a6..e50ef57e 100644 --- a/packages/parity-electron/src/index.ts +++ b/packages/parity-electron/src/index.ts @@ -16,7 +16,7 @@ export * from './signerNewToken'; /** * Set default options for @parity/electron. */ -export default (opts: { logger: LoggerFunction }) => { +export default (opts: { logger?: LoggerFunction }) => { if (opts.logger) { setLogger(opts.logger); } diff --git a/packages/parity-electron/src/isParityRunning.ts b/packages/parity-electron/src/isParityRunning.ts index 0dbd8ad8..2f9bbafb 100644 --- a/packages/parity-electron/src/isParityRunning.ts +++ b/packages/parity-electron/src/isParityRunning.ts @@ -17,12 +17,14 @@ export const isParityRunning = async ({ wsPort = '8546' }: { wsInterface: string; - wsPort: string; + wsPort: number | string; }) => { /** * Try to ping these hosts to test if Parity is running. */ const hostsToPing = [ + 'http://127.0.0.1:8545', + 'http://127.0.0.1:8546', `http://${wsInterface}:${wsPort}` ]; diff --git a/packages/parity-electron/src/runParity.ts b/packages/parity-electron/src/runParity.ts index 11175cf8..54844c57 100644 --- a/packages/parity-electron/src/runParity.ts +++ b/packages/parity-electron/src/runParity.ts @@ -8,7 +8,6 @@ import { spawn } from 'child_process'; import { promisify } from 'util'; import { getParityPath } from './getParityPath'; -import { isParityRunning } from './isParityRunning'; import logCommand from './utils/logCommand'; import logger from './utils/logger'; @@ -28,22 +27,12 @@ const catchableErrors = [ * Spawns a child process to run Parity. */ export const runParity = async ({ - wsInterface = '127.0.0.1', - wsPort = '8546', flags = [], onParityError = () => { } }: { - wsInterface: string; - wsPort: string; flags: string[]; onParityError: (error: Error) => void }) => { - // Do not run parity if there is already another instance running - const isRunning = await isParityRunning({ wsInterface, wsPort }); - if (isRunning) { - return; - } - const parityPath = await getParityPath(); // Some users somehow had no +x on the parity binary after downloading @@ -56,9 +45,8 @@ export const runParity = async ({ let logLastLine = ''; // Always contains last line of the Parity logs // Run an instance of parity with the correct flags - const args = ['--ws-interface', wsInterface, '--ws-port', wsPort, ...flags]; - parity = spawn(parityPath, args); - logger()('@parity/electron:main')(logCommand(parityPath, args)); + parity = spawn(parityPath, flags); + logger()('@parity/electron:main')(logCommand(parityPath, flags)); // Save in memory the last line of the log file, for handling error const callback = data => { diff --git a/packages/parity-electron/src/types.d.ts b/packages/parity-electron/src/types.d.ts index 3979f330..484e5d16 100644 --- a/packages/parity-electron/src/types.d.ts +++ b/packages/parity-electron/src/types.d.ts @@ -4,7 +4,3 @@ // SPDX-License-Identifier: BSD-3-Clause export type LoggerFunction = (namespace: string) => (log: string) => void; - -export type Options = { - logger: LoggerFunction; -}; -- GitLab From b2b908d7acfc1fe56a08bd914c479dd318abc4f7 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Thu, 19 Jul 2018 00:11:28 +0200 Subject: [PATCH 3/9] Move getRemainingArgs to a separate npm module --- packages/fether-electron/package.json | 3 ++- .../src/main/getRemainingArgs.js | 23 ------------------- packages/fether-electron/src/main/index.js | 4 +--- yarn.lock | 4 ++++ 4 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 packages/fether-electron/src/main/getRemainingArgs.js diff --git a/packages/fether-electron/package.json b/packages/fether-electron/package.json index 5b21a6c7..392ed320 100644 --- a/packages/fether-electron/package.json +++ b/packages/fether-electron/package.json @@ -41,6 +41,7 @@ "dependencies": { "@parity/electron": "^0.1.0", "commander": "^2.15.1", + "commander-remaining-args": "^1.0.0", "fether-react": "^0.1.0", "menubar": "^5.2.3", "pino": "^4.16.1", @@ -55,4 +56,4 @@ "electron-webpack": "^2.1.2", "webpack": "^4.7.0" } -} \ No newline at end of file +} diff --git a/packages/fether-electron/src/main/getRemainingArgs.js b/packages/fether-electron/src/main/getRemainingArgs.js deleted file mode 100644 index 0840a9ba..00000000 --- a/packages/fether-electron/src/main/getRemainingArgs.js +++ /dev/null @@ -1,23 +0,0 @@ -const { Option } = require('commander'); - -export default cli => - cli.rawArgs - .splice(Math.max(cli.rawArgs.findIndex(item => item.startsWith('-')), 0)) // Remove all arguments until one --option - .filter((rawArg, index, rawArgs) => { - // If the option is consumed by commander.js, then we skip it - if (cli.options.find(o => o.is(rawArg))) { - return false; - } - - // If it's an argument of an option consumed by commander.js, then we - // skip it too - const previousRawArg = rawArgs[index - 1]; - if (previousRawArg) { - const previousKey = new Option(previousRawArg).attributeName(); - if (cli[previousKey] === rawArg) { - return false; - } - } - - return true; - }); diff --git a/packages/fether-electron/src/main/index.js b/packages/fether-electron/src/main/index.js index f28e2fb6..b20a1eef 100644 --- a/packages/fether-electron/src/main/index.js +++ b/packages/fether-electron/src/main/index.js @@ -11,6 +11,7 @@ import parityElectron, { killParity } from '@parity/electron'; import electron from 'electron'; +import getRemainingArgs from 'commander-remaining-args'; import path from 'path'; import url from 'url'; @@ -23,9 +24,6 @@ import Pino from './utils/pino'; import { productName } from '../../electron-builder.json'; import staticPath from './utils/staticPath'; -// @TODO TEMP, will be made a separate module -import getRemainingArgs from './getRemainingArgs'; - const { app, BrowserWindow, ipcMain, session } = electron; let mainWindow; const pino = Pino(); diff --git a/yarn.lock b/yarn.lock index de316cfb..09e389df 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3244,6 +3244,10 @@ command-join@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/command-join/-/command-join-2.0.0.tgz#52e8b984f4872d952ff1bdc8b98397d27c7144cf" +commander-remaining-args@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/commander-remaining-args/-/commander-remaining-args-1.0.0.tgz#20bdf6af6de7f7065bb7ee4e42efe5cc0b70365a" + commander@2.15.x, commander@^2.11.0, commander@^2.15.1, commander@^2.8.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" -- GitLab From dbbf39b287b18dcc8b585e0d542171749bc35e8e Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Fri, 20 Jul 2018 14:27:23 +0200 Subject: [PATCH 4/9] Add default CLI values for --ws-interface and --ws-port --- packages/fether-electron/src/main/cli/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/fether-electron/src/main/cli/index.js b/packages/fether-electron/src/main/cli/index.js index 928f06c4..e35b2517 100644 --- a/packages/fether-electron/src/main/cli/index.js +++ b/packages/fether-electron/src/main/cli/index.js @@ -32,11 +32,13 @@ cli ) .option( '--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)` + `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)`, + '127.0.0.1' ) .option( '--ws-port ', - `Specify the port portion of the WebSockets server ${productName} will connect to. (default: 8546)` + `Specify the port portion of the WebSockets server ${productName} will connect to. (default: 8546)`, + 8546 ) .parse(process.argv); -- GitLab From c08c5689eebcca43e778b8a1f3ddb150c47f4856 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Fri, 20 Jul 2018 14:35:01 +0200 Subject: [PATCH 5/9] Fix CLI --chain missing --- packages/fether-electron/src/main/cli/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fether-electron/src/main/cli/index.js b/packages/fether-electron/src/main/cli/index.js index e35b2517..aae8d3d7 100644 --- a/packages/fether-electron/src/main/cli/index.js +++ b/packages/fether-electron/src/main/cli/index.js @@ -23,7 +23,7 @@ cli .version(version) .allowUnknownOption() .option( - '--chain', + '--chain ', 'The network to connect to, can be one of "foundation", "kovan" or "ropsten". (default: "kovan")' ) .option( -- GitLab From 5f6415e082809a3ef7f498919266ea8425b8c25e Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Fri, 20 Jul 2018 14:48:11 +0200 Subject: [PATCH 6/9] Fix promiseAny unhandled promise rejection --- packages/parity-electron/src/getParityPath.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/parity-electron/src/getParityPath.ts b/packages/parity-electron/src/getParityPath.ts index 6a21e227..59865c66 100644 --- a/packages/parity-electron/src/getParityPath.ts +++ b/packages/parity-electron/src/getParityPath.ts @@ -6,7 +6,7 @@ import { app } from 'electron'; import commandExists from 'command-exists'; import { stat } from 'fs'; -import promiseAny from 'promise-any'; +import * as promiseAny from 'promise-any'; import { promisify } from 'util'; import logger from './utils/logger'; -- GitLab From 5969d244586fa9fd481a70b015659aa19e807d7a Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Mon, 23 Jul 2018 15:33:18 +0200 Subject: [PATCH 7/9] Use `kovan` as default CLI value for --chain --- packages/fether-electron/src/main/cli/index.js | 3 ++- packages/fether-electron/src/main/index.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/fether-electron/src/main/cli/index.js b/packages/fether-electron/src/main/cli/index.js index aae8d3d7..75147b83 100644 --- a/packages/fether-electron/src/main/cli/index.js +++ b/packages/fether-electron/src/main/cli/index.js @@ -24,7 +24,8 @@ cli .allowUnknownOption() .option( '--chain ', - 'The network to connect to, can be one of "foundation", "kovan" or "ropsten". (default: "kovan")' + 'The network to connect to, can be one of "foundation", "kovan" or "ropsten". (default: "kovan")', + 'kovan' ) .option( '--no-run-parity', diff --git a/packages/fether-electron/src/main/index.js b/packages/fether-electron/src/main/index.js index b20a1eef..c9b8f0dc 100644 --- a/packages/fether-electron/src/main/index.js +++ b/packages/fether-electron/src/main/index.js @@ -77,7 +77,7 @@ function createWindow () { flags: [ ...getRemainingArgs(cli), '--light', - '--chain', cli.chain || 'kovan', + '--chain', cli.chain, '--ws-interface', cli.wsInterface, '--ws-port', cli.wsPort ], -- GitLab From 2cd1e34855cc131da6a00425c6beb2c3e24d068a Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Mon, 23 Jul 2018 17:43:41 +0200 Subject: [PATCH 8/9] Fix getRemainingArgs bug --- packages/fether-electron/package.json | 2 +- yarn.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/fether-electron/package.json b/packages/fether-electron/package.json index 392ed320..a659904e 100644 --- a/packages/fether-electron/package.json +++ b/packages/fether-electron/package.json @@ -41,7 +41,7 @@ "dependencies": { "@parity/electron": "^0.1.0", "commander": "^2.15.1", - "commander-remaining-args": "^1.0.0", + "commander-remaining-args": "^1.2.0", "fether-react": "^0.1.0", "menubar": "^5.2.3", "pino": "^4.16.1", diff --git a/yarn.lock b/yarn.lock index 09e389df..44abb8b5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3244,9 +3244,9 @@ command-join@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/command-join/-/command-join-2.0.0.tgz#52e8b984f4872d952ff1bdc8b98397d27c7144cf" -commander-remaining-args@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/commander-remaining-args/-/commander-remaining-args-1.0.0.tgz#20bdf6af6de7f7065bb7ee4e42efe5cc0b70365a" +commander-remaining-args@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/commander-remaining-args/-/commander-remaining-args-1.2.0.tgz#6fab4cce4a59db1698121f59105364adcb0b4c68" commander@2.15.x, commander@^2.11.0, commander@^2.15.1, commander@^2.8.1, commander@^2.9.0, commander@~2.15.0: version "2.15.1" -- GitLab From 24420ab65c34eafd54689a89ee4fbadee74c87b1 Mon Sep 17 00:00:00 2001 From: Axel Chalon Date: Mon, 30 Jul 2018 14:49:10 +0200 Subject: [PATCH 9/9] Don't pass Electron flag down to Parity --- packages/fether-electron/src/main/cli/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/fether-electron/src/main/cli/index.js b/packages/fether-electron/src/main/cli/index.js index 75147b83..06a1e81b 100644 --- a/packages/fether-electron/src/main/cli/index.js +++ b/packages/fether-electron/src/main/cli/index.js @@ -41,6 +41,8 @@ cli `Specify the port portion of the WebSockets server ${productName} will connect to. (default: 8546)`, 8546 ) - .parse(process.argv); + // `electron-webpack dev` runs Electron with the `--inspect` flag for HMR; + // we want to ignore this flag and not pass it down to Parity + .parse(process.argv.filter(arg => !arg.startsWith('--inspect'))); export default cli; -- GitLab