-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.swift
More file actions
executable file
·56 lines (49 loc) · 1.49 KB
/
install.swift
File metadata and controls
executable file
·56 lines (49 loc) · 1.49 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// main.swift
// InstallRMVIPERTemplate
//
import Foundation
let destinationPath = "/Users/\(NSFullUserName())/Library/Developer/Xcode/Templates"
let fm = FileManager.default
let currentDir = fm.currentDirectoryPath
func getTemplatesPaths() -> [String]? {
do {
let items = try fm.contentsOfDirectory(atPath: currentDir)
return items.filter { $0.contains(".xctemplate") }
} catch {
return nil
}
}
func copyTemplates() {
guard let templatePaths = getTemplatesPaths() else {
showMessage("Something went wrong :(")
return
}
for templatePath in templatePaths {
let source = currentDir + "/" + templatePath
let dest = destinationPath + "/" + templatePath
if !copyFiles(from: source, to: dest) {
showMessage("Something went wrong :(")
return
}
}
showMessage("Templates are installed successfully!")
}
func copyFiles(from source: String, to dest: String) -> Bool {
do {
let filelist = try fm.contentsOfDirectory(atPath: source)
try? fm.copyItem(atPath: source, toPath: dest)
for filename in filelist {
try? fm.copyItem(atPath: "\(source)/\(filename)", toPath: "\(dest)/\(filename)")
}
return true
} catch {
return false
}
}
func showMessage(_ message: String) {
print("===============================================")
print("\(message)")
print("===============================================")
}
copyTemplates()