diff --git a/Sources/MintKit/Mint.swift b/Sources/MintKit/Mint.swift index c8c9772..8891d05 100644 --- a/Sources/MintKit/Mint.swift +++ b/Sources/MintKit/Mint.swift @@ -293,6 +293,7 @@ public class Mint { try linkPackage(package, executable: executable, overwrite: overwrite) } } + try linkResources(package) checkLinkPath() } return false @@ -390,6 +391,7 @@ public class Mint { try linkPackage(package, executable: executable, overwrite: overwrite) } } + try linkResources(package) checkLinkPath() } @@ -406,12 +408,7 @@ public class Mint { pathsToCopy.append(executablePath) } - let copiedExtensions: Set = ["bundle", "resources", "dylib"] - for path in try buildPath.children() { - if let ext = path.extension, copiedExtensions.contains(ext) { - pathsToCopy.append(path) - } - } + try pathsToCopy.append(contentsOf: getResources(from: buildPath)) for path in pathsToCopy { let destinationPath = installPath + path.lastComponent @@ -422,6 +419,18 @@ public class Mint { try Task.run(bash: "cp -R \"\(path.string)\" \"\(destinationPath.string)\"") } } + + private func getResources(from path: Path) throws -> [Path] { + let extensions: Set = ["bundle", "resources", "dylib"] + + return try path.children().filter { + guard let ext = $0.extension, extensions.contains(ext) else { + return false + } + + return true + } + } private func checkLinkPath() { if let path = ProcessInfo.processInfo.environment["PATH"], !path.contains(linkPath.string) { @@ -491,6 +500,22 @@ public class Mint { output(confirmation.green) } + func linkResources(_ package: PackageReference) throws { + let packagePath = PackagePath(path: packagesPath, package: package) + let resources = try getResources(from: packagePath.installPath) + + for resource in resources { + let installPath = linkPath + resource.lastComponent + + do { + try Task.run(bash: "ln -s -f -h \"\(packagePath.installPath + resource.lastComponent)\" \"\(installPath.string)\"") + } catch { + errorOutput("Could not link \(resource.lastComponent) to \(installPath.string)".red) + return + } + } + } + public func bootstrap(link: Bool = false, overwrite: Bool? = nil) throws { let mintFile = try Mintfile(path: mintFilePath) @@ -539,6 +564,14 @@ public class Mint { let option = Input.readOption(options: packages.map { $0.gitRepo }, prompt: "There are multiple packages matching '\(name)', which one would you like to uninstall?") package = packages.first { $0.gitRepo == option }! } + + // get resources across all installed versions + let resources = Set( + try package.versionDirs + .map { try getResources(from: $0.path) } + .flatMap { $0 } + ) + try package.path.delete() output("\(package.name) was uninstalled") @@ -551,5 +584,11 @@ public class Mint { let installPath = linkPath + executable.name try installPath.delete() } + + // remove all resource artifact links + for resource in resources { + let installPath = linkPath + resource.lastComponent + try installPath.delete() + } } }