diff --git a/Sources/BivrostKit/BivrostKit.swift b/Sources/BivrostKit/BivrostKit.swift index 2a26b4c..6fa132a 100644 --- a/Sources/BivrostKit/BivrostKit.swift +++ b/Sources/BivrostKit/BivrostKit.swift @@ -26,7 +26,7 @@ public struct BivrostKit { let typeFolderPath = (Path(outputFolder) + Path(typeFolderName)).absolute().string let contractFolderPath = (Path(outputFolder) + Path(contractFolderName)).absolute().string - if force { + if Path(outputFolder).exists && force { try FileTool.delete(path: outputFolder) } // Cleanup output folder first, in case it exists diff --git a/Sources/BivrostKit/Generating/AuxWriter.swift b/Sources/BivrostKit/Generating/AuxWriter.swift index 73be328..908684b 100644 --- a/Sources/BivrostKit/Generating/AuxWriter.swift +++ b/Sources/BivrostKit/Generating/AuxWriter.swift @@ -6,12 +6,28 @@ // import PathKit +import Foundation struct AuxWriter { static func writeAuxiliaryFiles(to outputFolder: String) throws { try FileTool.create(path: outputFolder) let outputFolder = Path(outputFolder) - let resources = Path("./Resources") + + // Find Resources folder + let relativeResources = Path("Resources") + let relativeToWorkingDir = Path.current + relativeResources + + let resources: Path + if let relativeExecutablePathString = CommandLine.arguments.first { + let relativeExecutablePathWithoutExecutableString = (relativeExecutablePathString as NSString).deletingLastPathComponent + let executablePath = Path.current + Path(relativeExecutablePathWithoutExecutableString) + let relativeToExecutable = executablePath + relativeResources + // Check if executablePath/Resources exists (e.g. with Mint), otherwise use ChDir/Resources + resources = relativeToExecutable.exists ? relativeToExecutable : relativeToWorkingDir + } else { + // Just use ChDir/Resources + resources = relativeToWorkingDir + } try resources.children().forEach { try $0.copy(outputFolder + $0.lastComponent) } } }