Swiftpack.co - chiahsien/XcodeProjSorter as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by chiahsien.
chiahsien/XcodeProjSorter 0.3.0
A command-line tool to sort Xcode's `.xcodeproj` file.
⭐️ 8
🕓 2 years ago
.package(url: "https://github.com/chiahsien/XcodeProjSorter.git", from: "0.3.0")

XcodeProjSorter

A library with command line interface to sort Xcode's .xcodeproj file. It sorts following sessions:

  • PBXGroup and PBXVariantGroup
  • PBXResourcesBuildPhase
  • PBXSourcesBuildPhase
  • Targets
  • Remote Swift packages

Command Line Tool

You can find the command-line tool project under CLI directory and build it by yourself. Or, you can download it from releases page.

Usage

xcodeproj-sorter [--case-insensitive] [--numeric] <path-to-xcodeproj-file>

Use xcodeproj-sorter -h for more information.

You can use it to sort Xcode project file before committing it to git version control. Sorting project file can reduce merging conflict possibility.

1.

Create a Tools directory in project root directory, and put xcodeproj-sorter into Tools directory.

2.

Put following codes into .git/hooks/pre-commit.

#!/bin/sh
#
# Following script is to sort Xcode project files, and add them back to version control.
# The reason to sort project file is that it can reduce project.pbxproj file merging conflict possibility.
#
echo 'Sorting Xcode project files'

GIT_ROOT=$(git rev-parse --show-toplevel)
sorter="$GIT_ROOT/Tools/xcodeproj-sorter"
modifiedProjectFiles=( $(git diff --name-only --cached | grep "project.pbxproj") )

for filePath in ${modifiedProjectFiles[@]}; do
  fullFilePath="$GIT_ROOT/$filePath"
  $sorter -n $fullFilePath
  git add $fullFilePath
done

echo 'Done sorting Xcode project files'

exit 0

3.

Put following line into .gitattributes then commit it.

*.pbxproj merge=union

License

MIT license.

GitHub

link
Stars: 8
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Release Notes

2 years ago

Add two options:

-c, --case-insensitive  Sort file name with case insensitive.
-n, --numeric           Sort file name using numeric value, that is, 2.txt < 7.txt < 25.txt.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics