function runElectronApp(port) {
  if (isElectronRunning) return;

  isElectronRunning = true;
  process.env['ELECTRON_START_URL'] =
    process.env['ELECTRON_START_URL'] || `http://localhost:${port}`;
  const electronCommand = IS_WIN ? 'electron.cmd' : 'electron';

  const electronProcess = spawn(electronCommand, ['.']);

  electronProcess.stdout.on('data', data => {
    // dont log blank output or empty newlines
    const output = data.toString().trim();
    if (output.length) console.info(chalk.green('[ELECTRON]'), output);
  });
  electronProcess.stderr.on('data', data => {
    const output = data.toString();
    console.error(chalk.red(`[ELECTRON] ${output}`));
  });

  // close webpack server when electron quits
  electronProcess.on('exit', code => process.exit(code));

  // clear console for brevity
  process.stdout.write('\x1bc');
}
Singleton-ish run of Electron
Prevents multiple re-runs of Electron App