-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstall.swift
52 lines (40 loc) · 1.73 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
42
43
44
45
46
47
48
49
50
51
52
//
// main.swift
// Core-iOS-Application-Architecture
//
// Created by Artem Tishchenko on 11/11/2023
// Copyright All rights reserved.
// Special thanks Alexey Artemev from iDevs
import Foundation
func printInConsole(_ message:Any){
print("==> \(message)")
}
let fileManager = FileManager.default
let homeDirectoryForCurrentUser = fileManager.homeDirectoryForCurrentUser.path
let currentPath = fileManager.currentDirectoryPath
let templatePath = "\(homeDirectoryForCurrentUser)/Library/Developer/Xcode/Templates/"
let projectDir = "Project Templates/"
let moduleDir = "File Templates/"
let sourceProjectPath = "\(currentPath)/\(projectDir)"
let sourceModulePath = "\(currentPath)/\(moduleDir)"
let projectTemplatePath = "\(templatePath)/\(projectDir)"
let moduleTemplatePath = "\(templatePath)/\(moduleDir)"
func makeDir(path: String) {
try? fileManager.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
}
func moveTemplate(fromPath: String, toPath: String) throws {
let toURL = URL(fileURLWithPath:toPath)
try _ = fileManager.removeItem(at: toURL)
try _ = fileManager.copyItem(atPath: fromPath, toPath: toPath)
}
do {
printInConsole("Install Project templates at \(projectTemplatePath)")
makeDir(path: projectTemplatePath)
try moveTemplate(fromPath: sourceProjectPath, toPath: projectTemplatePath)
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 ?? "")")
}