SwiftPackageList
A command-line tool to generate a JSON-list of all used SPM-dependencies of an Xcode-project.
This includes all the Package.resolved
informations and the license from the checkouts. Additionally there is a Swift Package to read the generated package-list.json
from the application's bundle.
Command-Line Tool
Installation
Clone or download this repository and execute the install script with sudo sh install.sh
. After that you can run the swift-package-list
command in your terminal.
There is also an uninstall script for convenience.
Usage
Open the terminal and run swift-package-list
with the directory to the .xcodeproj
-file you want to generate the list from.
In addition to that you can specify the following options:
Option | Description |
---|---|
-d, --derived-data-path |
The directory to your DerivedData-folder. (default: ~/Library/Developer/Xcode/DerivedData) |
-o, --output-path |
The path where the package-list.json-file will be stored. (default: ~/Desktop) |
--requires-license | Will skip the packages without a license-file. |
--version | Show the version. |
-h, --help | Show help information. |
Run Script Phase
You can easily set up a Run Script Phase in your target of your Xcode-project to keep the package-list.json
up to date automatically:
- open the corresponding target and click on the plus under the Build Phases section
- select New Run Script Phase and add the following script into the code box:
# creates/updates package-list.json on every build
if type swift-package-list &> /dev/null; then
output_path=${PRODUCT_SETTINGS_PATH%/Info.plist}
swift-package-list $PROJECT_FILE_PATH --output-path $output_path --requires-license
else
echo "warning: swift-package-list not installed"
fi
- optionally you can rename the Phase by double-clicking on the title
- build your project (cmd + b)
- right-click on the targets-folder in the sidebar and select Add Files to "
" - select
package-list.json
in the Finder-window
The package-list.json
-file will be updated now on every build and can be opened from the bundle in you app. You can do that manually or use the package for that (as follows).
Swift Package
Load package-list.json
from the bundle with a single function call.
Requirements
- macOS 10.10+
- iOS 9.0+
- tvOS 9.0+
- watchOS 2.0+
Usage
Add the package to your project as shown here.
Now you can retrieve the packages from the file like this:
import SwiftPackageList
do {
let packages = try packageList()
// use packages
} catch PackageListError.noPackageList {
print("There is no package-list.json file")
} catch {
print(error)
}
License
SwiftPackageList is available under the MIT license. See the LICENSE file for more info.