Skip to content

Commit

Permalink
Try to find Resources in executable dir first
Browse files Browse the repository at this point in the history
  • Loading branch information
zweigraf committed Oct 20, 2017
1 parent 2b4cb24 commit dbdd502
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/BivrostKit/BivrostKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion Sources/BivrostKit/Generating/AuxWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}

0 comments on commit dbdd502

Please sign in to comment.