mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-02-02 11:33:02 +01:00
56 lines
1.8 KiB
Swift
56 lines
1.8 KiB
Swift
import Version
|
|
import XcodesKit
|
|
|
|
extension Version {
|
|
/// Initialize a Version from an XcodeReleases' XCModel.Xcode
|
|
///
|
|
/// This is kinda quick-and-dirty, and it would probably be better for us to adopt something closer to XCModel.Xcode under the hood and map the scraped data to it instead.
|
|
init?(xcReleasesXcode: XcodeRelease) {
|
|
var versionString = xcReleasesXcode.version.number ?? ""
|
|
|
|
// Append trailing ".0" in order to get a fully-specified version string
|
|
let components = versionString.components(separatedBy: ".")
|
|
versionString += Array(repeating: ".0", count: 3 - components.count).joined()
|
|
|
|
// Append prerelease identifier
|
|
switch xcReleasesXcode.version.release {
|
|
case let .beta(beta):
|
|
versionString += "-Beta"
|
|
if beta > 1 {
|
|
versionString += ".\(beta)"
|
|
}
|
|
case let .dp(dp):
|
|
versionString += "-DP"
|
|
if dp > 1 {
|
|
versionString += ".\(dp)"
|
|
}
|
|
case .gm:
|
|
break
|
|
case let .gmSeed(gmSeed):
|
|
versionString += "-GM.Seed"
|
|
if gmSeed > 1 {
|
|
versionString += ".\(gmSeed)"
|
|
}
|
|
case let .rc(rc):
|
|
versionString += "-Release.Candidate"
|
|
if rc > 1 {
|
|
versionString += ".\(rc)"
|
|
}
|
|
case .release:
|
|
break
|
|
}
|
|
|
|
// Append build identifier
|
|
if let buildNumber = xcReleasesXcode.version.build {
|
|
versionString += "+\(buildNumber)"
|
|
}
|
|
|
|
self.init(versionString)
|
|
}
|
|
|
|
var buildMetadataIdentifiersDisplay: String {
|
|
return !buildMetadataIdentifiers.isEmpty ? "(\(buildMetadataIdentifiers.joined(separator: " ")))" : ""
|
|
}
|
|
}
|
|
|