OLD | NEW |
| (Empty) |
1 #!/usr/bin/env dart | |
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 | |
4 // BSD-style license that can be found in the LICENSE file. | |
5 | |
6 /// Runs io.js with dev_compiler's generated code. | |
7 library dev_compiler.bin.devrun; | |
8 | |
9 import 'dart:io'; | |
10 | |
11 import 'package:dev_compiler/devc.dart' show devCompilerVersion; | |
12 import 'package:dev_compiler/src/compiler.dart' show validateOptions, compile; | |
13 import 'package:dev_compiler/src/options.dart'; | |
14 import 'package:dev_compiler/src/runner/runtime_utils.dart' | |
15 show listOutputFiles, getMainModuleName; | |
16 import 'package:dev_compiler/src/runner/v8_runner.dart' show V8Runner; | |
17 | |
18 import 'package:path/path.dart'; | |
19 | |
20 const String _appName = 'dartdevrun'; | |
21 | |
22 void _showUsageAndExit() { | |
23 print('usage: ${_appName} [<options>] <file.dart>\n'); | |
24 print('<file.dart> is a single Dart file to run.\n'); | |
25 print('<options> include:\n'); | |
26 print(argParser.usage); | |
27 exit(1); | |
28 } | |
29 | |
30 main(List<String> args) async { | |
31 CompilerOptions options; | |
32 | |
33 try { | |
34 options = validateOptions(args, forceOutDir: true); | |
35 } on FormatException catch (e) { | |
36 print('${e.message}\n'); | |
37 _showUsageAndExit(); | |
38 } | |
39 | |
40 if (options == null || options.help) _showUsageAndExit(); | |
41 if (options.version) { | |
42 print('${_appName} version ${devCompilerVersion}'); | |
43 exit(0); | |
44 } | |
45 | |
46 if (options.inputs.length != 1) { | |
47 stderr.writeln("Please only specify one input to run"); | |
48 _showUsageAndExit(); | |
49 } | |
50 var runner = new V8Runner(options); | |
51 | |
52 if (!compile(options)) exit(1); | |
53 | |
54 var files = await listOutputFiles(options); | |
55 var startStatement = 'dart_library.start("${getMainModuleName(options)}");'; | |
56 | |
57 // TODO(ochafik): Only generate the html when some flag is set. | |
58 await _writeHtmlRunner(options, files, startStatement); | |
59 | |
60 // Give our soul (and streams) away to iojs. | |
61 Process process = await runner.start(files, startStatement); | |
62 stdin.pipe(process.stdin); | |
63 stdout.addStream(process.stdout); | |
64 stderr.addStream(process.stderr); | |
65 exit(await process.exitCode); | |
66 } | |
67 | |
68 /// Generates an HTML file that can be used to run the output with Chrome Dev. | |
69 _writeHtmlRunner( | |
70 CompilerOptions options, List<File> files, String startStatement) async { | |
71 String outputDir = options.codegenOptions.outputDir; | |
72 String htmlOutput = join(outputDir, "run.html"); | |
73 await new File(htmlOutput).writeAsString(''' | |
74 <html><head></head><body> | |
75 ${files.map((f) => | |
76 '<script src="${relative(f.path, from: outputDir)}"></script>') | |
77 .join("\n")} | |
78 <script>$startStatement</script> | |
79 </body></html> | |
80 '''); | |
81 | |
82 stderr.writeln( | |
83 'Wrote $htmlOutput. It can be opened in Chrome Dev with the following flag
s:\n' | |
84 '--js-flags="--harmony-arrow-functions ' | |
85 '--harmony-classes ' | |
86 '--harmony-computed-property-names ' | |
87 '--harmony_destructuring ' | |
88 '--harmony-spreadcalls"' | |
89 '\n'); | |
90 } | |
OLD | NEW |