OLD | NEW |
---|---|
1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
2 // Copyright (c) 2015, 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 /// Runs dev_compiler's checker, and optionally the code generator. | 6 /// Command line entry point for Dart Development Compiler (dartdevc). |
7 /// Also can run a server for local development. | 7 /// |
8 library dev_compiler.bin.dartdevc; | 8 /// Supported commands are |
9 /// * compile: builds a collection of dart libraries into a single JS module | |
10 /// | |
11 /// Additionally, these commands are being considered | |
12 /// * link: combines several JS modules into a single JS file | |
13 /// * build: compiles & links a set of code, automatically determining | |
14 /// appropriate groupings of libraries to combine into JS modules | |
15 /// * watch: watch a directory and recompile build units automatically | |
16 /// * serve: uses `watch` to recompile and exposes a simple static file server | |
17 /// for local development | |
18 /// | |
19 /// These commands are combined so we have less names to expose on the PATH, | |
20 /// and for development simplicity while the precise UI has not been determined. | |
21 /// | |
22 /// A more typical structure for web tools is simply to have the compiler with | |
23 /// "watch" as an option. The challenge for us is: | |
24 /// | |
25 /// * Dart used to assume whole-program compiles, so we don't have a | |
26 /// user-declared unit of building, and neither "libraries" or "packages" will | |
27 /// work, | |
28 /// * We do not assume a `node` JS installation, so we cannot easily reuse | |
29 /// existing tools such as for the "link" step, or assume users have a local | |
vsm
2016/04/14 00:18:24
such as ??? for link step?
Jennifer Messerly
2016/04/14 18:28:40
I was thinking of webpack: https://webpack.github.
| |
30 /// file server, | |
31 /// * We didn't have a file watcher API at first, | |
32 /// * We had no conventions about where compiled output should go (or even | |
33 /// that we would be compiling at all, vs running on an in-browser Dart VM), | |
34 /// * We wanted a good first impression with our simple examples, so we used | |
35 /// local file servers, and users have an expectation of it now, even though | |
36 /// it doesn't scale to typical apps that need their own real servers. | |
9 | 37 |
10 import 'dart:io'; | 38 import 'dart:io'; |
39 import 'package:args/command_runner.dart'; | |
40 import 'package:dev_compiler/src/compiler/command.dart'; | |
11 | 41 |
12 import 'package:dev_compiler/devc.dart' show devCompilerVersion; | 42 main(List<String> args) async { |
13 import 'package:dev_compiler/src/compiler.dart' | 43 var runner = new CommandRunner('dartdevc', 'Dart Development Compiler'); |
14 show validateOptions, compile, setupLogger; | 44 runner.addCommand(new CompileCommand()); |
15 import 'package:dev_compiler/src/options.dart'; | 45 try { |
16 | 46 await runner.run(args); |
17 const String _appName = 'dartdevc'; | 47 } on UsageException catch (e) { |
18 | 48 // Incorrect usage, input file not found, etc. |
19 void _showUsageAndExit() { | 49 print(e); |
20 print('usage: dartdevc [<options>] <file.dart>...\n'); | 50 exit(64); |
21 print('<file.dart> is one or more Dart files to process.\n'); | 51 } on CompileErrorException catch (e) { |
22 print('<options> include:\n'); | 52 // Code has error(s) and failed to compile. |
23 print(argParser.usage); | 53 print(e); |
24 exit(1); | 54 exit(1); |
55 } catch (e, s) { | |
56 // Anything else is likely a compiler bug. | |
57 // | |
58 // --unsafe-force-compile is a bit of a grey area, but it's nice not to | |
59 // crash while compiling | |
60 // (of course, output code may crash, if it had errors). | |
61 // | |
62 print(""); | |
63 print("We're sorry, you've found a bug in our compiler."); | |
64 print("You can report this bug at:"); | |
65 print(" https://github.com/dart-lang/dev_compiler/issues"); | |
66 print(""); | |
67 print("Please include the information below in your report, along with"); | |
68 print("any other information that may help us track it down. Thanks!"); | |
69 print(""); | |
70 print(" dartdevc arguments: " + args.join(' ')); | |
71 print(" dart --version: ${Platform.version}"); | |
72 print(""); | |
73 print("```"); | |
74 print(e); | |
75 print(s); | |
76 print("```"); | |
77 } | |
25 } | 78 } |
26 | |
27 main(List<String> args) { | |
28 var options; | |
29 | |
30 try { | |
31 options = validateOptions(args); | |
32 } on FormatException catch (e) { | |
33 print('${e.message}\n'); | |
34 _showUsageAndExit(); | |
35 } | |
36 | |
37 if (options == null || options.help) _showUsageAndExit(); | |
38 if (options.version) { | |
39 print('${_appName} version ${devCompilerVersion}'); | |
40 exit(0); | |
41 } | |
42 | |
43 setupLogger(options.logLevel, print); | |
44 bool success = compile(options); | |
45 exit(success ? 0 : 1); | |
46 } | |
OLD | NEW |