Skip to content

Commit

Permalink
Update install.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
bartleby committed Dec 9, 2019
1 parent 3f529f6 commit 8dd6f4a
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions install.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 26,27 @@ let sourceModulePath = "\(currentPath)/\(moduleDir)"
let projectTemplatePath = "\(templatePath)/\(projectDir)"
let moduleTemplatePath = "\(templatePath)/\(moduleDir)"

func moveTemplate(fromPath: String, toPath: String){
let toURL = URL(fileURLWithPath:toPath)
func makeDir(path: String) {
try? fileManager.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
}

do {
if !fileManager.fileExists(atPath: toPath){
try fileManager.copyItem(atPath: fromPath, toPath: toPath)
printInConsole("Template installed succesfully.")

} else {
try _ = fileManager.removeItem(at: toURL)
try _ = fileManager.copyItem(atPath: fromPath, toPath: toPath)
printInConsole("Template already exists. So has been replaced succesfully.")
}
}
catch let error as NSError {
printInConsole("Ooops! Something went wrong: \(error.localizedFailureReason!)")
}
func moveTemplate(fromPath: String, toPath: String) throws {
let toURL = URL(fileURLWithPath:toPath)
try _ = fileManager.removeItem(at: toURL)
try _ = fileManager.copyItem(atPath: fromPath, toPath: toPath)
}

printInConsole("Install Project templates...")
moveTemplate(fromPath: sourceProjectPath, toPath: projectTemplatePath)

printInConsole("Install Module templates...")
moveTemplate(fromPath: sourceModulePath, toPath: moduleTemplatePath)
do {
printInConsole("Install Project templates at \(projectTemplatePath)")
makeDir(path: projectTemplatePath)
try moveTemplate(fromPath: sourceProjectPath, toPath: projectTemplatePath)

printInConsole("All templates have been successfully installed.")
printInConsole("Install Module templates at \(moduleTemplatePath)")
makeDir(path: moduleTemplatePath)
try moveTemplate(fromPath: sourceModulePath, toPath: moduleTemplatePath)

printInConsole("All templates have been successfully installed.")
} catch let error as NSError {
printInConsole("Could not install the templates. Reason: \(error.localizedFailureReason ?? "")")
}

0 comments on commit 8dd6f4a

Please sign in to comment.