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:
Pedro Piñera Buendía 2018-12-01 10:44:49 +01:00 committed by GitHub
parent a7c146c24a
commit 25d57ab830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 13 deletions

3
.gitignore vendored
View File

@ -98,4 +98,5 @@ Carthage/Checkouts
*.profraw *.profraw
tuist.zip tuist.zip
build/ build/
tuistenv tuistenv
TODO

View File

@ -4,6 +4,10 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/
## Next version ## Next version
### Fixed
- Files and groups sort order https://github.com/tuist/tuist/pull/164 by @pepibumur.
## 0.8.0 ## 0.8.0
### Added ### Added

View File

@ -10,15 +10,6 @@
"version": "4.3.0" "version": "4.3.0"
} }
}, },
{
"package": "core",
"repositoryURL": "https://github.com/tuist/core.git",
"state": {
"branch": null,
"revision": "4500863dd846244323b29cb0950cb861e1fddcd0",
"version": null
}
},
{ {
"package": "Nimble", "package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git", "repositoryURL": "https://github.com/Quick/Nimble.git",

View File

@ -32,4 +32,12 @@ extension AbsolutePath {
public func removingLastComponent() -> AbsolutePath { public func removingLastComponent() -> AbsolutePath {
return AbsolutePath("/\(components.dropLast().joined(separator: "/"))") 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
}
}
} }

View File

@ -37,7 +37,7 @@ class ProjectFileElements {
files.formUnion(projectFiles(project: project)) files.formUnion(projectFiles(project: project))
/// Files /// Files
generate(files: files.sorted(), generate(files: files.sorted(by: AbsolutePath.xcodeSortener()),
groups: groups, groups: groups,
pbxproj: pbxproj, pbxproj: pbxproj,
sourceRootPath: sourceRootPath) sourceRootPath: sourceRootPath)
@ -119,7 +119,7 @@ class ProjectFileElements {
func generate(products: [String], func generate(products: [String],
groups: ProjectGroups, groups: ProjectGroups,
pbxproj: PBXProj) { pbxproj: PBXProj) {
products.forEach { productName in products.sorted().forEach { productName in
if self.products[productName] != nil { return } if self.products[productName] != nil { return }
let fileType = Xcode.filetype(extension: String(productName.split(separator: ".").last!)) let fileType = Xcode.filetype(extension: String(productName.split(separator: ".").last!))
let fileReference = PBXFileReference(sourceTree: .buildProductsDir, let fileReference = PBXFileReference(sourceTree: .buildProductsDir,
@ -278,7 +278,7 @@ class ProjectFileElements {
toGroup: PBXGroup, toGroup: PBXGroup,
pbxproj: PBXProj) { pbxproj: PBXProj) {
// /path/to/*.lproj/* // /path/to/*.lproj/*
absolutePath.glob("*").forEach { localizedFile in absolutePath.glob("*").sorted().forEach { localizedFile in
let localizedName = localizedFile.components.last! let localizedName = localizedFile.components.last!
// Variant group // Variant group

View File

@ -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"),
])
}
}