Open App from Command Line Interface for Electron.
$ npm install --save electron-terminal-open
require electron.
'use strict';
const {BrowserWindow, app} = require('electron');
const parseArgs = require('minimist');
const electronTerminalOpen = require('electron-terminal-open');
let mainWindow;
function createMainWindow() {
const win = new BrowserWindow({
title: 'sample-app',
width: 400,
height: 500
});
if (process.env.NODE_ENV === 'development') {
win.openDevTools();
}
win.loadURL(`https://kangax.github.io/compat-table/es6/`);
win.on('closed', () => {
mainWindow = null;
});
return win;
}
const args = parseArgs(process.argv.slice(1));
if (args.h || args.help) {
console.log(`help sample`);
process.exit(0); // eslint-disable-line
}
if (args.v || args.version) {
console.log(app.getName(), app.getVersion());
process.exit(0); // eslint-disable-line
}
app.on('ready', () => {
electronTerminalOpen(app).then(() => {
mainWindow = createMainWindow();
}).catch(err => {
console.log(err);
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
See example.
Add executed-from prop to process.args.
$ pwd
/a/b/c
$ sample-app .
args['executed-from'] // => /a/b/c
Type: object
electron.app
Type: string
Default: com.electron.${app.getName()}
app-bundle-id
MIT © akameco