-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1580 from apollographql/fix/file_vs_folder
Add and test validation of multiple vs. single file urls
- Loading branch information
Showing
5 changed files
with
147 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
import Foundation | ||
|
||
public struct FileFinder { | ||
|
||
#if compiler(>=5.3) | ||
/// Version that works if you're using the 5.3 compiler or above | ||
/// - Parameter filePath: The full file path of the file to find. Defaults to the `#filePath` of the caller. | ||
/// - Returns: The file URL for the parent folder. | ||
public static func findParentFolder(from filePath: StaticString = #filePath) -> URL { | ||
self.findParentFolder(from: filePath.apollo.toString) | ||
} | ||
public static func findParentFolder(from filePath: StaticString = #filePath) -> URL { | ||
self.findParentFolder(from: filePath.apollo.toString) | ||
} | ||
|
||
/// The URL of a file at a given path | ||
/// - Parameter filePath: The full file path of the file to find | ||
/// - Returns: The file's URL | ||
public static func fileURL(from filePath: StaticString = #filePath) -> URL { | ||
URL(fileURLWithPath: filePath.apollo.toString) | ||
} | ||
#else | ||
/// Version that works if you're using the 5.2 compiler or below | ||
/// - Parameter file: The full file path of the file to find. Defaults to the `#file` of the caller. | ||
/// - Returns: The file URL for the parent folder. | ||
public static func findParentFolder(from filePath: StaticString = #file) -> URL { | ||
self.findParentFolder(from: filePath.apollo.toString) | ||
} | ||
/// Version that works if you're using the 5.2 compiler or below | ||
/// - Parameter file: The full file path of the file to find. Defaults to the `#file` of the caller. | ||
/// - Returns: The file URL for the parent folder. | ||
public static func findParentFolder(from filePath: StaticString = #file) -> URL { | ||
self.findParentFolder(from: filePath.apollo.toString) | ||
} | ||
|
||
/// The URL of a file at a given path | ||
/// - Parameter filePath: The full file path of the file to find | ||
/// - Returns: The file's URL | ||
public static func fileURL(from filePath: StaticString = #file) -> URL { | ||
URL(fileURLWithPath: filePath.apollo.toString) | ||
} | ||
#endif | ||
|
||
/// Finds the parent folder from a given file path. | ||
/// - Parameter filePath: The full file path, as a string | ||
/// - Returns: The file URL for the parent folder. | ||
public static func findParentFolder(from filePath: String) -> URL { | ||
let url = URL(fileURLWithPath: filePath) | ||
return url.deletingLastPathComponent() | ||
} | ||
public static func findParentFolder(from filePath: String) -> URL { | ||
let url = URL(fileURLWithPath: filePath) | ||
return url.deletingLastPathComponent() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters