Issue #839
Use locales data from faker.js
to https://github.com/onmyway133/EasyFake, renaming files since files, regardless of sub directories in Xcode, must have different name.
We use enumerator
API on FileManager
to traverse all files in all sub-directories
import Foundation
let localesURL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
.appendingPathComponent("Sources/EasyFake/Resources/locales")
let manager = FileManager.default
manager.enumerator(atPath: localesURL.path)?.forEach { path in
guard let path = path as? String else { return }
let url = URL(fileURLWithPath: path, relativeTo: localesURL)
guard url.lastPathComponent != "index.js" else {
try? manager.removeItem(at: url)
return
}
guard url.pathExtension != "DS_Store" else {
try? manager.removeItem(at: url)
return
}
let lastPath = url.path
.replacingOccurrences(of: localesURL.path, with: "")
guard !lastPath.isEmpty else { return }
let newName = lastPath
.trimmingCharacters(in: CharacterSet(arrayLiteral: "/"))
.replacingOccurrences(of: "/", with: "-")
let newUrl = localesURL.appendingPathComponent(newName)
if url.pathExtension == "js" {
try? manager.moveItem(at: url, to: newUrl)
}
}