| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 var prefix = log.gray( | 151 var prefix = 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(); | 155 var buffer = new StringBuffer(); |
| 156 buffer.write("$prefix "); | 156 buffer.write("$prefix "); |
| 157 | 157 |
| 158 if (result.isSuccess) { | 158 if (result.isSuccess) { |
| 159 buffer.write( | 159 buffer.write( |
| 160 "${log.green('GET')} ${result.url.path} $_arrow ${result.id}"); | 160 "${log.green('GET')} ${result.url.path} $_arrow ${result.id}"); |
| 161 log.collapsible(buffer); |
| 161 } else { | 162 } else { |
| 162 buffer.write("${log.red('GET')} ${result.url.path} $_arrow"); | 163 buffer.write("${log.red('GET')} ${result.url.path} $_arrow"); |
| 163 | 164 |
| 164 var error = result.error.toString(); | 165 var error = result.error.toString(); |
| 165 if (error.contains("\n")) { | 166 if (error.contains("\n")) { |
| 166 buffer.write("\n${prefixLines(error)}"); | 167 buffer.write("\n${prefixLines(error)}"); |
| 167 } else { | 168 } else { |
| 168 buffer.write(" $error"); | 169 buffer.write(" $error"); |
| 169 } | 170 } |
| 171 |
| 172 log.error(buffer); |
| 170 } | 173 } |
| 171 | |
| 172 log.message(buffer); | |
| 173 }, onError: _fatalError); | 174 }, onError: _fatalError); |
| 174 | 175 |
| 175 log.message("Serving ${entrypoint.root.name} " | 176 log.message("Serving ${entrypoint.root.name} " |
| 176 "${padRight(server.rootDirectory, directoryLength)} " | 177 "${padRight(server.rootDirectory, directoryLength)} " |
| 177 "on ${log.bold('http://$hostname:${server.port}')}"); | 178 "on ${log.bold('http://$hostname:${server.port}')}"); |
| 178 } | 179 } |
| 179 | 180 |
| 180 /// Reports [error] and exits the server. | 181 /// Reports [error] and exits the server. |
| 181 void _fatalError(error, [stackTrace]) { | 182 void _fatalError(error, [stackTrace]) { |
| 182 if (_completer.isCompleted) return; | 183 if (_completer.isCompleted) return; |
| 183 _completer.completeError(error, stackTrace); | 184 _completer.completeError(error, stackTrace); |
| 184 } | 185 } |
| 185 } | 186 } |
| OLD | NEW |