| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // Validate the package. | 102 // Validate the package. |
| 103 return _validate(packageBytesFuture.then((bytes) => bytes.length)) | 103 return _validate(packageBytesFuture.then((bytes) => bytes.length)) |
| 104 .then((_) => packageBytesFuture).then(_publish); | 104 .then((_) => packageBytesFuture).then(_publish); |
| 105 } | 105 } |
| 106 | 106 |
| 107 /// The basenames of files that are automatically excluded from archives. | 107 /// The basenames of files that are automatically excluded from archives. |
| 108 final _BLACKLISTED_FILES = const ['pubspec.lock']; | 108 final _BLACKLISTED_FILES = const ['pubspec.lock']; |
| 109 | 109 |
| 110 /// The basenames of directories that are automatically excluded from | 110 /// The basenames of directories that are automatically excluded from |
| 111 /// archives. | 111 /// archives. |
| 112 final _BLACKLISTED_DIRECTORIES = const ['packages']; | 112 final _BLACKLISTED_DIRS = const ['packages']; |
| 113 | 113 |
| 114 /// 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. |
| 115 /// If this is a Git repository, this will respect .gitignore; otherwise, it | 115 /// If this is a Git repository, this will respect .gitignore; otherwise, it |
| 116 /// will return all non-hidden files. | 116 /// will return all non-hidden files. |
| 117 Future<List<String>> get _filesToPublish { | 117 Future<List<String>> get _filesToPublish { |
| 118 var rootDir = entrypoint.root.dir; | 118 var rootDir = entrypoint.root.dir; |
| 119 | 119 |
| 120 return Future.wait([ | 120 return git.isInstalled.then((gitInstalled) { |
| 121 dirExists(join(rootDir, '.git')), | 121 if (dirExists(join(rootDir, '.git')) && gitInstalled) { |
| 122 git.isInstalled | |
| 123 ]).then((results) { | |
| 124 if (results[0] && results[1]) { | |
| 125 // List all files that aren't gitignored, including those not checked | 122 // List all files that aren't gitignored, including those not checked |
| 126 // in to Git. | 123 // in to Git. |
| 127 return git.run(["ls-files", "--cached", "--others", | 124 return git.run(["ls-files", "--cached", "--others", |
| 128 "--exclude-standard"]); | 125 "--exclude-standard"]); |
| 129 } | 126 } |
| 130 | 127 |
| 131 return listDir(rootDir, recursive: true).then((entries) { | 128 return listDir(rootDir, recursive: true).then((entries) { |
| 132 return Future.wait(entries.map((entry) { | 129 return entries |
| 133 return fileExists(entry).then((isFile) { | 130 .where(fileExists) // Skip directories. |
| 134 // Skip directories. | 131 .map((entry) => relativeTo(entry, rootDir)); |
| 135 if (!isFile) return null; | 132 }); |
| 133 }).then((files) => files.where(_shouldPublish).toList()); |
| 134 } |
| 136 | 135 |
| 137 // TODO(rnystrom): Making these relative will break archive | 136 /// Returns `true` if [file] should be published. |
| 138 // creation if the cwd is ever *not* the package root directory. | 137 bool _shouldPublish(String file) { |
| 139 // Should instead only make these relative right before generating | 138 if (_BLACKLISTED_FILES.contains(basename(file))) return false; |
| 140 // the tree display (which is what really needs them to be). | 139 return !splitPath(file).any(_BLACKLISTED_DIRS.contains); |
| 141 // Make it relative to the package root. | |
| 142 return relativeTo(entry, rootDir); | |
| 143 }); | |
| 144 })); | |
| 145 }); | |
| 146 }).then((files) => files.where((file) { | |
| 147 if (file == null || _BLACKLISTED_FILES.contains(basename(file))) { | |
| 148 return false; | |
| 149 } | |
| 150 | |
| 151 return !splitPath(file).any(_BLACKLISTED_DIRECTORIES.contains); | |
| 152 }).toList()); | |
| 153 } | 140 } |
| 154 | 141 |
| 155 /// Returns the value associated with [key] in [map]. Throws a user-friendly | 142 /// Returns the value associated with [key] in [map]. Throws a user-friendly |
| 156 /// error if [map] doens't contain [key]. | 143 /// error if [map] doens't contain [key]. |
| 157 _expectField(Map map, String key, http.Response response) { | 144 _expectField(Map map, String key, http.Response response) { |
| 158 if (map.containsKey(key)) return map[key]; | 145 if (map.containsKey(key)) return map[key]; |
| 159 invalidServerResponse(response); | 146 invalidServerResponse(response); |
| 160 } | 147 } |
| 161 | 148 |
| 162 /// Validates the package. Throws an exception if it's invalid. | 149 /// Validates the package. Throws an exception if it's invalid. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 178 var s = warnings.length == 1 ? '' : 's'; | 165 var s = warnings.length == 1 ? '' : 's'; |
| 179 message = "Package has ${warnings.length} warning$s. Upload anyway"; | 166 message = "Package has ${warnings.length} warning$s. Upload anyway"; |
| 180 } | 167 } |
| 181 | 168 |
| 182 return confirm(message).then((confirmed) { | 169 return confirm(message).then((confirmed) { |
| 183 if (!confirmed) throw "Package upload canceled."; | 170 if (!confirmed) throw "Package upload canceled."; |
| 184 }); | 171 }); |
| 185 }); | 172 }); |
| 186 } | 173 } |
| 187 } | 174 } |
| OLD | NEW |