Fix the files and groups sorting order (#164)
* Gitignore TODO * Sorten files and groups before adding them to the project * Test it * Update CHANGELOG
This commit is contained in:
parent
a7c146c24a
commit
25d57ab830
|
@ -98,4 +98,5 @@ Carthage/Checkouts
|
|||
*.profraw
|
||||
tuist.zip
|
||||
build/
|
||||
tuistenv
|
||||
tuistenv
|
||||
TODO
|
|
@ -4,6 +4,10 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/
|
|||
|
||||
## Next version
|
||||
|
||||
### Fixed
|
||||
|
||||
- Files and groups sort order https://github.com/tuist/tuist/pull/164 by @pepibumur.
|
||||
|
||||
## 0.8.0
|
||||
|
||||
### Added
|
||||
|
|
|
@ -10,15 +10,6 @@
|
|||
"version": "4.3.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "core",
|
||||
"repositoryURL": "https://github.com/tuist/core.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "4500863dd846244323b29cb0950cb861e1fddcd0",
|
||||
"version": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "Nimble",
|
||||
"repositoryURL": "https://github.com/Quick/Nimble.git",
|
||||
|
|
|
@ -32,4 +32,12 @@ extension AbsolutePath {
|
|||
public func removingLastComponent() -> AbsolutePath {
|
||||
return AbsolutePath("/\(components.dropLast().joined(separator: "/"))")
|
||||
}
|
||||
|
||||
/// Returns a function to sorten files for Xcode projects.
|
||||
/// - Returns: Sortening function.
|
||||
public static func xcodeSortener() -> ((AbsolutePath, AbsolutePath) -> Bool) {
|
||||
return { lhs, rhs in
|
||||
lhs.components.count < rhs.components.count || lhs.asString < rhs.asString
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class ProjectFileElements {
|
|||
files.formUnion(projectFiles(project: project))
|
||||
|
||||
/// Files
|
||||
generate(files: files.sorted(),
|
||||
generate(files: files.sorted(by: AbsolutePath.xcodeSortener()),
|
||||
groups: groups,
|
||||
pbxproj: pbxproj,
|
||||
sourceRootPath: sourceRootPath)
|
||||
|
@ -119,7 +119,7 @@ class ProjectFileElements {
|
|||
func generate(products: [String],
|
||||
groups: ProjectGroups,
|
||||
pbxproj: PBXProj) {
|
||||
products.forEach { productName in
|
||||
products.sorted().forEach { productName in
|
||||
if self.products[productName] != nil { return }
|
||||
let fileType = Xcode.filetype(extension: String(productName.split(separator: ".").last!))
|
||||
let fileReference = PBXFileReference(sourceTree: .buildProductsDir,
|
||||
|
@ -278,7 +278,7 @@ class ProjectFileElements {
|
|||
toGroup: PBXGroup,
|
||||
pbxproj: PBXProj) {
|
||||
// /path/to/*.lproj/*
|
||||
absolutePath.glob("*").forEach { localizedFile in
|
||||
absolutePath.glob("*").sorted().forEach { localizedFile in
|
||||
let localizedName = localizedFile.components.last!
|
||||
|
||||
// Variant group
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import Basic
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import TuistCore
|
||||
|
||||
final class AbsolutePathExtrasTests: XCTestCase {
|
||||
func test_xcodeSortener() {
|
||||
let subject = [
|
||||
AbsolutePath("/sources/a.swift"),
|
||||
AbsolutePath("/a.swift"),
|
||||
AbsolutePath("/b.swift"),
|
||||
AbsolutePath("/sources/b.swift"),
|
||||
].sorted(by: AbsolutePath.xcodeSortener())
|
||||
|
||||
XCTAssertEqual(subject, [
|
||||
AbsolutePath("/a.swift"),
|
||||
AbsolutePath("/b.swift"),
|
||||
AbsolutePath("/sources/a.swift"),
|
||||
AbsolutePath("/sources/b.swift"),
|
||||
])
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue