| Index: sdk/lib/_internal/pub/lib/src/command/serve.dart
|
| diff --git a/sdk/lib/_internal/pub/lib/src/command/serve.dart b/sdk/lib/_internal/pub/lib/src/command/serve.dart
|
| index f43cc3a4b1a6588237079b86617460089a4938a0..f9f217b86b3e909517419b6ef5bba9d7a8f05025 100644
|
| --- a/sdk/lib/_internal/pub/lib/src/command/serve.dart
|
| +++ b/sdk/lib/_internal/pub/lib/src/command/serve.dart
|
| @@ -36,6 +36,9 @@ class ServeCommand extends PubCommand {
|
| /// `true` if Dart entrypoints should be compiled to JavaScript.
|
| bool get useDart2JS => commandOptions['dart2js'];
|
|
|
| + /// `true` if the admin server URL should be displayed on startup.
|
| + bool get logAdminUrl => commandOptions['log-admin-url'];
|
| +
|
| /// The build mode.
|
| BarbackMode get mode => new BarbackMode(commandOptions['mode']);
|
|
|
| @@ -54,6 +57,14 @@ class ServeCommand extends PubCommand {
|
| commandParser.addOption('hostname',
|
| defaultsTo: 'localhost',
|
| hide: true);
|
| +
|
| + // TODO(rnystrom): A hidden option to print the URL that the admin server
|
| + // is bound to on startup. Since this is currently only used for the Web
|
| + // Socket interface, we don't want to show it to users, but the tests and
|
| + // Editor need this logged to know what port to bind to.
|
| + // Remove this (and always log) when #16954 is fixed.
|
| + commandParser.addFlag('log-admin-url', defaultsTo: false, hide: true);
|
| +
|
| commandParser.addFlag('dart2js', defaultsTo: true,
|
| help: 'Compile Dart to JavaScript.');
|
| commandParser.addFlag('force-poll', defaultsTo: false,
|
| @@ -83,12 +94,24 @@ class ServeCommand extends PubCommand {
|
| var directoryLength = directories.map((dir) => dir.length)
|
| .reduce(math.max);
|
|
|
| - // Start up the servers. We pause updates while this is happening so that
|
| - // we don't log spurious build results in the middle of listing out the
|
| - // bound servers.
|
| - environment.pauseUpdates();
|
| - return Future.forEach(directories, (directory) {
|
| - return _startServer(environment, directory, directoryLength);
|
| + return environment.startAdminServer().then((server) {
|
| + server.results.listen((_) {
|
| + // The admin server produces no result values.
|
| + assert(false);
|
| + }, onError: _fatalError);
|
| +
|
| + if (logAdminUrl) {
|
| + log.message("Running admin server on "
|
| + "${log.bold('http://$hostname:${server.port}')}");
|
| + }
|
| +
|
| + // Start up the servers. We pause updates while this is happening so
|
| + // that we don't log spurious build results in the middle of listing
|
| + // out the bound servers.
|
| + environment.pauseUpdates();
|
| + return Future.forEach(directories, (directory) {
|
| + return _startServer(environment, directory, directoryLength);
|
| + });
|
| }).then((_) {
|
| // Now that the servers are up and logged, send them to barback.
|
| environment.barback.errors.listen((error) {
|
| @@ -103,11 +126,7 @@ class ServeCommand extends PubCommand {
|
| log.message("Build completed with "
|
| "${log.red(result.errors.length)} errors.");
|
| }
|
| - }, onError: (error, [stackTrace]) {
|
| - if (!_completer.isCompleted) {
|
| - _completer.completeError(error, stackTrace);
|
| - }
|
| - });
|
| + }, onError: _fatalError);
|
|
|
| environment.resumeUpdates();
|
| return _completer.future;
|
| @@ -147,11 +166,7 @@ class ServeCommand extends PubCommand {
|
| }
|
|
|
| log.message(buffer);
|
| -
|
| - }, onError: (error, [stackTrace]) {
|
| - if (_completer.isCompleted) return;
|
| - _completer.completeError(error, stackTrace);
|
| - });
|
| + }, onError: _fatalError);
|
|
|
| log.message("Serving ${entrypoint.root.name} "
|
| "${padRight(server.rootDirectory, directoryLength)} "
|
| @@ -202,4 +217,10 @@ class ServeCommand extends PubCommand {
|
| plural: pluralVerb);
|
| return "$directories $names $verb";
|
| }
|
| +
|
| + /// Reports [error] and exits the server.
|
| + void _fatalError(error, [stackTrace]) {
|
| + if (_completer.isCompleted) return;
|
| + _completer.completeError(error, stackTrace);
|
| + }
|
| }
|
|
|