mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2024-09-20 00:58:04 +03:00
37e1f72531
* Only allow folder with unknown UTI * Update fixture * Use fileGroups instead of fixtures. * Change log * Add to the right place * Rename title
71 lines
2.2 KiB
Swift
71 lines
2.2 KiB
Swift
import Foundation
|
|
import PathKit
|
|
import XcodeProj
|
|
|
|
extension PBXFileElement {
|
|
public var nameOrPath: String {
|
|
return name ?? path ?? ""
|
|
}
|
|
|
|
static func sortByNamePath(_ lhs: PBXFileElement, _ rhs: PBXFileElement) -> Bool {
|
|
return lhs.namePathSortString.localizedStandardCompare(rhs.namePathSortString) == .orderedAscending
|
|
}
|
|
|
|
private var namePathSortString: String {
|
|
// This string needs to be unique for all combinations of name & path or the order won't be stable.
|
|
return "\(name ?? path ?? "")\t\(name ?? "")\t\(path ?? "")"
|
|
}
|
|
}
|
|
|
|
extension PBXProj {
|
|
|
|
public func printGroups() -> String {
|
|
guard let project = projects.first,
|
|
let mainGroup = project.mainGroup else {
|
|
return ""
|
|
}
|
|
return printGroup(group: mainGroup)
|
|
}
|
|
|
|
public func printGroup(group: PBXGroup) -> String {
|
|
var string = group.nameOrPath
|
|
for child in group.children {
|
|
if let group = child as? PBXGroup {
|
|
string += "\n 📁 " + printGroup(group: group).replacingOccurrences(of: "\n ", with: "\n ")
|
|
} else if let fileReference = child as? PBXFileReference {
|
|
string += "\n 📄 " + fileReference.nameOrPath
|
|
} else if let variantGroup = child as? PBXVariantGroup {
|
|
string += "\n 🌎 " + variantGroup.nameOrPath
|
|
} else if let versionGroup = child as? XCVersionGroup {
|
|
string += "\n 🔢 " + versionGroup.nameOrPath
|
|
}
|
|
}
|
|
return string
|
|
}
|
|
}
|
|
|
|
extension Dictionary {
|
|
|
|
public var valueArray: [Value] {
|
|
Array(values)
|
|
}
|
|
}
|
|
|
|
extension Xcode {
|
|
|
|
public static func fileType(path: Path) -> String? {
|
|
guard let fileExtension = path.extension else { return nil }
|
|
switch fileExtension {
|
|
// cases that aren't handled (yet) in XcodeProj.
|
|
default:
|
|
// fallback to XcodeProj defaults
|
|
return Xcode.filetype(extension: fileExtension)
|
|
}
|
|
}
|
|
|
|
public static func isDirectoryFileWrapper(path: Path) -> Bool {
|
|
guard path.isDirectory else { return false }
|
|
return fileType(path: path) != nil
|
|
}
|
|
}
|