Merge pull request #856 from embark-framework/features/config-browser-open
cli and config options for browser auto-open
This commit is contained in:
commit
904c716d89
11
cmd/cmd.js
11
cmd/cmd.js
|
@ -168,6 +168,7 @@ class Cmd {
|
|||
.option('-b, --host [host]', __('host to run the dev webserver (default: %s)', 'localhost'))
|
||||
.option('--noserver', __('disable the development webserver'))
|
||||
.option('--nodashboard', __('simple mode, disables the dashboard'))
|
||||
.option('--nobrowser', __('prevent the development webserver from automatically opening a web browser'))
|
||||
.option('--no-color', __('no colors in case it\'s needed for compatbility purposes'))
|
||||
.option('--logfile [logfile]', __('filename to output logs (default: %s)', 'none'))
|
||||
.option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
|
||||
|
@ -177,17 +178,19 @@ class Cmd {
|
|||
.action(function(env, options) {
|
||||
checkDeps();
|
||||
i18n.setOrDetectLocale(options.locale);
|
||||
const nullify = (v) => (!v || typeof v !== 'string') ? null : v;
|
||||
embark.run({
|
||||
env: env || 'development',
|
||||
serverPort: options.port,
|
||||
serverHost: options.host,
|
||||
serverPort: nullify(options.port),
|
||||
serverHost: nullify(options.host),
|
||||
client: options.client || 'geth',
|
||||
locale: options.locale,
|
||||
runWebserver: !options.noserver,
|
||||
runWebserver: options.noserver == null ? null : !options.noserver,
|
||||
useDashboard: !options.nodashboard,
|
||||
logFile: options.logfile,
|
||||
logLevel: options.loglevel,
|
||||
webpackConfigName: options.pipeline || 'development'
|
||||
webpackConfigName: options.pipeline || 'development',
|
||||
openBrowser: options.nobrowser == null ? null : !options.nobrowser,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -56,17 +56,24 @@ class EmbarkController {
|
|||
self.context = options.context || [constants.contexts.run, constants.contexts.build];
|
||||
let Dashboard = require('./dashboard/dashboard.js');
|
||||
|
||||
let webServerConfig = {
|
||||
enabled: options.runWebserver
|
||||
};
|
||||
const webServerConfig = {};
|
||||
|
||||
if (options.serverHost) {
|
||||
if (options.runWebserver != null) {
|
||||
webServerConfig.enabled = options.runWebserver;
|
||||
}
|
||||
|
||||
if (options.serverHost != null) {
|
||||
webServerConfig.host = options.serverHost;
|
||||
}
|
||||
if (options.serverPort) {
|
||||
|
||||
if (options.serverPort != null) {
|
||||
webServerConfig.port = options.serverPort;
|
||||
}
|
||||
|
||||
if (options.openBrowser != null) {
|
||||
webServerConfig.openBrowser = options.openBrowser;
|
||||
}
|
||||
|
||||
const Engine = require('../lib/core/engine.js');
|
||||
const engine = new Engine({
|
||||
env: options.env,
|
||||
|
@ -147,11 +154,8 @@ class EmbarkController {
|
|||
engine.events.emit("status", __("Ready").green);
|
||||
});
|
||||
|
||||
if (options.runWebserver) {
|
||||
engine.startService("webServer", {
|
||||
host: options.serverHost,
|
||||
port: options.serverPort
|
||||
});
|
||||
if (webServerConfig.enabled !== false) {
|
||||
engine.startService("webServer");
|
||||
}
|
||||
engine.startService("fileWatcher");
|
||||
callback();
|
||||
|
|
|
@ -314,6 +314,7 @@ Config.prototype.loadWebServerConfigFile = function() {
|
|||
var configObject = {
|
||||
"enabled": true,
|
||||
"host": defaultHost,
|
||||
"openBrowser": true,
|
||||
"port": 8000
|
||||
};
|
||||
|
||||
|
|
|
@ -226,9 +226,8 @@ class Engine {
|
|||
this.watch.start();
|
||||
}
|
||||
|
||||
webServerService(_options) {
|
||||
_options.buildDir = this.config.buildDir;
|
||||
this.registerModule('webserver', _options);
|
||||
webServerService() {
|
||||
this.registerModule('webserver');
|
||||
}
|
||||
|
||||
storageService(_options) {
|
||||
|
|
|
@ -10,18 +10,18 @@ const Templates = {
|
|||
};
|
||||
|
||||
class WebServer {
|
||||
constructor(embark, options) {
|
||||
constructor(embark) {
|
||||
this.embark = embark;
|
||||
this.logger = embark.logger;
|
||||
this.events = embark.events;
|
||||
this.buildDir = options.buildDir;
|
||||
this.buildDir = embark.config.buildDir;
|
||||
this.webServerConfig = embark.config.webServerConfig;
|
||||
if (!this.webServerConfig.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.host = options.host || this.webServerConfig.host;
|
||||
this.port = options.port || this.webServerConfig.port;
|
||||
this.host = this.webServerConfig.host;
|
||||
this.port = parseInt(this.webServerConfig.port, 10);
|
||||
|
||||
this.events.emit("status", __("Starting Server"));
|
||||
|
||||
|
@ -29,7 +29,8 @@ class WebServer {
|
|||
buildDir: this.buildDir,
|
||||
events: this.events,
|
||||
host: this.host,
|
||||
port: this.port
|
||||
port: this.port,
|
||||
openBrowser: this.webServerConfig.openBrowser
|
||||
});
|
||||
|
||||
this.events.on('webserver:config:change', () => {
|
||||
|
@ -64,6 +65,11 @@ class WebServer {
|
|||
}
|
||||
|
||||
testPort(done) {
|
||||
if (this.port === 0) {
|
||||
this.logger.warn(__('Assigning an available port'));
|
||||
this.server.port = 0;
|
||||
return done();
|
||||
}
|
||||
utils.pingEndpoint(this.host, this.port, 'http', 'http', '', (err) => {
|
||||
if (err) { // Port is ok
|
||||
return done();
|
||||
|
|
|
@ -13,6 +13,7 @@ class Server {
|
|||
this.hostname = dockerHostSwap(options.host) || defaultHost;
|
||||
this.isFirstStart = true;
|
||||
this.opened = false;
|
||||
this.openBrowser = options.openBrowser;
|
||||
}
|
||||
|
||||
start(callback) {
|
||||
|
@ -49,7 +50,7 @@ class Server {
|
|||
});
|
||||
},
|
||||
function openBrowser(next) {
|
||||
if (self.opened) {
|
||||
if (!self.openBrowser || self.opened) {
|
||||
return next();
|
||||
}
|
||||
self.opened = true;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
module.exports = {
|
||||
enabled: true,
|
||||
host: "localhost",
|
||||
openBrowser: true,
|
||||
port: 8000
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
module.exports = {
|
||||
enabled: true,
|
||||
host: "localhost",
|
||||
openBrowser: true,
|
||||
port: 8000
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue