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:io'; | 7 import 'dart:io'; |
8 import 'dart:json'; | 8 import 'dart:json'; |
9 import 'dart:uri'; | 9 import 'dart:uri'; |
10 | 10 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 /// The basenames of directories that are automatically excluded from | 107 /// The basenames of directories that are automatically excluded from |
108 /// archives. | 108 /// archives. |
109 final _BLACKLISTED_DIRECTORIES = const ['packages']; | 109 final _BLACKLISTED_DIRECTORIES = const ['packages']; |
110 | 110 |
111 /// Returns a list of files that should be included in the published package. | 111 /// Returns a list of files that should be included in the published package. |
112 /// If this is a Git repository, this will respect .gitignore; otherwise, it | 112 /// If this is a Git repository, this will respect .gitignore; otherwise, it |
113 /// will return all non-hidden files. | 113 /// will return all non-hidden files. |
114 Future<List<String>> get _filesToPublish { | 114 Future<List<String>> get _filesToPublish { |
115 var rootDir = entrypoint.root.dir; | 115 var rootDir = entrypoint.root.dir; |
116 | 116 |
117 // TODO(rnystrom): listDir() returns real file paths after symlinks are | |
118 // resolved. This means if libDir contains a symlink, the resulting paths | |
119 // won't appear to be within it, which confuses relativeTo(). Work around | |
120 // that here by making sure we have the real path to libDir. Remove this | |
121 // when #7346 is fixed. | |
122 rootDir = new File(rootDir).fullPathSync(); | |
123 | |
124 return Futures.wait([ | 117 return Futures.wait([ |
125 dirExists(join(rootDir, '.git')), | 118 dirExists(join(rootDir, '.git')), |
126 git.isInstalled | 119 git.isInstalled |
127 ]).chain((results) { | 120 ]).chain((results) { |
128 if (results[0] && results[1]) { | 121 if (results[0] && results[1]) { |
129 // List all files that aren't gitignored, including those not checked | 122 // List all files that aren't gitignored, including those not checked |
130 // in to Git. | 123 // in to Git. |
131 return git.run(["ls-files", "--cached", "--others", | 124 return git.run(["ls-files", "--cached", "--others", |
132 "--exclude-standard"]); | 125 "--exclude-standard"]); |
133 } | 126 } |
134 | 127 |
135 return listDir(rootDir, recursive: true).chain((entries) { | 128 return listDir(rootDir, recursive: true).chain((entries) { |
136 return Futures.wait(entries.map((entry) { | 129 return Futures.wait(entries.map((entry) { |
137 return fileExists(entry).transform((isFile) { | 130 return fileExists(entry).transform((isFile) { |
138 // Skip directories. | 131 // Skip directories. |
139 if (!isFile) return null; | 132 if (!isFile) return null; |
140 | 133 |
141 // TODO(rnystrom): Making these relative will break archive | 134 // TODO(rnystrom): Making these relative will break archive |
142 // creation if the cwd is ever *not* the package root directory. | 135 // creation if the cwd is ever *not* the package root directory. |
143 // Should instead only make these relative right before generating | 136 // Should instead only make these relative right before generating |
144 // the tree display (which is what really needs them to be). | 137 // the tree display (which is what really needs them to be). |
145 // Make it relative to the package root. | 138 // Make it relative to the package root. |
146 entry = relativeTo(entry, rootDir); | 139 return relativeTo(entry, rootDir); |
147 | |
148 // TODO(rnystrom): dir.list() will include paths with resolved | |
149 // symlinks. In particular, we'll get paths to symlinked files from | |
150 // "packages" that reach outside of this package. Since the path | |
151 // has already been resolved, we don't even see "packages" in that | |
152 // path anymore. | |
153 // These should not be included in the archive. As a hack, ignore | |
154 // any file whose relative path is backing out of the root | |
155 // directory. Should do something cleaner. | |
156 var parts = path.split(entry); | |
157 if (!parts.isEmpty && parts[0] == '..') return null; | |
158 | |
159 return entry; | |
160 }); | 140 }); |
161 })); | 141 })); |
162 }); | 142 }); |
163 }).transform((files) => files.filter((file) { | 143 }).transform((files) => files.filter((file) { |
164 if (file == null || _BLACKLISTED_FILES.contains(basename(file))) { | 144 if (file == null || _BLACKLISTED_FILES.contains(basename(file))) { |
165 return false; | 145 return false; |
166 } | 146 } |
167 | 147 |
168 return !splitPath(file).some(_BLACKLISTED_DIRECTORIES.contains); | 148 return !splitPath(file).some(_BLACKLISTED_DIRECTORIES.contains); |
169 })); | 149 })); |
(...skipping 25 matching lines...) Expand all Loading... |
195 var s = warnings.length == 1 ? '' : 's'; | 175 var s = warnings.length == 1 ? '' : 's'; |
196 message = "Package has ${warnings.length} warning$s. Upload anyway"; | 176 message = "Package has ${warnings.length} warning$s. Upload anyway"; |
197 } | 177 } |
198 | 178 |
199 return confirm(message).transform((confirmed) { | 179 return confirm(message).transform((confirmed) { |
200 if (!confirmed) throw "Package upload canceled."; | 180 if (!confirmed) throw "Package upload canceled."; |
201 }); | 181 }); |
202 }); | 182 }); |
203 } | 183 } |
204 } | 184 } |
OLD | NEW |