mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
tweaked format of generated references
- more characters - underscore after type name - remove duplication count unless greater than 1
This commit is contained in:
@@ -18,14 +18,15 @@ public class ReferenceGenerator {
|
||||
public func generate<T: PBXObject>(_ element: T.Type, _ id: String) -> String {
|
||||
var uuid: String = ""
|
||||
var counter: UInt = 0
|
||||
let characterCount = 16
|
||||
let className: String = String(describing: T.self)
|
||||
.replacingOccurrences(of: "PBX", with: "")
|
||||
.replacingOccurrences(of: "XC", with: "")
|
||||
let classAcronym = String(className.filter { String($0).lowercased() != String($0) })
|
||||
let stringID = String(abs(id.hashValue).description.prefix(10 - classAcronym.count))
|
||||
let stringID = String(abs(id.hashValue).description.prefix(characterCount - classAcronym.count - 2))
|
||||
repeat {
|
||||
uuid = "\(classAcronym)_\(stringID)\(counter > 0 ? "-\(counter)" : "")"
|
||||
counter += 1
|
||||
uuid = "\(classAcronym)\(stringID)\(String(format: "%02d", counter))"
|
||||
} while (references.contains(uuid))
|
||||
references.insert(uuid)
|
||||
return uuid
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+6
-6
@@ -5,31 +5,31 @@
|
||||
<TestAction selectedDebuggerIdentifier="Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier="Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv="YES" buildConfiguration="Production Debug">
|
||||
<Testables>
|
||||
<TestableReference skipped="NO">
|
||||
<BuildableReference BlueprintIdentifier="NT7831228901" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS_Tests.xctest" BlueprintName="App_iOS" BuildableIdentifier="primary" />
|
||||
<BuildableReference BlueprintIdentifier="NT_783122899910" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS_Tests.xctest" BlueprintName="App_iOS" BuildableIdentifier="primary" />
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference BlueprintIdentifier="NT8252321101" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
|
||||
<BuildableReference BlueprintIdentifier="NT_825232110500" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
|
||||
</MacroExpansion>
|
||||
</TestAction>
|
||||
<ProfileAction savedToolIdentifier="" useCustomWorkingDirectory="NO" shouldUseLaunchSchemeArgsEnv="YES" buildConfiguration="Production Release" debugDocumentVersioning="YES">
|
||||
<BuildableProductRunnable runnableDebuggingMode="0">
|
||||
<BuildableReference BlueprintIdentifier="NT8252321101" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
|
||||
<BuildableReference BlueprintIdentifier="NT_825232110500" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<BuildAction parallelizeBuildables="YES" buildImplicitDependencies="YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry buildForArchiving="YES" buildForTesting="YES" buildForRunning="YES" buildForProfiling="YES" buildForAnalyzing="YES">
|
||||
<BuildableReference BlueprintIdentifier="NT8252321101" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
|
||||
<BuildableReference BlueprintIdentifier="NT_825232110500" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry buildForArchiving="NO" buildForTesting="YES" buildForRunning="NO" buildForProfiling="NO" buildForAnalyzing="YES">
|
||||
<BuildableReference BlueprintIdentifier="NT7831228901" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS_Tests.xctest" BlueprintName="App_iOS" BuildableIdentifier="primary" />
|
||||
<BuildableReference BlueprintIdentifier="NT_783122899910" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS_Tests.xctest" BlueprintName="App_iOS" BuildableIdentifier="primary" />
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<LaunchAction selectedDebuggerIdentifier="Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier="Xcode.DebuggerFoundation.Launcher.LLDB" launchStyle="0" buildConfiguration="Production Debug" debugServiceExtension="internal" ignoresPersistentStateOnLaunch="NO" useCustomWorkingDirectory="NO" allowLocationSimulation="YES" debugDocumentVersioning="YES">
|
||||
<BuildableProductRunnable runnableDebuggingMode="0">
|
||||
<BuildableReference BlueprintIdentifier="NT8252321101" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
|
||||
<BuildableReference BlueprintIdentifier="NT_825232110500" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
</Scheme>
|
||||
@@ -242,6 +242,33 @@ func projectGeneratorTests() {
|
||||
}
|
||||
}
|
||||
|
||||
$0.describe("Reference Generator") {
|
||||
|
||||
let referenceGenerator = ReferenceGenerator()
|
||||
$0.before {
|
||||
referenceGenerator.clear()
|
||||
}
|
||||
|
||||
$0.it("generates prefixes") {
|
||||
let references = [
|
||||
referenceGenerator.generate(PBXGroup.self, "a"),
|
||||
referenceGenerator.generate(PBXFileReference.self, "a"),
|
||||
referenceGenerator.generate(XCConfigurationList.self, "a"),
|
||||
]
|
||||
try expect(references[0].hasPrefix("G")).to.beTrue()
|
||||
try expect(references[1].hasPrefix("FR")).to.beTrue()
|
||||
try expect(references[2].hasPrefix("CL")).to.beTrue()
|
||||
}
|
||||
|
||||
$0.it("handles duplicates") {
|
||||
let first = referenceGenerator.generate(PBXGroup.self, "a")
|
||||
let second = referenceGenerator.generate(PBXGroup.self, "a")
|
||||
|
||||
try expect(first) != second
|
||||
try expect(second.hasSuffix("-1")).to.beTrue()
|
||||
}
|
||||
}
|
||||
|
||||
$0.describe("Sources") {
|
||||
|
||||
let directoryPath = Path("TestDirectory")
|
||||
@@ -494,34 +521,6 @@ func projectGeneratorTests() {
|
||||
try project.expectFileMissing(paths: ["Sources", "A", "a.swift"])
|
||||
}
|
||||
}
|
||||
|
||||
$0.describe("Reference Generator") {
|
||||
|
||||
let referenceGenerator = ReferenceGenerator()
|
||||
$0.before {
|
||||
referenceGenerator.clear()
|
||||
}
|
||||
|
||||
$0.it("generates prefixes") {
|
||||
let references = [
|
||||
referenceGenerator.generate(PBXGroup.self, "a"),
|
||||
referenceGenerator.generate(PBXFileReference.self, "a"),
|
||||
referenceGenerator.generate(XCConfigurationList.self, "a"),
|
||||
]
|
||||
try expect(references[0].hasPrefix("G")).to.beTrue()
|
||||
try expect(references[1].hasPrefix("FR")).to.beTrue()
|
||||
try expect(references[2].hasPrefix("CL")).to.beTrue()
|
||||
}
|
||||
|
||||
$0.it("handles duplicates") {
|
||||
let first = referenceGenerator.generate(PBXGroup.self, "a")
|
||||
let second = referenceGenerator.generate(PBXGroup.self, "a")
|
||||
|
||||
try expect(first) != second
|
||||
try expect(first.hasSuffix("01")).to.beTrue()
|
||||
try expect(second.hasSuffix("02")).to.beTrue()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user