| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 /// Command line entry point for Dart Development Compiler (dartdevc). | 6 /// Command line entry point for Dart Development Compiler (dartdevc). |
| 7 /// | 7 /// |
| 8 /// Supported commands are | 8 /// Supported commands are |
| 9 /// * compile: builds a collection of dart libraries into a single JS module | 9 /// * compile: builds a collection of dart libraries into a single JS module |
| 10 /// | 10 /// |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 library dev_compiler.web.main; | 39 library dev_compiler.web.main; |
| 40 | 40 |
| 41 import 'dart:async'; | 41 import 'dart:async'; |
| 42 | 42 |
| 43 import 'package:args/command_runner.dart'; | 43 import 'package:args/command_runner.dart'; |
| 44 import 'package:js/js.dart'; | 44 import 'package:js/js.dart'; |
| 45 | 45 |
| 46 import 'web_command.dart'; | 46 import 'web_command.dart'; |
| 47 | 47 |
| 48 @JS() | 48 @JS() |
| 49 external set compileDartExpression(Function function); | 49 external set setUpCompilerInBrowser(Function function); |
| 50 | |
| 51 typedef String CompileFn(String dart); | |
| 52 typedef void OnLoadFn(CompileFn compile); | |
| 53 | 50 |
| 54 Future main() async { | 51 Future main() async { |
| 55 var args = ['compile']; | 52 var args = ['compile']; |
| 56 _runCommand((result) { | 53 _runCommand(args); |
| 57 compileDartExpression = allowInterop(result); | |
| 58 }, args); | |
| 59 } | 54 } |
| 60 | 55 |
| 61 /// Runs a single compile command, and returns an exit code. | 56 /// Runs a single compile command, and returns an exit code. |
| 62 Future<int> _runCommand(OnLoadFn onload, List<String> args, | 57 Future<int> _runCommand(List<String> args, |
| 63 {MessageHandler messageHandler}) async { | 58 {MessageHandler messageHandler}) async { |
| 64 try { | 59 try { |
| 60 // TODO: Remove CommandRunner and args if possible. May run into issues |
| 61 // with ArgResults or ArgParsers. |
| 65 var runner = new CommandRunner('dartdevc', 'Dart Development Compiler'); | 62 var runner = new CommandRunner('dartdevc', 'Dart Development Compiler'); |
| 66 runner | 63 runner.addCommand(new WebCompileCommand(messageHandler: messageHandler)); |
| 67 .addCommand(new WebCompileCommand(onload, messageHandler: messageHandler
)); | 64 setUpCompilerInBrowser = allowInterop(await runner.run(args)); |
| 68 await runner.run(args); | |
| 69 } catch (e, s) { | 65 } catch (e, s) { |
| 70 return _handleError(e, s, args, messageHandler: messageHandler); | 66 return _handleError(e, s, args, messageHandler: messageHandler); |
| 71 } | 67 } |
| 72 return 1; | 68 return 1; |
| 73 } | 69 } |
| 74 | 70 |
| 75 /// Handles [error] in a uniform fashion. Returns the proper exit code and calls | 71 /// Handles [error] in a uniform fashion. Returns the proper exit code and calls |
| 76 /// [messageHandler] with messages. | 72 /// [messageHandler] with messages. |
| 77 int _handleError(dynamic error, dynamic stackTrace, List<String> args, | 73 int _handleError(dynamic error, dynamic stackTrace, List<String> args, |
| 78 {MessageHandler messageHandler}) { | 74 {MessageHandler messageHandler}) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 105 messageHandler(""); | 101 messageHandler(""); |
| 106 messageHandler(" dartdevc arguments: " + args.join(' ')); | 102 messageHandler(" dartdevc arguments: " + args.join(' ')); |
| 107 messageHandler(""); | 103 messageHandler(""); |
| 108 messageHandler("```"); | 104 messageHandler("```"); |
| 109 messageHandler(error); | 105 messageHandler(error); |
| 110 messageHandler(stackTrace); | 106 messageHandler(stackTrace); |
| 111 messageHandler("```"); | 107 messageHandler("```"); |
| 112 return 70; | 108 return 70; |
| 113 } | 109 } |
| 114 } | 110 } |
| OLD | NEW |