| 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 298   Future start() async { | 298   Future start() async { | 
| 299     // Create output directory if needed. shelf_static will fail otherwise. | 299     // Create output directory if needed. shelf_static will fail otherwise. | 
| 300     var out = new Directory(outDir); | 300     var out = new Directory(outDir); | 
| 301     if (!await out.exists()) await out.create(recursive: true); | 301     if (!await out.exists()) await out.create(recursive: true); | 
| 302 | 302 | 
| 303     var handler = const shelf.Pipeline() | 303     var handler = const shelf.Pipeline() | 
| 304         .addMiddleware(rebuildAndCache) | 304         .addMiddleware(rebuildAndCache) | 
| 305         .addHandler(shelf_static.createStaticHandler(outDir, | 305         .addHandler(shelf_static.createStaticHandler(outDir, | 
| 306             defaultDocument: _entryPath)); | 306             defaultDocument: _entryPath)); | 
| 307     await shelf.serve(handler, host, port); | 307     await shelf.serve(handler, host, port); | 
| 308     _log.fine('Serving $_entryPath at http://$host:$port/'); | 308     print('Serving $_entryPath at http://$host:$port/'); | 
| 309     compiler.run(); | 309     compiler.run(); | 
| 310   } | 310   } | 
| 311 | 311 | 
| 312   shelf.Handler rebuildAndCache(shelf.Handler handler) => (request) { | 312   shelf.Handler rebuildAndCache(shelf.Handler handler) => (request) { | 
| 313     _log.fine('requested $GREEN_COLOR${request.url}$NO_COLOR'); | 313     print('requested $GREEN_COLOR${request.url}$NO_COLOR'); | 
| 314     // Trigger recompile only when requesting the HTML page. | 314     // Trigger recompile only when requesting the HTML page. | 
| 315     var segments = request.url.pathSegments; | 315     var segments = request.url.pathSegments; | 
| 316     bool isEntryPage = segments.length == 0 || segments[0] == _entryPath; | 316     bool isEntryPage = segments.length == 0 || segments[0] == _entryPath; | 
| 317     if (isEntryPage) compiler._runAgain(); | 317     if (isEntryPage) compiler._runAgain(); | 
| 318 | 318 | 
| 319     // To help browsers cache resources that don't change, we serve these | 319     // To help browsers cache resources that don't change, we serve these | 
| 320     // resources by adding a query parameter containing their hash: | 320     // resources by adding a query parameter containing their hash: | 
| 321     //    /{path-to-file.js}?____cached={hash} | 321     //    /{path-to-file.js}?____cached={hash} | 
| 322     var hash = request.url.queryParameters['____cached']; | 322     var hash = request.url.queryParameters['____cached']; | 
| 323     var response = handler(request); | 323     var response = handler(request); | 
| 324     var policy = hash != null ? 'max-age=${24 * 60 * 60}' : 'no-cache'; | 324     var policy = hash != null ? 'max-age=${24 * 60 * 60}' : 'no-cache'; | 
| 325     var headers = {'cache-control': policy}; | 325     var headers = {'cache-control': policy}; | 
| 326     if (hash != null) { | 326     if (hash != null) { | 
| 327       // Note: the cache-control header should be enough, but this doesn't hurt | 327       // Note: the cache-control header should be enough, but this doesn't hurt | 
| 328       // and can help renew the policy after it expires. | 328       // and can help renew the policy after it expires. | 
| 329       headers['ETag'] = hash; | 329       headers['ETag'] = hash; | 
| 330     } | 330     } | 
| 331     return response.change(headers: headers); | 331     return response.change(headers: headers); | 
| 332   }; | 332   }; | 
| 333 } | 333 } | 
| 334 | 334 | 
| 335 final _log = new Logger('dev_compiler'); | 335 final _log = new Logger('dev_compiler'); | 
| 336 final _earlyErrorResult = new CheckerResults(const [], null, true); | 336 final _earlyErrorResult = new CheckerResults(const [], null, true); | 
| OLD | NEW | 
|---|