| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Command line tool to run the checker on a Dart program. | 5 /// Command line tool to run the checker on a Dart program. |
| 6 library dev_compiler.devc; | 6 library dev_compiler.devc; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 259 } |
| 260 var port = options.port; | 260 var port = options.port; |
| 261 _log.fine('Serving $entryPath at http://0.0.0.0:$port/'); | 261 _log.fine('Serving $entryPath at http://0.0.0.0:$port/'); |
| 262 var compiler = new Compiler(options); | 262 var compiler = new Compiler(options); |
| 263 return new CompilerServer._(compiler, outDir, port, entryPath); | 263 return new CompilerServer._(compiler, outDir, port, entryPath); |
| 264 } | 264 } |
| 265 | 265 |
| 266 CompilerServer._(this.compiler, this.outDir, this.port, this._entryPath); | 266 CompilerServer._(this.compiler, this.outDir, this.port, this._entryPath); |
| 267 | 267 |
| 268 Future start() async { | 268 Future start() async { |
| 269 // Create output directory if needed. shelf_static will fail otherwise. |
| 270 var out = new Directory(outDir); |
| 271 if (!await out.exists()) await out.create(recursive: true); |
| 272 |
| 269 var handler = const shelf.Pipeline() | 273 var handler = const shelf.Pipeline() |
| 270 .addMiddleware(rebuildAndCache) | 274 .addMiddleware(rebuildAndCache) |
| 271 .addHandler(shelf_static.createStaticHandler(outDir, | 275 .addHandler(shelf_static.createStaticHandler(outDir, |
| 272 defaultDocument: _entryPath)); | 276 defaultDocument: _entryPath)); |
| 273 await shelf.serve(handler, '0.0.0.0', port); | 277 await shelf.serve(handler, '0.0.0.0', port); |
| 274 compiler.run(); | 278 compiler.run(); |
| 275 } | 279 } |
| 276 | 280 |
| 277 shelf.Handler rebuildAndCache(shelf.Handler handler) => (request) { | 281 shelf.Handler rebuildAndCache(shelf.Handler handler) => (request) { |
| 278 _log.fine('requested $GREEN_COLOR${request.url}$NO_COLOR'); | 282 _log.fine('requested $GREEN_COLOR${request.url}$NO_COLOR'); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 298 // Note: the cache-control header should be enough, but this doesn't hurt | 302 // Note: the cache-control header should be enough, but this doesn't hurt |
| 299 // and can help renew the policy after it expires. | 303 // and can help renew the policy after it expires. |
| 300 headers['ETag'] = segments[1]; | 304 headers['ETag'] = segments[1]; |
| 301 } | 305 } |
| 302 return response.change(headers: headers); | 306 return response.change(headers: headers); |
| 303 }; | 307 }; |
| 304 } | 308 } |
| 305 | 309 |
| 306 final _log = new Logger('dev_compiler'); | 310 final _log = new Logger('dev_compiler'); |
| 307 final _earlyErrorResult = new CheckerResults(const [], null, true); | 311 final _earlyErrorResult = new CheckerResults(const [], null, true); |
| OLD | NEW |