OLD | NEW |
1 library pub.command.serve; | 1 library pub.command.serve; |
2 import 'dart:async'; | 2 import 'dart:async'; |
3 import 'dart:math' as math; | 3 import 'dart:math' as math; |
4 import 'package:barback/barback.dart'; | 4 import 'package:barback/barback.dart'; |
5 import '../barback/asset_environment.dart'; | 5 import '../barback/asset_environment.dart'; |
6 import '../barback/pub_package_provider.dart'; | 6 import '../barback/pub_package_provider.dart'; |
7 import '../log.dart' as log; | 7 import '../log.dart' as log; |
8 import '../utils.dart'; | 8 import '../utils.dart'; |
9 import 'barback.dart'; | 9 import 'barback.dart'; |
10 final _arrow = getSpecial('\u2192', '=>'); | 10 final _arrow = getSpecial('\u2192', '=>'); |
11 class ServeCommand extends BarbackCommand { | 11 class ServeCommand extends BarbackCommand { |
12 String get description => | 12 String get description => |
13 'Run a local web development server.\n\n' | 13 'Run a local web development server.\n\n' |
14 'By default, this serves "web/" and "test/", but an explicit list of \
n' | 14 'By default, this serves "web/" and "test/", but an explicit list of \
n' |
15 'directories to serve can be provided as well.'; | 15 'directories to serve can be provided as well.'; |
16 String get usage => "pub serve [directories...]"; | 16 String get usage => "pub serve [directories...]"; |
17 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-serve.html"; | 17 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-serve.html"; |
18 PubPackageProvider _provider; | 18 PubPackageProvider _provider; |
19 String get hostname => commandOptions['hostname']; | 19 String get hostname => commandOptions['hostname']; |
20 int get port => parseInt(commandOptions['port'], 'port'); | 20 int get port => parseInt(commandOptions['port'], 'port'); |
21 int get adminPort { | 21 int get adminPort { |
22 var adminPort = commandOptions['admin-port']; | 22 var adminPort = commandOptions['admin-port']; |
23 return adminPort == null ? null : parseInt(adminPort, 'admin port'); | 23 return adminPort == null ? null : parseInt(adminPort, 'admin port'); |
24 } | 24 } |
25 bool get useDart2JS => commandOptions['dart2js']; | 25 bool get useDart2JS => commandOptions['dart2js']; |
| 26 bool get logAdminUrl => commandOptions['log-admin-url']; |
26 BarbackMode get defaultMode => BarbackMode.DEBUG; | 27 BarbackMode get defaultMode => BarbackMode.DEBUG; |
27 List<String> get defaultSourceDirectories => ["web", "test"]; | 28 List<String> get defaultSourceDirectories => ["web", "test"]; |
28 final _completer = new Completer(); | 29 final _completer = new Completer(); |
29 ServeCommand() { | 30 ServeCommand() { |
30 commandParser.addOption( | 31 commandParser.addOption( |
31 'hostname', | 32 'hostname', |
32 defaultsTo: 'localhost', | 33 defaultsTo: 'localhost', |
33 help: 'The hostname to listen on.'); | 34 help: 'The hostname to listen on.'); |
34 commandParser.addOption( | 35 commandParser.addOption( |
35 'port', | 36 'port', |
(...skipping 23 matching lines...) Expand all Loading... |
59 entrypoint, | 60 entrypoint, |
60 mode, | 61 mode, |
61 watcherType: watcherType, | 62 watcherType: watcherType, |
62 hostname: hostname, | 63 hostname: hostname, |
63 basePort: port, | 64 basePort: port, |
64 useDart2JS: useDart2JS).then((x2) { | 65 useDart2JS: useDart2JS).then((x2) { |
65 try { | 66 try { |
66 var environment = x2; | 67 var environment = x2; |
67 var directoryLength = | 68 var directoryLength = |
68 sourceDirectories.map(((dir) => dir.length)).reduce(math.max
); | 69 sourceDirectories.map(((dir) => dir.length)).reduce(math.max
); |
69 join2() { | 70 environment.startAdminServer(adminPort).then((x3) { |
70 environment.pauseUpdates(); | 71 try { |
71 var it0 = sourceDirectories.iterator; | 72 var server = x3; |
72 break0(x6) { | 73 server.results.listen(((_) { |
73 environment.barback.errors.listen(((error) { | 74 assert(false); |
74 log.error(log.red("Build error:\n$error")); | |
75 })); | |
76 environment.barback.results.listen(((result) { | |
77 if (result.succeeded) { | |
78 log.message( | |
79 "Build completed ${log.green('successfully')}"); | |
80 } else { | |
81 log.message( | |
82 "Build completed with " "${log.red(result.errors.len
gth)} errors."); | |
83 } | |
84 }), onError: _fatalError); | 75 }), onError: _fatalError); |
85 environment.resumeUpdates(); | 76 join2() { |
86 _completer.future.then((x3) { | 77 environment.pauseUpdates(); |
87 try { | 78 var it0 = sourceDirectories.iterator; |
88 x3; | 79 break0(x7) { |
89 completer0.complete(null); | 80 environment.barback.errors.listen(((error) { |
90 } catch (e1) { | 81 log.error(log.red("Build error:\n$error")); |
91 completer0.completeError(e1); | 82 })); |
92 } | 83 environment.barback.results.listen(((result) { |
93 }, onError: (e2) { | 84 if (result.succeeded) { |
94 completer0.completeError(e2); | 85 log.message( |
95 }); | 86 "Build completed ${log.green('successfully')}"); |
96 } | 87 } else { |
97 continue0(x7) { | 88 log.message( |
98 if (it0.moveNext()) { | 89 "Build completed with " "${log.red(result.errors
.length)} errors."); |
99 Future.wait([]).then((x5) { | 90 } |
100 var directory = it0.current; | 91 }), onError: _fatalError); |
101 _startServer( | 92 environment.resumeUpdates(); |
102 environment, | 93 _completer.future.then((x4) { |
103 directory, | |
104 directoryLength).then((x4) { | |
105 try { | 94 try { |
106 x4; | 95 x4; |
107 continue0(null); | 96 completer0.complete(null); |
108 } catch (e3) { | 97 } catch (e2) { |
109 completer0.completeError(e3); | 98 completer0.completeError(e2); |
110 } | 99 } |
111 }, onError: (e4) { | 100 }, onError: (e3) { |
112 completer0.completeError(e4); | 101 completer0.completeError(e3); |
113 }); | 102 }); |
114 }); | 103 } |
115 } else { | 104 continue0(x8) { |
116 break0(null); | 105 if (it0.moveNext()) { |
| 106 Future.wait([]).then((x6) { |
| 107 var directory = it0.current; |
| 108 _startServer( |
| 109 environment, |
| 110 directory, |
| 111 directoryLength).then((x5) { |
| 112 try { |
| 113 x5; |
| 114 continue0(null); |
| 115 } catch (e4) { |
| 116 completer0.completeError(e4); |
| 117 } |
| 118 }, onError: (e5) { |
| 119 completer0.completeError(e5); |
| 120 }); |
| 121 }); |
| 122 } else { |
| 123 break0(null); |
| 124 } |
| 125 } |
| 126 continue0(null); |
117 } | 127 } |
118 } | 128 if (logAdminUrl) { |
119 continue0(null); | |
120 } | |
121 if (adminPort != null) { | |
122 environment.startAdminServer(adminPort).then((x8) { | |
123 try { | |
124 var server = x8; | |
125 server.results.listen(((_) { | |
126 assert(false); | |
127 }), onError: _fatalError); | |
128 log.message( | 129 log.message( |
129 "Running admin server on " "${log.bold('http://${hostn
ame}:${server.port}')}"); | 130 "Running admin server on " "${log.bold('http://${hostn
ame}:${server.port}')}"); |
130 join2(); | 131 join2(); |
131 } catch (e5) { | 132 } else { |
132 completer0.completeError(e5); | 133 join2(); |
133 } | 134 } |
134 }, onError: (e6) { | 135 } catch (e1) { |
135 completer0.completeError(e6); | 136 completer0.completeError(e1); |
136 }); | 137 } |
137 } else { | 138 }, onError: (e6) { |
138 join2(); | 139 completer0.completeError(e6); |
139 } | 140 }); |
140 } catch (e0) { | 141 } catch (e0) { |
141 completer0.completeError(e0); | 142 completer0.completeError(e0); |
142 } | 143 } |
143 }, onError: (e7) { | 144 }, onError: (e7) { |
144 completer0.completeError(e7); | 145 completer0.completeError(e7); |
145 }); | 146 }); |
146 } | 147 } |
147 if (commandOptions['force-poll']) { | 148 if (commandOptions['force-poll']) { |
148 join1(WatcherType.POLLING); | 149 join1(WatcherType.POLLING); |
149 } else { | 150 } else { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 completer0.completeError(e2); | 212 completer0.completeError(e2); |
212 } | 213 } |
213 }); | 214 }); |
214 return completer0.future; | 215 return completer0.future; |
215 } | 216 } |
216 void _fatalError(error, [stackTrace]) { | 217 void _fatalError(error, [stackTrace]) { |
217 if (_completer.isCompleted) return; | 218 if (_completer.isCompleted) return; |
218 _completer.completeError(error, stackTrace); | 219 _completer.completeError(error, stackTrace); |
219 } | 220 } |
220 } | 221 } |
OLD | NEW |