knectron
v0.1.16
Published
Connect Electron to remote source such as Create React App.
Downloads
32
Maintainers
Readme
Knectron
Utility to connect Electron to remote source such as Create React App.
At first you may think this is overkill but we wrote this as it just connects/fires up in a little cleaner manner. Once you get the hang of it, you'll likely find it useful.
Quick Start
$ npm install knectron
Using API
const knectron = require('../dist/knectron');
knectron({
args: ['./dist'] // first arg is path to electron app
});
Knectron Options
interface IConnectOptions {
port?: number; // port to listen on (default: 3000)
host?: string; // host to listen on (default: 127.0.0.1)
spawnOptions?: SpawnOptions; // child_process options (default: { stdio: pipe })
args?: any[]; // args passed to Electron (default: './dist')
maxTries?: number; // max reconnect tries (default: 5)
retryDelay?: number; // delay between retries (default: 1200)
// API ONLY - NO CLI
onConnected?: (url?: string) => void;
onFailed?: (tries?: number) => void;
onRetry?: (tries?: number) => void;
onExit?: (err: Error) => void;
}
Using CLI
Knectron comes with a simple CLI. You can either install globally:
Using Globally
Install Knectron globally.
$ npm install knectron -g
One in your path you can do the following where args after "--" are passed directly to electron as shown here below.
$ knectron ./main.js -- --enable-logging
Using NPM Script
Or you can use npm scripts to execute:
{
"scripts": {
"knectron": "knectron ./main.js"
}
}
Then simply run the script as you would any npm script:
$ npm run knectron
CLI Help
To display help from your terminal run:
$ knectron --help
You will see the below help:
`Usage: knectron <path> [options]
Options:
--port the port to connect to
--host the host to connect to
--silent hides retries
--max-tries maximum connection retries
--retry-delay delay until retry
--spawn-options Node child_process spawn options
--help, -h display help
--examples show examples
Args provided after "--" directly passed to Electron`
CLI Examples
From your terminal type:
$ knectron --examples
The following will be shown:
`Examples:
knectron ./main.js --host=127.0.0.1 --port=5000
knectron ./main.js -- --enable-logging --v=5
knectron ./main.js --spawn-options.stdio=inherit
knectron ./main.js --spawn-options.stdio='[0,1,2]'`