forked from AckeeCZ/iOS-MVVM-ProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename.swift
executable file
·27 lines (21 loc) · 881 Bytes
/
rename.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
#!/usr/bin/env swift
import Foundation
func rename(with name: String) throws {
try replaceName(at: "Podfile", name: name)
try replaceName(at: "Project.swift", name: name)
try replaceName(at: "Setup.swift", name: name)
try replaceName(at: "Workspace.swift", name: name)
try replaceName(at: ".swiftlint.yml", name: name)
try FileManager.default.moveItem(atPath: "ProjectTemplate", toPath: name)
}
func replaceName(at path: String, name: String) throws {
let content = try String(contentsOfFile: path)
try content.replacingOccurrences(of: "ProjectTemplate", with: name).write(toFile: path, atomically: true, encoding: .utf8)
}
let arguments = CommandLine.arguments
if arguments.count == 2 {
try rename(with: arguments[1])
} else {
print("You must provide a name argument")
}
try FileManager.default.removeItem(atPath: "rename.swift")