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']; | |
27 BarbackMode get defaultMode => BarbackMode.DEBUG; | 26 BarbackMode get defaultMode => BarbackMode.DEBUG; |
28 List<String> get defaultSourceDirectories => ["web", "test"]; | 27 List<String> get defaultSourceDirectories => ["web", "test"]; |
29 final _completer = new Completer(); | 28 final _completer = new Completer(); |
30 ServeCommand() { | 29 ServeCommand() { |
31 commandParser.addOption( | 30 commandParser.addOption( |
32 'hostname', | 31 'hostname', |
33 defaultsTo: 'localhost', | 32 defaultsTo: 'localhost', |
34 help: 'The hostname to listen on.'); | 33 help: 'The hostname to listen on.'); |
35 commandParser.addOption( | 34 commandParser.addOption( |
36 'port', | 35 'port', |
(...skipping 23 matching lines...) Expand all Loading... |
60 entrypoint, | 59 entrypoint, |
61 mode, | 60 mode, |
62 watcherType: watcherType, | 61 watcherType: watcherType, |
63 hostname: hostname, | 62 hostname: hostname, |
64 basePort: port, | 63 basePort: port, |
65 useDart2JS: useDart2JS).then((x2) { | 64 useDart2JS: useDart2JS).then((x2) { |
66 try { | 65 try { |
67 var environment = x2; | 66 var environment = x2; |
68 var directoryLength = | 67 var directoryLength = |
69 sourceDirectories.map(((dir) => dir.length)).reduce(math.max
); | 68 sourceDirectories.map(((dir) => dir.length)).reduce(math.max
); |
70 environment.startAdminServer(adminPort).then((x3) { | 69 join2() { |
71 try { | 70 environment.pauseUpdates(); |
72 var server = x3; | 71 var it0 = sourceDirectories.iterator; |
73 server.results.listen(((_) { | 72 break0(x6) { |
74 assert(false); | 73 environment.barback.errors.listen(((error) { |
| 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 } |
75 }), onError: _fatalError); | 84 }), onError: _fatalError); |
76 join2() { | 85 environment.resumeUpdates(); |
77 environment.pauseUpdates(); | 86 _completer.future.then((x3) { |
78 var it0 = sourceDirectories.iterator; | 87 try { |
79 break0(x7) { | 88 x3; |
80 environment.barback.errors.listen(((error) { | 89 completer0.complete(null); |
81 log.error(log.red("Build error:\n$error")); | 90 } catch (e1) { |
82 })); | 91 completer0.completeError(e1); |
83 environment.barback.results.listen(((result) { | 92 } |
84 if (result.succeeded) { | 93 }, onError: (e2) { |
85 log.message( | 94 completer0.completeError(e2); |
86 "Build completed ${log.green('successfully')}"); | 95 }); |
87 } else { | 96 } |
88 log.message( | 97 continue0(x7) { |
89 "Build completed with " "${log.red(result.errors
.length)} errors."); | 98 if (it0.moveNext()) { |
90 } | 99 Future.wait([]).then((x5) { |
91 }), onError: _fatalError); | 100 var directory = it0.current; |
92 environment.resumeUpdates(); | 101 _startServer( |
93 _completer.future.then((x4) { | 102 environment, |
| 103 directory, |
| 104 directoryLength).then((x4) { |
94 try { | 105 try { |
95 x4; | 106 x4; |
96 completer0.complete(null); | 107 continue0(null); |
97 } catch (e2) { | 108 } catch (e3) { |
98 completer0.completeError(e2); | 109 completer0.completeError(e3); |
99 } | 110 } |
100 }, onError: (e3) { | 111 }, onError: (e4) { |
101 completer0.completeError(e3); | 112 completer0.completeError(e4); |
102 }); | 113 }); |
103 } | 114 }); |
104 continue0(x8) { | 115 } else { |
105 if (it0.moveNext()) { | 116 break0(null); |
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); | |
127 } | 117 } |
128 if (logAdminUrl) { | 118 } |
| 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); |
129 log.message( | 128 log.message( |
130 "Running admin server on " "${log.bold('http://${hostn
ame}:${server.port}')}"); | 129 "Running admin server on " "${log.bold('http://${hostn
ame}:${server.port}')}"); |
131 join2(); | 130 join2(); |
132 } else { | 131 } catch (e5) { |
133 join2(); | 132 completer0.completeError(e5); |
134 } | 133 } |
135 } catch (e1) { | 134 }, onError: (e6) { |
136 completer0.completeError(e1); | 135 completer0.completeError(e6); |
137 } | 136 }); |
138 }, onError: (e6) { | 137 } else { |
139 completer0.completeError(e6); | 138 join2(); |
140 }); | 139 } |
141 } catch (e0) { | 140 } catch (e0) { |
142 completer0.completeError(e0); | 141 completer0.completeError(e0); |
143 } | 142 } |
144 }, onError: (e7) { | 143 }, onError: (e7) { |
145 completer0.completeError(e7); | 144 completer0.completeError(e7); |
146 }); | 145 }); |
147 } | 146 } |
148 if (commandOptions['force-poll']) { | 147 if (commandOptions['force-poll']) { |
149 join1(WatcherType.POLLING); | 148 join1(WatcherType.POLLING); |
150 } else { | 149 } else { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 completer0.completeError(e2); | 211 completer0.completeError(e2); |
213 } | 212 } |
214 }); | 213 }); |
215 return completer0.future; | 214 return completer0.future; |
216 } | 215 } |
217 void _fatalError(error, [stackTrace]) { | 216 void _fatalError(error, [stackTrace]) { |
218 if (_completer.isCompleted) return; | 217 if (_completer.isCompleted) return; |
219 _completer.completeError(error, stackTrace); | 218 _completer.completeError(error, stackTrace); |
220 } | 219 } |
221 } | 220 } |
OLD | NEW |