| 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:convert' show JSON; | 5 import 'dart:convert' show JSON; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 import 'package:args/command_runner.dart'; | 7 import 'package:args/command_runner.dart'; |
| 8 import 'package:analyzer/src/generated/source.dart' show Source; | 8 import 'package:analyzer/src/generated/source.dart' show Source; |
| 9 import 'package:analyzer/src/summary/package_bundle_reader.dart' | 9 import 'package:analyzer/src/summary/package_bundle_reader.dart' |
| 10 show InSummarySource; | 10 show InSummarySource; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 usageException('Output file $outPath must be within the module root ' | 65 usageException('Output file $outPath must be within the module root ' |
| 66 'directory $moduleRoot'); | 66 'directory $moduleRoot'); |
| 67 } | 67 } |
| 68 modulePath = | 68 modulePath = |
| 69 path.withoutExtension(path.relative(outPath, from: moduleRoot)); | 69 path.withoutExtension(path.relative(outPath, from: moduleRoot)); |
| 70 } else { | 70 } else { |
| 71 moduleRoot = path.dirname(outPath); | 71 moduleRoot = path.dirname(outPath); |
| 72 modulePath = path.basenameWithoutExtension(outPath); | 72 modulePath = path.basenameWithoutExtension(outPath); |
| 73 } | 73 } |
| 74 | 74 |
| 75 if (argResults.rest.isEmpty) { | |
| 76 usageException('Please pass at least one source file as an argument.'); | |
| 77 } | |
| 78 | |
| 79 var unit = new BuildUnit(modulePath, libraryRoot, argResults.rest, | 75 var unit = new BuildUnit(modulePath, libraryRoot, argResults.rest, |
| 80 (source) => _moduleForLibrary(moduleRoot, source)); | 76 (source) => _moduleForLibrary(moduleRoot, source)); |
| 81 | 77 |
| 82 JSModuleFile module = compiler.compile(unit, _compilerOptions); | 78 JSModuleFile module = compiler.compile(unit, _compilerOptions); |
| 83 module.errors.forEach(messageHandler); | 79 module.errors.forEach(messageHandler); |
| 84 | 80 |
| 85 if (!module.isValid) throw new CompileErrorException(); | 81 if (!module.isValid) throw new CompileErrorException(); |
| 86 | 82 |
| 87 // Write JS file, as well as source map and summary (if requested). | 83 // Write JS file, as well as source map and summary (if requested). |
| 88 new File(outPath).writeAsStringSync(module.code); | 84 new File(outPath).writeAsStringSync(module.code); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 117 'Imported file "${source.uri}" was not found as a summary or source ' | 113 'Imported file "${source.uri}" was not found as a summary or source ' |
| 118 'file. Please pass in either the summary or the source file ' | 114 'file. Please pass in either the summary or the source file ' |
| 119 'for this import.'); | 115 'for this import.'); |
| 120 } | 116 } |
| 121 } | 117 } |
| 122 | 118 |
| 123 /// Thrown when the input source code has errors. | 119 /// Thrown when the input source code has errors. |
| 124 class CompileErrorException implements Exception { | 120 class CompileErrorException implements Exception { |
| 125 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; | 121 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; |
| 126 } | 122 } |
| OLD | NEW |