| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 command_lish; | 5 library command_lish; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:json'; | 9 import 'dart:json'; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // XML parser. | 80 // XML parser. |
| 81 throw 'Failed to upload the package.'; | 81 throw 'Failed to upload the package.'; |
| 82 } else if (url.origin == server.origin) { | 82 } else if (url.origin == server.origin) { |
| 83 handleJsonError(asyncError.error.response); | 83 handleJsonError(asyncError.error.response); |
| 84 } | 84 } |
| 85 }); | 85 }); |
| 86 } | 86 } |
| 87 | 87 |
| 88 Future onRun() { | 88 Future onRun() { |
| 89 var files; | 89 var files; |
| 90 return _filesToPublish.then((f) { | 90 var packageBytesFuture = _filesToPublish.then((f) { |
| 91 files = f; | 91 files = f; |
| 92 log.fine('Archiving and publishing ${entrypoint.root}.'); | 92 log.fine('Archiving and publishing ${entrypoint.root}.'); |
| 93 return createTarGz(files, baseDir: entrypoint.root.dir); | 93 return createTarGz(files, baseDir: entrypoint.root.dir); |
| 94 }).then(consumeInputStream).then((packageBytes) { | 94 }).then(consumeInputStream); |
| 95 // Show the package contents so the user can verify they look OK. | 95 |
| 96 var package = entrypoint.root; | 96 // Show the package contents so the user can verify they look OK. |
| 97 log.message( | 97 var package = entrypoint.root; |
| 98 'Publishing "${package.name}" ${package.version}:\n' | 98 log.message( |
| 99 '${generateTree(files)}'); | 99 'Publishing "${package.name}" ${package.version}:\n' |
| 100 '${generateTree(files)}'); |
| 100 | 101 |
| 101 // Validate the package. | 102 // Validate the package. |
| 102 return _validate().then((_) => _publish(packageBytes)); | 103 return _validate(packageBytesFuture.then((bytes) => bytes.length)) |
| 103 }); | 104 .then((_) => packageBytesFuture).then(_publish); |
| 104 } | 105 } |
| 105 | 106 |
| 106 /// The basenames of files that are automatically excluded from archives. | 107 /// The basenames of files that are automatically excluded from archives. |
| 107 final _BLACKLISTED_FILES = const ['pubspec.lock']; | 108 final _BLACKLISTED_FILES = const ['pubspec.lock']; |
| 108 | 109 |
| 109 /// The basenames of directories that are automatically excluded from | 110 /// The basenames of directories that are automatically excluded from |
| 110 /// archives. | 111 /// archives. |
| 111 final _BLACKLISTED_DIRECTORIES = const ['packages']; | 112 final _BLACKLISTED_DIRECTORIES = const ['packages']; |
| 112 | 113 |
| 113 /// Returns a list of files that should be included in the published package. | 114 /// Returns a list of files that should be included in the published package. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 153 } |
| 153 | 154 |
| 154 /// Returns the value associated with [key] in [map]. Throws a user-friendly | 155 /// Returns the value associated with [key] in [map]. Throws a user-friendly |
| 155 /// error if [map] doens't contain [key]. | 156 /// error if [map] doens't contain [key]. |
| 156 _expectField(Map map, String key, http.Response response) { | 157 _expectField(Map map, String key, http.Response response) { |
| 157 if (map.containsKey(key)) return map[key]; | 158 if (map.containsKey(key)) return map[key]; |
| 158 invalidServerResponse(response); | 159 invalidServerResponse(response); |
| 159 } | 160 } |
| 160 | 161 |
| 161 /// Validates the package. Throws an exception if it's invalid. | 162 /// Validates the package. Throws an exception if it's invalid. |
| 162 Future _validate() { | 163 Future _validate(Future<int> packageSize) { |
| 163 return Validator.runAll(entrypoint).then((pair) { | 164 return Validator.runAll(entrypoint, packageSize).then((pair) { |
| 164 var errors = pair.first; | 165 var errors = pair.first; |
| 165 var warnings = pair.last; | 166 var warnings = pair.last; |
| 166 | 167 |
| 167 if (!errors.isEmpty) { | 168 if (!errors.isEmpty) { |
| 168 throw "Sorry, your package is missing " | 169 throw "Sorry, your package is missing " |
| 169 "${(errors.length > 1) ? 'some requirements' : 'a requirement'} " | 170 "${(errors.length > 1) ? 'some requirements' : 'a requirement'} " |
| 170 "and can't be published yet.\nFor more information, see: " | 171 "and can't be published yet.\nFor more information, see: " |
| 171 "http://pub.dartlang.org/doc/pub-lish.html.\n"; | 172 "http://pub.dartlang.org/doc/pub-lish.html.\n"; |
| 172 } | 173 } |
| 173 | 174 |
| 174 var message = 'Looks great! Are you ready to upload your package'; | 175 var message = 'Looks great! Are you ready to upload your package'; |
| 175 | 176 |
| 176 if (!warnings.isEmpty) { | 177 if (!warnings.isEmpty) { |
| 177 var s = warnings.length == 1 ? '' : 's'; | 178 var s = warnings.length == 1 ? '' : 's'; |
| 178 message = "Package has ${warnings.length} warning$s. Upload anyway"; | 179 message = "Package has ${warnings.length} warning$s. Upload anyway"; |
| 179 } | 180 } |
| 180 | 181 |
| 181 return confirm(message).then((confirmed) { | 182 return confirm(message).then((confirmed) { |
| 182 if (!confirmed) throw "Package upload canceled."; | 183 if (!confirmed) throw "Package upload canceled."; |
| 183 }); | 184 }); |
| 184 }); | 185 }); |
| 185 } | 186 } |
| 186 } | 187 } |
| OLD | NEW |