diff --git a/default_app/main.js b/default_app/main.js index 6ff26e9ea67..c46d1fc3bd6 100644 --- a/default_app/main.js +++ b/default_app/main.js @@ -6,14 +6,9 @@ const Menu = electron.Menu; const fs = require('fs'); const path = require('path'); +const repl = require('repl'); const url = require('url'); -// Quit when all windows are closed and no other one is listening to this. -app.on('window-all-closed', function() { - if (app.listeners('window-all-closed').length == 1) - app.quit(); -}); - // Parse command line options. var argv = process.argv.slice(1); var option = { file: null, help: null, version: null, webdriver: null, modules: [] }; @@ -27,6 +22,8 @@ for (var i = 0; i < argv.length; i++) { } else if (argv[i] == '--help' || argv[i] == '-h') { option.help = true; break; + } else if (argv[i] == '--interactive' || argv[i] == '-i') { + option.interactive = true; } else if (argv[i] == '--test-type=webdriver') { option.webdriver = true; } else if (argv[i] == '--require' || argv[i] == '-r') { @@ -40,6 +37,12 @@ for (var i = 0; i < argv.length; i++) { } } +// Quit when all windows are closed and no other one is listening to this. +app.on('window-all-closed', function() { + if (app.listeners('window-all-closed').length == 1 && !option.interactive) + app.quit(); +}); + // Create default menu. app.once('ready', function() { if (Menu.getApplicationMenu()) @@ -275,6 +278,12 @@ function loadApplicationByUrl(appUrl) { require('./default_app').load(appUrl); } +function startRepl() { + repl.start('> ').on('exit', function() { + process.exit(0); + }); +} + // Start the specified app if there is one specified in command line, otherwise // start the default app. if (option.file && !option.webdriver) { @@ -302,11 +311,14 @@ if (option.file && !option.webdriver) { helpMessage += " - .html/.htm file.\n"; helpMessage += " - http://, https://, or file:// URL.\n"; helpMessage += "\nOptions:\n"; - helpMessage += " -r, --require Module to preload (option can be repeated)\n"; helpMessage += " -h, --help Print this usage message.\n"; + helpMessage += " -i, --interactive Open a REPL to the main process.\n"; + helpMessage += " -r, --require Module to preload (option can be repeated)\n"; helpMessage += " -v, --version Print the version."; console.log(helpMessage); process.exit(0); +} else if (option.interactive) { + startRepl(); } else { loadApplicationByUrl('file://' + __dirname + '/index.html'); } diff --git a/package.json b/package.json index 21ac10cff25..9f097c167df 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "build": "python ./script/build.py -c D", "lint": "python ./script/eslint.py && python ./script/cpplint.py", "preinstall": "node -e 'process.exit(0)'", + "repl": "python ./script/start.py --interactive", "start": "python ./script/start.py", "test": "python ./script/test.py" }