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 | 8 |
9 import '../barback/dart_forwarding_transformer.dart'; | 9 import '../barback/dart_forwarding_transformer.dart'; |
10 import '../barback/dart2js_transformer.dart'; | 10 import '../barback/dart2js_transformer.dart'; |
(...skipping 13 matching lines...) Expand all Loading... |
24 String get description => "Run a local web development server."; | 24 String get description => "Run a local web development server."; |
25 String get usage => 'pub serve'; | 25 String get usage => 'pub serve'; |
26 | 26 |
27 PubPackageProvider _provider; | 27 PubPackageProvider _provider; |
28 | 28 |
29 String get hostname => commandOptions['hostname']; | 29 String get hostname => commandOptions['hostname']; |
30 | 30 |
31 /// `true` if Dart entrypoints should be compiled to JavaScript. | 31 /// `true` if Dart entrypoints should be compiled to JavaScript. |
32 bool get useDart2JS => commandOptions['dart2js']; | 32 bool get useDart2JS => commandOptions['dart2js']; |
33 | 33 |
| 34 /// `true` if generated JavaScript should be minified. |
| 35 bool get minify => commandOptions['minify']; |
| 36 |
34 ServeCommand() { | 37 ServeCommand() { |
35 commandParser.addOption('port', defaultsTo: '8080', | 38 commandParser.addOption('port', defaultsTo: '8080', |
36 help: 'The port to listen on.'); | 39 help: 'The port to listen on.'); |
37 | 40 |
38 // A hidden option for the tests to work around a bug in some of the OS X | 41 // A hidden option for the tests to work around a bug in some of the OS X |
39 // bots where "localhost" very rarely resolves to the IPv4 loopback address | 42 // bots where "localhost" very rarely resolves to the IPv4 loopback address |
40 // instead of IPv6 (or vice versa). The tests will always set this to | 43 // instead of IPv6 (or vice versa). The tests will always set this to |
41 // 127.0.0.1. | 44 // 127.0.0.1. |
42 commandParser.addOption('hostname', | 45 commandParser.addOption('hostname', |
43 defaultsTo: 'localhost', | 46 defaultsTo: 'localhost', |
44 hide: true); | 47 hide: true); |
45 | 48 |
46 commandParser.addFlag('dart2js', defaultsTo: true, | 49 commandParser.addFlag('dart2js', defaultsTo: true, |
47 help: 'Compile Dart to JavaScript.'); | 50 help: 'Compile Dart to JavaScript.'); |
| 51 |
| 52 commandParser.addFlag('minify', defaultsTo: false, |
| 53 help: 'Minify generated JavaScript.'); |
48 } | 54 } |
49 | 55 |
50 Future onRun() { | 56 Future onRun() { |
51 var port; | 57 var port; |
52 try { | 58 try { |
53 port = int.parse(commandOptions['port']); | 59 port = int.parse(commandOptions['port']); |
54 } on FormatException catch (_) { | 60 } on FormatException catch (_) { |
55 log.error('Could not parse port "${commandOptions['port']}"'); | 61 log.error('Could not parse port "${commandOptions['port']}"'); |
56 this.printUsage(); | 62 this.printUsage(); |
57 return flushThenExit(exit_codes.USAGE); | 63 return flushThenExit(exit_codes.USAGE); |
58 } | 64 } |
59 | 65 |
60 return entrypoint.ensureLockFileIsUpToDate().then((_) { | 66 return entrypoint.ensureLockFileIsUpToDate().then((_) { |
61 return entrypoint.loadPackageGraph(); | 67 return entrypoint.loadPackageGraph(); |
62 }).then((graph) { | 68 }).then((graph) { |
63 // TODO(rnystrom): Add support for dart2dart transformer here. | 69 // TODO(rnystrom): Add support for dart2dart transformer here. |
64 var builtInTransformers = null; | 70 var builtInTransformers = null; |
65 if (useDart2JS) { | 71 if (useDart2JS) { |
66 builtInTransformers = [ | 72 builtInTransformers = [ |
67 new Dart2JSTransformer(graph), | 73 new Dart2JSTransformer(graph, minify: minify), |
68 new DartForwardingTransformer() | 74 new DartForwardingTransformer() |
69 ]; | 75 ]; |
70 } | 76 } |
71 | 77 |
72 return barback.createServer(hostname, port, graph, | 78 return barback.createServer(hostname, port, graph, |
73 builtInTransformers: builtInTransformers); | 79 builtInTransformers: builtInTransformers); |
74 }).then((server) { | 80 }).then((server) { |
75 /// This completer is used to keep pub running (by not completing) and | 81 /// This completer is used to keep pub running (by not completing) and |
76 /// to pipe fatal errors to pub's top-level error-handling machinery. | 82 /// to pipe fatal errors to pub's top-level error-handling machinery. |
77 var completer = new Completer(); | 83 var completer = new Completer(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 if (!completer.isCompleted) completer.completeError(error, stackTrace); | 116 if (!completer.isCompleted) completer.completeError(error, stackTrace); |
111 }); | 117 }); |
112 | 118 |
113 log.message("Serving ${entrypoint.root.name} " | 119 log.message("Serving ${entrypoint.root.name} " |
114 "on http://$hostname:${server.port}"); | 120 "on http://$hostname:${server.port}"); |
115 | 121 |
116 return completer.future; | 122 return completer.future; |
117 }); | 123 }); |
118 } | 124 } |
119 } | 125 } |
OLD | NEW |