| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:math' as math; | 6 import 'dart:math' as math; |
| 7 | 7 |
| 8 import 'package:barback/barback.dart'; | 8 import 'package:barback/barback.dart'; |
| 9 | 9 |
| 10 import '../barback/asset_environment.dart'; | 10 import '../barback/asset_environment.dart'; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // been compiled to JavaScript already. | 143 // been compiled to JavaScript already. |
| 144 if (mode == BarbackMode.RELEASE) { | 144 if (mode == BarbackMode.RELEASE) { |
| 145 server.allowAsset = (url) => !url.path.endsWith(".dart"); | 145 server.allowAsset = (url) => !url.path.endsWith(".dart"); |
| 146 } | 146 } |
| 147 | 147 |
| 148 // Add two characters to account for "[" and "]". | 148 // Add two characters to account for "[" and "]". |
| 149 var directory = log.gray( | 149 var directory = log.gray( |
| 150 padRight("[${server.rootDirectory}]", directoryLength + 2)); | 150 padRight("[${server.rootDirectory}]", directoryLength + 2)); |
| 151 | 151 |
| 152 server.results.listen((result) { | 152 server.results.listen((result) { |
| 153 if (result.isSuccess) { | 153 if (result.isCached) { |
| 154 var prefix = "$directory ${log.green('GET')}"; |
| 155 log.collapsible( |
| 156 "$prefix ${result.url.path} $_arrow (cached) ${result.id}", |
| 157 "$prefix Served ## cached assets."); |
| 158 } else if (result.isSuccess) { |
| 154 var prefix = "$directory ${log.green('GET')}"; | 159 var prefix = "$directory ${log.green('GET')}"; |
| 155 log.collapsible("$prefix ${result.url.path} $_arrow ${result.id}", | 160 log.collapsible("$prefix ${result.url.path} $_arrow ${result.id}", |
| 156 "$prefix Served ## assets."); | 161 "$prefix Served ## assets."); |
| 157 } else { | 162 } else { |
| 158 var buffer = new StringBuffer(); | 163 var buffer = new StringBuffer(); |
| 159 buffer.write("$directory ${log.red('GET')} ${result.url.path} $_arrow"); | 164 buffer.write("$directory ${log.red('GET')} ${result.url.path} $_arrow"); |
| 160 | 165 |
| 161 var error = result.error.toString(); | 166 var error = result.error.toString(); |
| 162 if (error.contains("\n")) { | 167 if (error.contains("\n")) { |
| 163 buffer.write("\n${prefixLines(error)}"); | 168 buffer.write("\n${prefixLines(error)}"); |
| 164 } else { | 169 } else { |
| 165 buffer.write(" $error"); | 170 buffer.write(" $error"); |
| 166 } | 171 } |
| 167 | 172 |
| 168 log.error(buffer); | 173 log.error(buffer); |
| 169 } | 174 } |
| 170 }, onError: _fatalError); | 175 }, onError: _fatalError); |
| 171 | 176 |
| 172 log.message("Serving ${entrypoint.root.name} " | 177 log.message("Serving ${entrypoint.root.name} " |
| 173 "${padRight(server.rootDirectory, directoryLength)} " | 178 "${padRight(server.rootDirectory, directoryLength)} " |
| 174 "on ${log.bold('http://$hostname:${server.port}')}"); | 179 "on ${log.bold('http://$hostname:${server.port}')}"); |
| 175 } | 180 } |
| 176 | 181 |
| 177 /// Reports [error] and exits the server. | 182 /// Reports [error] and exits the server. |
| 178 void _fatalError(error, [stackTrace]) { | 183 void _fatalError(error, [stackTrace]) { |
| 179 if (_completer.isCompleted) return; | 184 if (_completer.isCompleted) return; |
| 180 _completer.completeError(error, stackTrace); | 185 _completer.completeError(error, stackTrace); |
| 181 } | 186 } |
| 182 } | 187 } |
| OLD | NEW |