| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 254 |
| 255 // TODO(sigmund): allow running without a dir, but keep output in memory? | 255 // TODO(sigmund): allow running without a dir, but keep output in memory? |
| 256 var outDir = options.outputDir; | 256 var outDir = options.outputDir; |
| 257 if (outDir == null) { | 257 if (outDir == null) { |
| 258 print('error: devc in server mode also requires specifying and ' | 258 print('error: devc in server mode also requires specifying and ' |
| 259 'output location for generated code.'); | 259 'output location for generated code.'); |
| 260 exit(1); | 260 exit(1); |
| 261 } | 261 } |
| 262 var port = options.port; | 262 var port = options.port; |
| 263 var host = options.host; | 263 var host = options.host; |
| 264 _log.fine('Serving $entryPath at http://$host:$port/'); | |
| 265 var compiler = new Compiler(options); | 264 var compiler = new Compiler(options); |
| 266 return new CompilerServer._(compiler, outDir, host, port, entryPath); | 265 return new CompilerServer._(compiler, outDir, host, port, entryPath); |
| 267 } | 266 } |
| 268 | 267 |
| 269 CompilerServer._( | 268 CompilerServer._( |
| 270 this.compiler, this.outDir, this.host, this.port, this._entryPath); | 269 this.compiler, this.outDir, this.host, this.port, this._entryPath); |
| 271 | 270 |
| 272 Future start() async { | 271 Future start() async { |
| 273 // Create output directory if needed. shelf_static will fail otherwise. | 272 // Create output directory if needed. shelf_static will fail otherwise. |
| 274 var out = new Directory(outDir); | 273 var out = new Directory(outDir); |
| 275 if (!await out.exists()) await out.create(recursive: true); | 274 if (!await out.exists()) await out.create(recursive: true); |
| 276 | 275 |
| 277 var handler = const shelf.Pipeline() | 276 var handler = const shelf.Pipeline() |
| 278 .addMiddleware(rebuildAndCache) | 277 .addMiddleware(rebuildAndCache) |
| 279 .addHandler(shelf_static.createStaticHandler(outDir, | 278 .addHandler(shelf_static.createStaticHandler(outDir, |
| 280 defaultDocument: _entryPath)); | 279 defaultDocument: _entryPath)); |
| 281 await shelf.serve(handler, host, port); | 280 await shelf.serve(handler, host, port); |
| 281 _log.fine('Serving $_entryPath at http://$host:$port/'); |
| 282 compiler.run(); | 282 compiler.run(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 shelf.Handler rebuildAndCache(shelf.Handler handler) => (request) { | 285 shelf.Handler rebuildAndCache(shelf.Handler handler) => (request) { |
| 286 _log.fine('requested $GREEN_COLOR${request.url}$NO_COLOR'); | 286 _log.fine('requested $GREEN_COLOR${request.url}$NO_COLOR'); |
| 287 // Trigger recompile only when requesting the HTML page. | 287 // Trigger recompile only when requesting the HTML page. |
| 288 var segments = request.url.pathSegments; | 288 var segments = request.url.pathSegments; |
| 289 bool isEntryPage = segments.length == 0 || segments[0] == _entryPath; | 289 bool isEntryPage = segments.length == 0 || segments[0] == _entryPath; |
| 290 if (isEntryPage) compiler._runAgain(); | 290 if (isEntryPage) compiler._runAgain(); |
| 291 | 291 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 306 // Note: the cache-control header should be enough, but this doesn't hurt | 306 // Note: the cache-control header should be enough, but this doesn't hurt |
| 307 // and can help renew the policy after it expires. | 307 // and can help renew the policy after it expires. |
| 308 headers['ETag'] = segments[1]; | 308 headers['ETag'] = segments[1]; |
| 309 } | 309 } |
| 310 return response.change(headers: headers); | 310 return response.change(headers: headers); |
| 311 }; | 311 }; |
| 312 } | 312 } |
| 313 | 313 |
| 314 final _log = new Logger('dev_compiler'); | 314 final _log = new Logger('dev_compiler'); |
| 315 final _earlyErrorResult = new CheckerResults(const [], null, true); | 315 final _earlyErrorResult = new CheckerResults(const [], null, true); |
| OLD | NEW |