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 /** | 5 /** |
6 * Helper functionality to make working with IO easier. | 6 * Helper functionality to make working with IO easier. |
7 */ | 7 */ |
8 #library('io'); | 8 #library('io'); |
9 | 9 |
10 #import('dart:io'); | 10 #import('dart:io'); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 args = ['/c', 'mklink', '/j', to, from]; | 272 args = ['/c', 'mklink', '/j', to, from]; |
273 } | 273 } |
274 | 274 |
275 return runProcess(command, args).transform((result) { | 275 return runProcess(command, args).transform((result) { |
276 // TODO(rnystrom): Check exit code and output? | 276 // TODO(rnystrom): Check exit code and output? |
277 return new File(to); | 277 return new File(to); |
278 }); | 278 }); |
279 } | 279 } |
280 | 280 |
281 /** | 281 /** |
282 * Creates a new symlink that creates an alias from the package [from] to [to], | |
283 * both of which can be a [String], [File], or [Directory]. Returns a [Future] | |
284 * which completes to the symlink file (i.e. [to]). | |
285 * | |
286 * Unlike [createSymlink], this has heuristics to detect if [from] is using | |
287 * the old or new style of package layout. If it's using the new style, then | |
288 * it will create a symlink to the "lib" directory contained inside that | |
289 * package directory. Otherwise, it just symlinks to the package directory | |
290 * itself. | |
291 */ | |
292 // TODO(rnystrom): Remove this when old style packages are no longer supported. | |
293 // See: http://code.google.com/p/dart/issues/detail?id=4964. | |
294 Future<File> createPackageSymlink(from, to) { | |
295 // If from contains any Dart files at the top level (aside from build.dart) | |
296 // we assume that means it's an old style package. | |
297 return listDir(from).chain((contents) { | |
298 var isOldStyle = contents.some( | |
299 (file) => file.endsWith('.dart') && basename(file) != 'build.dart'); | |
300 | |
301 if (isOldStyle) { | |
nweiz
2012/09/10 19:24:47
Shouldn't we print some sort of deprecation warnin
Bob Nystrom
2012/09/11 19:36:59
I don't want to warn when a dependency has the old
| |
302 return createSymlink(from, to); | |
nweiz
2012/09/10 19:24:47
Style nit: avoid the extra indentation of the else
Bob Nystrom
2012/09/11 19:36:59
Done.
| |
303 } else { | |
304 // It's a new style package, so symlink to the 'lib' directory. But only | |
305 // if the package actually *has* one. Otherwise, we won't create a | |
306 // symlink at all. | |
nweiz
2012/09/10 19:24:47
It seems potentially confusing to users to just si
Bob Nystrom
2012/09/11 19:36:59
Done. Prints warning.
| |
307 from = join(from, 'lib'); | |
308 return dirExists(from).chain((exists) { | |
309 if (exists) { | |
310 return createSymlink(from, to); | |
311 } else { | |
312 return new Future.immediate(to); | |
313 } | |
314 }); | |
315 } | |
316 }); | |
317 } | |
318 | |
319 /** | |
282 * Given [entry] which may be a [String], [File], or [Directory] relative to | 320 * Given [entry] which may be a [String], [File], or [Directory] relative to |
283 * the current working directory, returns its full canonicalized path. | 321 * the current working directory, returns its full canonicalized path. |
284 */ | 322 */ |
285 // TODO(rnystrom): Should this be async? | 323 // TODO(rnystrom): Should this be async? |
286 String getFullPath(entry) => new File(_getPath(entry)).fullPathSync(); | 324 String getFullPath(entry) => new File(_getPath(entry)).fullPathSync(); |
287 | 325 |
288 /** | 326 /** |
289 * Opens an input stream for a HTTP GET request to [uri], which may be a | 327 * Opens an input stream for a HTTP GET request to [uri], which may be a |
290 * [String] or [Uri]. | 328 * [String] or [Uri]. |
291 */ | 329 */ |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 return new Directory(entry); | 589 return new Directory(entry); |
552 } | 590 } |
553 | 591 |
554 /** | 592 /** |
555 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 593 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
556 */ | 594 */ |
557 Uri _getUri(uri) { | 595 Uri _getUri(uri) { |
558 if (uri is Uri) return uri; | 596 if (uri is Uri) return uri; |
559 return new Uri.fromString(uri); | 597 return new Uri.fromString(uri); |
560 } | 598 } |
OLD | NEW |