| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:io'; | 5 import 'dart:io'; |
| 6 import 'package:analyzer/src/generated/source.dart' show Source; | 6 import 'package:analyzer/src/generated/source.dart' show Source; |
| 7 import 'package:analyzer/src/summary/package_bundle_reader.dart' | 7 import 'package:analyzer/src/summary/package_bundle_reader.dart' |
| 8 show InSummarySource; | 8 show InSummarySource; |
| 9 import 'package:args/args.dart' show ArgParser, ArgResults; | 9 import 'package:args/args.dart' show ArgParser, ArgResults; |
| 10 import 'package:args/command_runner.dart' show UsageException; | 10 import 'package:args/command_runner.dart' show UsageException; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 void _compile(ArgResults argResults, void printFn(Object obj)) { | 84 void _compile(ArgResults argResults, void printFn(Object obj)) { |
| 85 var compiler = | 85 var compiler = |
| 86 new ModuleCompiler(new AnalyzerOptions.fromArguments(argResults)); | 86 new ModuleCompiler(new AnalyzerOptions.fromArguments(argResults)); |
| 87 var compilerOpts = new CompilerOptions.fromArguments(argResults); | 87 var compilerOpts = new CompilerOptions.fromArguments(argResults); |
| 88 if (argResults['help']) { | 88 if (argResults['help']) { |
| 89 printFn(_usageMessage); | 89 printFn(_usageMessage); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 var outPaths = argResults['out'] as List<String>; | 92 var outPaths = argResults['out'] as List<String>; |
| 93 var moduleFormats = parseModuleFormatOption(argResults); | 93 var moduleFormats = parseModuleFormatOption(argResults); |
| 94 bool singleOutFile = argResults['single-out-file']; |
| 95 if (singleOutFile) { |
| 96 for (var format in moduleFormats) { |
| 97 if (format != ModuleFormat.amd && format != ModuleFormat.legacy) { |
| 98 _usageException('Format $format cannot be combined with ' |
| 99 'single-out-file. Only amd and legacy modes are supported.'); |
| 100 } |
| 101 } |
| 102 } |
| 94 | 103 |
| 95 if (outPaths.isEmpty) { | 104 if (outPaths.isEmpty) { |
| 96 _usageException('Please include the output file location. For example:\n' | 105 _usageException('Please include the output file location. For example:\n' |
| 97 ' -o PATH/TO/OUTPUT_FILE.js'); | 106 ' -o PATH/TO/OUTPUT_FILE.js'); |
| 98 } else if (outPaths.length != moduleFormats.length) { | 107 } else if (outPaths.length != moduleFormats.length) { |
| 99 _usageException('Number of output files (${outPaths.length}) must match ' | 108 _usageException('Number of output files (${outPaths.length}) must match ' |
| 100 'number of module formats (${moduleFormats.length}).'); | 109 'number of module formats (${moduleFormats.length}).'); |
| 101 } | 110 } |
| 102 | 111 |
| 103 // TODO(jmesserly): for now the first one is special. This will go away once | 112 // TODO(jmesserly): for now the first one is special. This will go away once |
| (...skipping 26 matching lines...) Expand all Loading... |
| 130 (source) => _moduleForLibrary(moduleRoot, source, compilerOpts)); | 139 (source) => _moduleForLibrary(moduleRoot, source, compilerOpts)); |
| 131 | 140 |
| 132 var module = compiler.compile(unit, compilerOpts); | 141 var module = compiler.compile(unit, compilerOpts); |
| 133 module.errors.forEach(printFn); | 142 module.errors.forEach(printFn); |
| 134 | 143 |
| 135 if (!module.isValid) throw new CompileErrorException(); | 144 if (!module.isValid) throw new CompileErrorException(); |
| 136 | 145 |
| 137 // Write JS file, as well as source map and summary (if requested). | 146 // Write JS file, as well as source map and summary (if requested). |
| 138 for (var i = 0; i < outPaths.length; i++) { | 147 for (var i = 0; i < outPaths.length; i++) { |
| 139 var outPath = outPaths[i]; | 148 var outPath = outPaths[i]; |
| 140 module.writeCodeSync(moduleFormats[i], outPath); | 149 module.writeCodeSync(moduleFormats[i], singleOutFile, outPath); |
| 141 if (module.summaryBytes != null) { | 150 if (module.summaryBytes != null) { |
| 142 var summaryPath = | 151 var summaryPath = |
| 143 path.withoutExtension(outPath) + '.${compilerOpts.summaryExtension}'; | 152 path.withoutExtension(outPath) + '.${compilerOpts.summaryExtension}'; |
| 144 new File(summaryPath).writeAsBytesSync(module.summaryBytes); | 153 new File(summaryPath).writeAsBytesSync(module.summaryBytes); |
| 145 } | 154 } |
| 146 } | 155 } |
| 147 } | 156 } |
| 148 | 157 |
| 149 String _moduleForLibrary( | 158 String _moduleForLibrary( |
| 150 String moduleRoot, Source source, CompilerOptions compilerOpts) { | 159 String moduleRoot, Source source, CompilerOptions compilerOpts) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 173 '\n\n${_argParser.usage}'; | 182 '\n\n${_argParser.usage}'; |
| 174 | 183 |
| 175 void _usageException(String message) { | 184 void _usageException(String message) { |
| 176 throw new UsageException(message, _usageMessage); | 185 throw new UsageException(message, _usageMessage); |
| 177 } | 186 } |
| 178 | 187 |
| 179 /// Thrown when the input source code has errors. | 188 /// Thrown when the input source code has errors. |
| 180 class CompileErrorException implements Exception { | 189 class CompileErrorException implements Exception { |
| 181 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; | 190 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; |
| 182 } | 191 } |
| OLD | NEW |