Index: sdk/lib/_internal/pub_generated/lib/src/command/serve.dart |
diff --git a/sdk/lib/_internal/pub_generated/lib/src/command/serve.dart b/sdk/lib/_internal/pub_generated/lib/src/command/serve.dart |
index 8255ec1932dda27f1446a923700dfdf870006ab2..2aae583d9740ffe4691ebf119721c4d89ab39ab6 100644 |
--- a/sdk/lib/_internal/pub_generated/lib/src/command/serve.dart |
+++ b/sdk/lib/_internal/pub_generated/lib/src/command/serve.dart |
@@ -1,13 +1,23 @@ |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
library pub.command.serve; |
+ |
import 'dart:async'; |
import 'dart:math' as math; |
+ |
import 'package:barback/barback.dart'; |
+ |
import '../barback/asset_environment.dart'; |
import '../barback/pub_package_provider.dart'; |
import '../log.dart' as log; |
import '../utils.dart'; |
import 'barback.dart'; |
+ |
final _arrow = getSpecial('\u2192', '=>'); |
+ |
+/// Handles the `serve` pub command. |
class ServeCommand extends BarbackCommand { |
String get description => |
'Run a local web development server.\n\n' |
@@ -15,18 +25,38 @@ class ServeCommand extends BarbackCommand { |
'directories to serve can be provided as well.'; |
String get usage => "pub serve [directories...]"; |
String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-serve.html"; |
+ |
PubPackageProvider _provider; |
+ |
String get hostname => commandOptions['hostname']; |
+ |
+ /// The base port for the servers. |
+ /// |
+ /// This will print a usage error and exit if the specified port is invalid. |
int get port => parseInt(commandOptions['port'], 'port'); |
+ |
+ /// The port for the admin UI. |
+ /// |
+ /// This will print a usage error and exit if the specified port is invalid. |
int get adminPort { |
var adminPort = commandOptions['admin-port']; |
return adminPort == null ? null : parseInt(adminPort, 'admin port'); |
} |
+ |
+ /// `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']; |
+ |
BarbackMode get defaultMode => BarbackMode.DEBUG; |
+ |
List<String> get defaultSourceDirectories => ["web", "test"]; |
+ |
+ /// This completer is used to keep pub running (by not completing) and to |
+ /// pipe fatal errors to pub's top-level error-handling machinery. |
final _completer = new Completer(); |
+ |
ServeCommand() { |
commandParser.addOption( |
'hostname', |
@@ -36,8 +66,17 @@ class ServeCommand extends BarbackCommand { |
'port', |
defaultsTo: '8080', |
help: 'The base port to listen on.'); |
+ |
+ // 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); |
+ |
+ // TODO(nweiz): Make this public when issue 16954 is fixed. |
commandParser.addOption('admin-port', hide: true); |
+ |
commandParser.addFlag( |
'dart2js', |
defaultsTo: true, |
@@ -47,6 +86,7 @@ class ServeCommand extends BarbackCommand { |
defaultsTo: false, |
help: 'Force the use of a polling filesystem watcher.'); |
} |
+ |
Future onRunTransformerCommand() { |
final completer0 = new Completer(); |
scheduleMicrotask(() { |
@@ -65,8 +105,9 @@ class ServeCommand extends BarbackCommand { |
useDart2JS: useDart2JS).then((x2) { |
try { |
var environment = x2; |
- var directoryLength = |
- sourceDirectories.map(((dir) => dir.length)).reduce(math.max); |
+ var directoryLength = sourceDirectories.map(((dir) { |
+ return dir.length; |
+ })).reduce(math.max); |
environment.startAdminServer(adminPort).then((x3) { |
try { |
var server = x3; |
@@ -76,7 +117,7 @@ class ServeCommand extends BarbackCommand { |
join2() { |
environment.pauseUpdates(); |
var it0 = sourceDirectories.iterator; |
- break0(x7) { |
+ break0() { |
environment.barback.errors.listen(((error) { |
log.error(log.red("Build error:\n$error")); |
})); |
@@ -93,37 +134,38 @@ class ServeCommand extends BarbackCommand { |
_completer.future.then((x4) { |
try { |
x4; |
- completer0.complete(null); |
- } catch (e2) { |
- completer0.completeError(e2); |
+ completer0.complete(); |
+ } catch (e0, s0) { |
+ completer0.completeError(e0, s0); |
} |
- }, onError: (e3) { |
- completer0.completeError(e3); |
- }); |
+ }, onError: completer0.completeError); |
} |
- continue0(x8) { |
+ var trampoline0; |
+ continue0() { |
+ trampoline0 = null; |
if (it0.moveNext()) { |
- Future.wait([]).then((x6) { |
- var directory = it0.current; |
- _startServer( |
- environment, |
- directory, |
- directoryLength).then((x5) { |
+ var directory = it0.current; |
+ _startServer( |
+ environment, |
+ directory, |
+ directoryLength).then((x5) { |
+ trampoline0 = () { |
+ trampoline0 = null; |
try { |
x5; |
- continue0(null); |
- } catch (e4) { |
- completer0.completeError(e4); |
+ trampoline0 = continue0; |
+ } catch (e1, s1) { |
+ completer0.completeError(e1, s1); |
} |
- }, onError: (e5) { |
- completer0.completeError(e5); |
- }); |
- }); |
+ }; |
+ do trampoline0(); while (trampoline0 != null); |
+ }, onError: completer0.completeError); |
} else { |
- break0(null); |
+ break0(); |
} |
} |
- continue0(null); |
+ trampoline0 = continue0; |
+ do trampoline0(); while (trampoline0 != null); |
} |
if (logAdminUrl) { |
log.message( |
@@ -132,18 +174,14 @@ class ServeCommand extends BarbackCommand { |
} else { |
join2(); |
} |
- } catch (e1) { |
- completer0.completeError(e1); |
+ } catch (e2, s2) { |
+ completer0.completeError(e2, s2); |
} |
- }, onError: (e6) { |
- completer0.completeError(e6); |
- }); |
- } catch (e0) { |
- completer0.completeError(e0); |
+ }, onError: completer0.completeError); |
+ } catch (e3, s3) { |
+ completer0.completeError(e3, s3); |
} |
- }, onError: (e7) { |
- completer0.completeError(e7); |
- }); |
+ }, onError: completer0.completeError); |
} |
if (commandOptions['force-poll']) { |
join1(WatcherType.POLLING); |
@@ -156,12 +194,13 @@ class ServeCommand extends BarbackCommand { |
} else { |
join0(parseInt(commandOptions['admin-port'], 'admin port')); |
} |
- } catch (e8) { |
- completer0.completeError(e8); |
+ } catch (e, s) { |
+ completer0.completeError(e, s); |
} |
}); |
return completer0.future; |
} |
+ |
Future _startServer(AssetEnvironment environment, String rootDirectory, |
int directoryLength) { |
final completer0 = new Completer(); |
@@ -194,26 +233,28 @@ class ServeCommand extends BarbackCommand { |
"Serving ${entrypoint.root.name} " |
"${padRight(server.rootDirectory, directoryLength)} " |
"on ${log.bold('http://${hostname}:${server.port}')}"); |
- completer0.complete(null); |
+ completer0.complete(); |
} |
if (mode == BarbackMode.RELEASE) { |
- server.allowAsset = ((url) => !url.path.endsWith(".dart")); |
+ server.allowAsset = ((url) { |
+ return !url.path.endsWith(".dart"); |
+ }); |
join0(); |
} else { |
join0(); |
} |
- } catch (e0) { |
- completer0.completeError(e0); |
+ } catch (e0, s0) { |
+ completer0.completeError(e0, s0); |
} |
- }, onError: (e1) { |
- completer0.completeError(e1); |
- }); |
- } catch (e2) { |
- completer0.completeError(e2); |
+ }, onError: completer0.completeError); |
+ } catch (e, s) { |
+ completer0.completeError(e, s); |
} |
}); |
return completer0.future; |
} |
+ |
+ /// Reports [error] and exits the server. |
void _fatalError(error, [stackTrace]) { |
if (_completer.isCompleted) return; |
_completer.completeError(error, stackTrace); |