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) 2015, 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 /// Runs dev_compiler's checker, and optionally the code generator. |
7 /// Also can run a server for local development. | 7 /// Also can run a server for local development. |
8 library dev_compiler.bin.dartdevc; | 8 library dev_compiler.bin.dartdevc; |
9 | 9 |
10 import 'dart:io'; | 10 import 'dart:io'; |
11 | 11 |
12 import 'package:dev_compiler/devc.dart' show devCompilerVersion; | 12 import 'package:dev_compiler/devc.dart' show devCompilerVersion; |
13 import 'package:dev_compiler/src/compiler.dart' | 13 import 'package:dev_compiler/src/compiler.dart' |
14 show validateOptions, compile, setupLogger; | 14 show validateOptions, compile, setupLogger; |
15 import 'package:dev_compiler/src/options.dart'; | 15 import 'package:dev_compiler/src/options.dart'; |
16 import 'package:dev_compiler/src/server/server.dart' show DevServer; | |
17 | 16 |
18 const String _appName = 'dartdevc'; | 17 const String _appName = 'dartdevc'; |
19 | 18 |
20 void _showUsageAndExit() { | 19 void _showUsageAndExit() { |
21 print('usage: dartdevc [<options>] <file.dart>...\n'); | 20 print('usage: dartdevc [<options>] <file.dart>...\n'); |
22 print('<file.dart> is one or more Dart files to process.\n'); | 21 print('<file.dart> is one or more Dart files to process.\n'); |
23 print('<options> include:\n'); | 22 print('<options> include:\n'); |
24 print(argParser.usage); | 23 print(argParser.usage); |
25 exit(1); | 24 exit(1); |
26 } | 25 } |
27 | 26 |
28 main(List<String> args) { | 27 main(List<String> args) { |
29 var options; | 28 var options; |
30 | 29 |
31 try { | 30 try { |
32 options = validateOptions(args); | 31 options = validateOptions(args); |
33 } on FormatException catch (e) { | 32 } on FormatException catch (e) { |
34 print('${e.message}\n'); | 33 print('${e.message}\n'); |
35 _showUsageAndExit(); | 34 _showUsageAndExit(); |
36 } | 35 } |
37 | 36 |
38 if (options == null || options.help) _showUsageAndExit(); | 37 if (options == null || options.help) _showUsageAndExit(); |
39 if (options.version) { | 38 if (options.version) { |
40 print('${_appName} version ${devCompilerVersion}'); | 39 print('${_appName} version ${devCompilerVersion}'); |
41 exit(0); | 40 exit(0); |
42 } | 41 } |
43 | 42 |
44 setupLogger(options.logLevel, print); | 43 setupLogger(options.logLevel, print); |
45 | 44 bool success = compile(options); |
46 if (options.serverMode) { | 45 exit(success ? 0 : 1); |
47 new DevServer(options).start(); | |
48 } else { | |
49 exit(compile(options) ? 0 : 1); | |
50 } | |
51 } | 46 } |
OLD | NEW |