OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library pub.command.serve; | 5 library pub.command.serve; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
9 | 9 |
10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 Future _startServer(AssetEnvironment environment, String rootDirectory, | 141 Future _startServer(AssetEnvironment environment, String rootDirectory, |
142 int directoryLength) async { | 142 int directoryLength) async { |
143 var server = await environment.serveDirectory(rootDirectory); | 143 var server = await environment.serveDirectory(rootDirectory); |
144 // In release mode, strip out .dart files since all relevant ones have | 144 // In release mode, strip out .dart files since all relevant ones have |
145 // been compiled to JavaScript already. | 145 // been compiled to JavaScript already. |
146 if (mode == BarbackMode.RELEASE) { | 146 if (mode == BarbackMode.RELEASE) { |
147 server.allowAsset = (url) => !url.path.endsWith(".dart"); | 147 server.allowAsset = (url) => !url.path.endsWith(".dart"); |
148 } | 148 } |
149 | 149 |
150 // Add two characters to account for "[" and "]". | 150 // Add two characters to account for "[" and "]". |
151 var prefix = log.gray( | 151 var directory = log.gray( |
152 padRight("[${server.rootDirectory}]", directoryLength + 2)); | 152 padRight("[${server.rootDirectory}]", directoryLength + 2)); |
153 | 153 |
154 server.results.listen((result) { | 154 server.results.listen((result) { |
155 var buffer = new StringBuffer(); | |
156 buffer.write("$prefix "); | |
157 | |
158 if (result.isSuccess) { | 155 if (result.isSuccess) { |
159 buffer.write( | 156 var prefix = "$directory ${log.green('GET')}"; |
160 "${log.green('GET')} ${result.url.path} $_arrow ${result.id}"); | 157 log.collapsible("$prefix ${result.url.path} $_arrow ${result.id}", |
| 158 "$prefix Served ## assets."); |
161 } else { | 159 } else { |
162 buffer.write("${log.red('GET')} ${result.url.path} $_arrow"); | 160 var buffer = new StringBuffer(); |
| 161 buffer.write("$directory ${log.red('GET')} ${result.url.path} $_arrow"); |
163 | 162 |
164 var error = result.error.toString(); | 163 var error = result.error.toString(); |
165 if (error.contains("\n")) { | 164 if (error.contains("\n")) { |
166 buffer.write("\n${prefixLines(error)}"); | 165 buffer.write("\n${prefixLines(error)}"); |
167 } else { | 166 } else { |
168 buffer.write(" $error"); | 167 buffer.write(" $error"); |
169 } | 168 } |
| 169 |
| 170 log.error(buffer); |
170 } | 171 } |
171 | |
172 log.message(buffer); | |
173 }, onError: _fatalError); | 172 }, onError: _fatalError); |
174 | 173 |
175 log.message("Serving ${entrypoint.root.name} " | 174 log.message("Serving ${entrypoint.root.name} " |
176 "${padRight(server.rootDirectory, directoryLength)} " | 175 "${padRight(server.rootDirectory, directoryLength)} " |
177 "on ${log.bold('http://$hostname:${server.port}')}"); | 176 "on ${log.bold('http://$hostname:${server.port}')}"); |
178 } | 177 } |
179 | 178 |
180 /// Reports [error] and exits the server. | 179 /// Reports [error] and exits the server. |
181 void _fatalError(error, [stackTrace]) { | 180 void _fatalError(error, [stackTrace]) { |
182 if (_completer.isCompleted) return; | 181 if (_completer.isCompleted) return; |
183 _completer.completeError(error, stackTrace); | 182 _completer.completeError(error, stackTrace); |
184 } | 183 } |
185 } | 184 } |
OLD | NEW |