-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// URL-selectDirectories.swift | ||
// Ignite | ||
// https://www.github.com/twostraws/Ignite | ||
// See LICENSE for license information. | ||
// | ||
|
||
import Foundation | ||
|
||
extension URL { | ||
/// Returns URL where to find Assets/Content/Includes and URL where to generate the static web site. | ||
/// When building a package, the website is built at the source URL (and both URLs are equal). | ||
/// When building a MacOS app, the website is built in a subdirectory of the app's sandbox. | ||
/// - Parameter file: path of a Swift source file to find source root directory by scanning path upwards. | ||
/// - Returns tupple containing source URL and URL where output is built. | ||
public static func selectDirectories(from file: StaticString) throws -> SourceBuildDirectories { | ||
var currentURL = URL(filePath: file.description) | ||
|
||
repeat { | ||
currentURL = currentURL.deletingLastPathComponent() | ||
|
||
let packageURL = currentURL.appending(path: "Package.swift") | ||
if FileManager.default.fileExists(atPath: packageURL.path) { | ||
return SourceBuildDirectories(source: packageURL.deletingLastPathComponent(), | ||
build: packageURL.deletingLastPathComponent()) | ||
} | ||
} while currentURL.path() != "/" | ||
|
||
let buildDirectory: String = NSHomeDirectory() // app's home directory for a sandboxed MacOS app | ||
if buildDirectory.contains("/Library/Containers/") { | ||
let buildDirectoryURL: URL = URL(filePath: buildDirectory) | ||
return SourceBuildDirectories(source: buildDirectoryURL, | ||
build: buildDirectoryURL) | ||
} | ||
|
||
throw PublishingError.missingPackageDirectory | ||
} | ||
|
||
} | ||
|
||
/// Provides URL to where to find Assets/Content/Includes input directories and Build output directory | ||
public struct SourceBuildDirectories { | ||
public let source: URL | ||
public let build: URL | ||
} |
37 changes: 0 additions & 37 deletions
37
Sources/Ignite/Extensions/URL-SelectSiteRootDirectory.swift
This file was deleted.
Oops, something went wrong.
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