| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library pub.command.list_package_dirs; | 5 library pub.command.list_package_dirs; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; |
| 8 import 'dart:io'; | 9 import 'dart:io'; |
| 9 import 'dart:json' as json; | |
| 10 | 10 |
| 11 import 'package:path/path.dart' as path; | 11 import 'package:path/path.dart' as path; |
| 12 | 12 |
| 13 import '../command.dart'; | 13 import '../command.dart'; |
| 14 import '../exit_codes.dart' as exit_codes; | 14 import '../exit_codes.dart' as exit_codes; |
| 15 import '../log.dart' as log; | 15 import '../log.dart' as log; |
| 16 | 16 |
| 17 /// Handles the `list-package-dirs` pub command. | 17 /// Handles the `list-package-dirs` pub command. |
| 18 class ListPackageDirsCommand extends PubCommand { | 18 class ListPackageDirsCommand extends PubCommand { |
| 19 String get description => "Print local paths to dependencies."; | 19 String get description => "Print local paths to dependencies."; |
| 20 String get usage => "pub list-package-dirs"; | 20 String get usage => "pub list-package-dirs"; |
| 21 bool get hidden => true; | 21 bool get hidden => true; |
| 22 | 22 |
| 23 ListPackageDirsCommand() { | 23 ListPackageDirsCommand() { |
| 24 commandParser.addOption("format", | 24 commandParser.addOption("format", |
| 25 help: "How output should be displayed.", | 25 help: "How output should be displayed.", |
| 26 allowed: ["json"]); | 26 allowed: ["json"]); |
| 27 } | 27 } |
| 28 | 28 |
| 29 Future onRun() { | 29 Future onRun() { |
| 30 if (!entrypoint.lockFileExists) { | 30 if (!entrypoint.lockFileExists) { |
| 31 log.error(json.stringify( | 31 log.error(JSON.encode( |
| 32 'Package "myapp" has no lockfile. Please run "pub install" first.')); | 32 'Package "myapp" has no lockfile. Please run "pub install" first.')); |
| 33 exit(exit_codes.NO_INPUT); | 33 exit(exit_codes.NO_INPUT); |
| 34 } | 34 } |
| 35 | 35 |
| 36 var output = {}; | 36 var output = {}; |
| 37 | 37 |
| 38 // Include the local paths to all locked packages. | 38 // Include the local paths to all locked packages. |
| 39 var packages = {}; | 39 var packages = {}; |
| 40 var futures = []; | 40 var futures = []; |
| 41 entrypoint.loadLockFile().packages.forEach((name, package) { | 41 entrypoint.loadLockFile().packages.forEach((name, package) { |
| 42 var source = entrypoint.cache.sources[package.source]; | 42 var source = entrypoint.cache.sources[package.source]; |
| 43 futures.add(source.getDirectory(package).then((packageDir) { | 43 futures.add(source.getDirectory(package).then((packageDir) { |
| 44 packages[name] = path.join(packageDir, "lib"); | 44 packages[name] = path.join(packageDir, "lib"); |
| 45 })); | 45 })); |
| 46 }); | 46 }); |
| 47 | 47 |
| 48 output["packages"] = packages; | 48 output["packages"] = packages; |
| 49 | 49 |
| 50 // Include the self link. | 50 // Include the self link. |
| 51 packages[entrypoint.root.name] = path.join(entrypoint.root.dir, "lib"); | 51 packages[entrypoint.root.name] = path.join(entrypoint.root.dir, "lib"); |
| 52 | 52 |
| 53 // Include the file(s) which when modified will affect the results. For pub, | 53 // Include the file(s) which when modified will affect the results. For pub, |
| 54 // that's just the lockfile. | 54 // that's just the lockfile. |
| 55 output["input_files"] = [entrypoint.lockFilePath]; | 55 output["input_files"] = [entrypoint.lockFilePath]; |
| 56 | 56 |
| 57 return Future.wait(futures).then((_) { | 57 return Future.wait(futures).then((_) { |
| 58 log.message(json.stringify(output)); | 58 log.message(JSON.encode(output)); |
| 59 }); | 59 }); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| OLD | NEW |