From c93f0a0e539cdfc08e2e41a0b7cca3f5b3706233 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 9 Nov 2018 10:37:55 +0100 Subject: [PATCH 1/3] Added option to pass command line arguments --- README.md | 10 +++++++++- main.js | 9 ++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a49053c..8cf6e04 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,15 @@ require('electron-reload')(__dirname, { # API `electron_reload(paths, options)` * `paths`: a file, directory or glob pattern to watch -* `options` (optional): [`chokidar`](https://github.com/paulmillr/chokidar) options plus `electron` property pointing to electron executables. (default: `{ignored: /node_modules|[\/\\]\./}`) +* `options` (optional) containing: + + [`chokidar`](https://github.com/paulmillr/chokidar) options + + `electron` property pointing to electron executables. + + `argv` string array with command line options passed to the executed Electron app. Only used when hard resetting. + +`options` will default to `{ignored: /node_modules|[\/\\]\./, argv: []}`. # Why this module? diff --git a/main.js b/main.js index ac7ad3d..d0b36b5 100644 --- a/main.js +++ b/main.js @@ -18,11 +18,13 @@ const ignoredPaths = [mainFile, /node_modules|[/\\]\./] * @param {String} hardResetMethod method to restart electron * @returns {Function} handler to pass to chokidar */ -const createHardresetHandler = (eXecutable, hardResetMethod) => +const createHardresetHandler = (eXecutable, hardResetMethod, argv) => () => { // Detaching child is useful when in Windows to let child // live after the parent is killed - let child = spawn(eXecutable, [appPath], { + let args = (argv || []).concat([appPath]); + console.log("new args", args); + let child = spawn(eXecutable, args, { detached: true, stdio: 'inherit' }) @@ -73,9 +75,10 @@ module.exports = (glob, options = {}) => { // Preparing hard reset if electron executable is given in options // A hard reset is only done when the main file has changed + console.log("options", options); let eXecutable = options.electron if (eXecutable && fs.existsSync(eXecutable)) { - chokidar.watch(mainFile).once('change', createHardresetHandler(eXecutable, options.hardResetMethod)) + chokidar.watch(mainFile).once('change', createHardresetHandler(eXecutable, options.hardResetMethod, options.argv)) } else { console.log('Electron could not be found. No hard resets for you!') } From 4c62c487f86ac8fc79f399b8eec5751af0e671a8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 9 Nov 2018 10:42:31 +0100 Subject: [PATCH 2/3] Removed console.logs --- main.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.js b/main.js index d0b36b5..ff65b0e 100644 --- a/main.js +++ b/main.js @@ -23,7 +23,6 @@ const createHardresetHandler = (eXecutable, hardResetMethod, argv) => // Detaching child is useful when in Windows to let child // live after the parent is killed let args = (argv || []).concat([appPath]); - console.log("new args", args); let child = spawn(eXecutable, args, { detached: true, stdio: 'inherit' @@ -75,7 +74,6 @@ module.exports = (glob, options = {}) => { // Preparing hard reset if electron executable is given in options // A hard reset is only done when the main file has changed - console.log("options", options); let eXecutable = options.electron if (eXecutable && fs.existsSync(eXecutable)) { chokidar.watch(mainFile).once('change', createHardresetHandler(eXecutable, options.hardResetMethod, options.argv)) From 024e8664644f638ef04cb607828b1bebcd423f12 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 9 Nov 2018 11:13:22 +0100 Subject: [PATCH 3/3] Fixed standard issues --- main.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index ff65b0e..85e29d0 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,7 @@ -const {app} = require('electron') +const { app } = require('electron') const chokidar = require('chokidar') const fs = require('fs') -const {spawn} = require('child_process') +const { spawn } = require('child_process') const path = require('path') // Main file poses a special case, as its changes are @@ -22,7 +22,7 @@ const createHardresetHandler = (eXecutable, hardResetMethod, argv) => () => { // Detaching child is useful when in Windows to let child // live after the parent is killed - let args = (argv || []).concat([appPath]); + let args = (argv || []).concat([appPath]) let child = spawn(eXecutable, args, { detached: true, stdio: 'inherit' @@ -49,7 +49,7 @@ const createHardresetHandler = (eXecutable, hardResetMethod, argv) => const createWatcher = (glob, options = {}) => { // Watch everything but the node_modules folder and main file // main file changes are only effective if hard reset is possible - let opts = Object.assign({ignored: ignoredPaths}, options) + let opts = Object.assign({ ignored: ignoredPaths }, options) return chokidar.watch(glob, opts) }