-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.swift
41 lines (35 loc) · 1.64 KB
/
install.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Foundation
private let templateName = "TCA-SwiftUI.xctemplate"
private let destinationPath = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/TCA-SwiftUI"
private func messageInConsole(_ message: String) {
print("\(message)")
}
private let fileManager = FileManager.default
private func copyTemplate(createingFolderIfNeed: Bool = false) {
do {
if !fileManager.fileExists(atPath:"\(destinationPath)/\(templateName)"){
try fileManager.copyItem(atPath: templateName, toPath: "\(destinationPath)/\(templateName)")
messageInConsole("Template installed succesfully")
} else {
try fileManager.removeItem(at: URL(fileURLWithPath:"\(destinationPath)/\(templateName)"))
try fileManager.copyItem(atPath: templateName, toPath: "\(destinationPath)/\(templateName)")
messageInConsole("Template already exists. So has been replaced succesfully")
}
} catch let error as NSError {
messageInConsole("Something Error: \(error.localizedFailureReason!)")
messageInConsole("Try again with Creating new Folder")
if createingFolderIfNeed {
creatingFolder()
}
}
}
private func creatingFolder() {
do {
try fileManager.createDirectory(at: URL(fileURLWithPath:"\(destinationPath)"), withIntermediateDirectories: true, attributes: nil)
copyTemplate()
} catch let error as NSError {
messageInConsole("Something Error: \(error.localizedFailureReason!)")
messageInConsole("Finished")
}
}
copyTemplate(createingFolderIfNeed: true)