Skip to content

Commit

Permalink
Merge pull request #52 from FelixHerrmann/release/3.0
Browse files Browse the repository at this point in the history
Release 3.0
  • Loading branch information
FelixHerrmann authored May 28, 2023
2 parents e6f8aa9 + 0ba13f0 commit 2a3d629
Show file tree
Hide file tree
Showing 13 changed files with 474 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,62 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SwiftPackageListJSONPlugin"
BuildableName = "SwiftPackageListJSONPlugin"
BlueprintName = "SwiftPackageListJSONPlugin"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SwiftPackageListPropertyListPlugin"
BuildableName = "SwiftPackageListPropertyListPlugin"
BlueprintName = "SwiftPackageListPropertyListPlugin"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SwiftPackageListSettingsBundlePlugin"
BuildableName = "SwiftPackageListSettingsBundlePlugin"
BlueprintName = "SwiftPackageListSettingsBundlePlugin"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SwiftPackageListPDFPlugin"
BuildableName = "SwiftPackageListPDFPlugin"
BlueprintName = "SwiftPackageListPDFPlugin"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down
24 changes: 24 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ let package = Package(
],
products: [
.executable(name: "swift-package-list", targets: ["SwiftPackageListCommand"]),
.plugin(name: "SwiftPackageListJSONPlugin", targets: ["SwiftPackageListJSONPlugin"]),
.plugin(name: "SwiftPackageListPropertyListPlugin", targets: ["SwiftPackageListPropertyListPlugin"]),
.plugin(name: "SwiftPackageListSettingsBundlePlugin", targets: ["SwiftPackageListSettingsBundlePlugin"]),
.plugin(name: "SwiftPackageListPDFPlugin", targets: ["SwiftPackageListPDFPlugin"]),
.library(name: "SwiftPackageList", targets: ["SwiftPackageList"]),
.library(name: "SwiftPackageListObjc", type: .dynamic, targets: ["SwiftPackageListObjc"]),
.library(name: "SwiftPackageListUI", targets: ["SwiftPackageListUI"]),
Expand All @@ -30,6 +34,26 @@ let package = Package(
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),
.plugin(
name: "SwiftPackageListJSONPlugin",
capability: .buildTool(),
dependencies: [.target(name: "SwiftPackageListCommand")]
),
.plugin(
name: "SwiftPackageListPropertyListPlugin",
capability: .buildTool(),
dependencies: [.target(name: "SwiftPackageListCommand")]
),
.plugin(
name: "SwiftPackageListSettingsBundlePlugin",
capability: .buildTool(),
dependencies: [.target(name: "SwiftPackageListCommand")]
),
.plugin(
name: "SwiftPackageListPDFPlugin",
capability: .buildTool(),
dependencies: [.target(name: "SwiftPackageListCommand")]
),
.target(
name: "SwiftPackageListCore",
dependencies: ["SwiftPackageList"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// SwiftPackageListJSONPlugin.swift
// SwiftPackageListJSONPlugin
//
// Created by Felix Herrmann on 22.05.23.
//

import Foundation
import PackagePlugin

@main
struct SwiftPackageListJSONPlugin: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
return []
}
}

#if canImport(XcodeProjectPlugin)
import XcodeProjectPlugin

extension SwiftPackageListJSONPlugin: XcodeBuildToolPlugin {
func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] {
let projectPath = context.xcodeProject.directory.appending("\(context.xcodeProject.displayName).xcodeproj")
let executable = try context.tool(named: "SwiftPackageListCommand").path
.removingLastComponent()
.appending("swift-package-list")
let outputPath = context.pluginWorkDirectory
let fileType = "json"
return [
.buildCommand(
displayName: "SwiftPackageListPlugin",
executable: executable,
arguments: ["generate", projectPath, "--output-path", outputPath, "--file-type", fileType, "--requires-license"],
outputFiles: [outputPath.appending("package-list.json")]
)
]
}
}
#endif
39 changes: 39 additions & 0 deletions Plugins/SwiftPackageListPDFPlugin/SwiftPackageListPDFPlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// SwiftPackageListPDFPlugin.swift
// SwiftPackageListPDFPlugin
//
// Created by Felix Herrmann on 27.05.23.
//

import Foundation
import PackagePlugin

@main
struct SwiftPackageListPDFPlugin: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
return []
}
}

#if canImport(XcodeProjectPlugin)
import XcodeProjectPlugin

extension SwiftPackageListPDFPlugin: XcodeBuildToolPlugin {
func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] {
let projectPath = context.xcodeProject.directory.appending("\(context.xcodeProject.displayName).xcodeproj")
let executable = try context.tool(named: "SwiftPackageListCommand").path
.removingLastComponent()
.appending("swift-package-list")
let outputPath = context.pluginWorkDirectory
let fileType = "pdf"
return [
.buildCommand(
displayName: "SwiftPackageListPlugin",
executable: executable,
arguments: ["generate", projectPath, "--output-path", outputPath, "--file-type", fileType, "--requires-license"],
outputFiles: [outputPath.appending("Acknowledgements.pdf")]
)
]
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// SwiftPackageListPropertyListPlugin.swift
// SwiftPackageListPropertyListPlugin
//
// Created by Felix Herrmann on 27.05.23.
//

import Foundation
import PackagePlugin

@main
struct SwiftPackageListPropertyListPlugin: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
return []
}
}

#if canImport(XcodeProjectPlugin)
import XcodeProjectPlugin

extension SwiftPackageListPropertyListPlugin: XcodeBuildToolPlugin {
func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] {
let projectPath = context.xcodeProject.directory.appending("\(context.xcodeProject.displayName).xcodeproj")
let executable = try context.tool(named: "SwiftPackageListCommand").path
.removingLastComponent()
.appending("swift-package-list")
let outputPath = context.pluginWorkDirectory
let fileType = "plist"
return [
.buildCommand(
displayName: "SwiftPackageListPlugin",
executable: executable,
arguments: ["generate", projectPath, "--output-path", outputPath, "--file-type", fileType, "--requires-license"],
outputFiles: [outputPath.appending("package-list.plist")]
)
]
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// SwiftPackageListSettingsBundlePlugin.swift
// SwiftPackageListSettingsBundlePlugin
//
// Created by Felix Herrmann on 27.05.23.
//

import Foundation
import PackagePlugin

@main
struct SwiftPackageListSettingsBundlePlugin: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
return []
}
}

#if canImport(XcodeProjectPlugin)
import XcodeProjectPlugin

extension SwiftPackageListSettingsBundlePlugin: XcodeBuildToolPlugin {
func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] {
let projectPath = context.xcodeProject.directory.appending("\(context.xcodeProject.displayName).xcodeproj")
let executable = try context.tool(named: "SwiftPackageListCommand").path
.removingLastComponent()
.appending("swift-package-list")
let outputPath = context.pluginWorkDirectory
let fileType = "settings-bundle"
return [
.buildCommand(
displayName: "SwiftPackageListPlugin",
executable: executable,
arguments: ["generate", projectPath, "--output-path", outputPath, "--file-type", fileType, "--requires-license"],
outputFiles: [outputPath.appending("Settings.bundle")]
)
]
}
}
#endif
57 changes: 42 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
[![Xcode Build](https://github.com/FelixHerrmann/swift-package-list/actions/workflows/xcodebuild.yml/badge.svg)](https://github.com/FelixHerrmann/swift-package-list/actions/workflows/xcodebuild.yml)
[![SwiftLint](https://github.com/FelixHerrmann/swift-package-list/actions/workflows/swiftlint.yml/badge.svg)](https://github.com/FelixHerrmann/swift-package-list/actions/workflows/swiftlint.yml)

A command-line tool to generate a JSON, PLIST, Settings.bundle or PDF file with all used SPM-dependencies of an Xcode project or workspace.
A command-line tool to get all used SPM-dependencies of an Xcode project or workspace.

The output includes all the `Package.resolved` informations and the license from the checkouts.
You can also generate a JSON, PLIST, Settings.bundle or PDF file.

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 file from the application's bundle with a top-level function or pre-build UI.


Expand All @@ -32,20 +34,45 @@ Clone or download this repository and run `make install`, `make update` or `make

### Usage

Open the terminal and run `swift-package-list <project-path>` with the path to the `.xcodeproj` or `.xcworkspace` file you want to generate the list from.
#### Scan Command

Open the terminal and run `swift-package-list scan <project-path>` with the path to the `.xcodeproj` or `.xcworkspace` file you want to get the JSON output from.

In addition to that you can specify the following options:

| Option | Description |
| ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| -d, --derived-data-path \<derived-data-path\> | The path to your DerivedData-folder. (default: ~/Library/Developer/Xcode/DerivedData) |
| -s, --source-packages-path <source-packages-path> | The path to a custom SourcePackages-folder. |
| -o, --output-path \<output-path\> | The path where the package-list file will be stored. (default: ~/Desktop) |
| -f, --file-type \<file-type\> | The file type of the generated package-list file. Available options are json, plist, settings-bundle and pdf. (default: json) |
| -c, --custom-file-name <custom-file-name> | A custom filename to be used instead of the default ones. |
| --requires-license | Will skip the packages without a license-file. |
| --version | Show the version. |
| -h, --help | Show help information. |
| Option | Description |
| --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| -d, --derived-data-path \<derived-data-path\> | The path to your DerivedData-folder. (default: ~/Library/Developer/Xcode/DerivedData) |
| -s, --source-packages-path \<source-packages-path\> | The path to a custom SourcePackages-folder. |
| --requires-license | Will skip the packages without a license-file. |
| --version | Show the version. |
| -h, --help | Show help information. |

#### Generate Command

Open the terminal and run `swift-package-list generate <project-path>` with the path to the `.xcodeproj` or `.xcworkspace` file you want to generate the list from.

In addition to that you can specify the following options:

| Option | Description |
| --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| -d, --derived-data-path \<derived-data-path\> | The path to your DerivedData-folder. (default: ~/Library/Developer/Xcode/DerivedData) |
| -s, --source-packages-path \<source-packages-path\> | The path to a custom SourcePackages-folder. |
| -o, --output-path \<output-path\> | The path where the package-list file will be stored. (default: ~/Desktop) |
| -f, --file-type \<file-type\> | The file type of the generated package-list file. Available options are json, plist, settings-bundle and pdf. (default: json) |
| -c, --custom-file-name \<custom-file-name\> | A custom filename to be used instead of the default ones. |
| --requires-license | Will skip the packages without a license-file. |
| --version | Show the version. |
| -h, --help | Show help information. |

### Build Tool Plugins

For each file type there is a dedicated plugin available which you can add to your targets.

Simply add them under the `Run Build Tool Plug-ins` section in the Target's Build Phases tab after you have added this package to the project's Package Dependencies.

Once added the file(s) will get generated during every build process and are available in the App's bundle.
You can then open them manually or use the various options in the included [Swift Package](#swift-package).

### Run Script Phase

Expand All @@ -56,7 +83,7 @@ You can easily set up a Run Script Phase in your target of your Xcode project to
```shell
if command -v swift-package-list &> /dev/null; then
OUTPUT_PATH=$SOURCE_ROOT/$TARGETNAME
swift-package-list "$PROJECT_FILE_PATH" --output-path "$OUTPUT_PATH" --requires-license
swift-package-list generate "$PROJECT_FILE_PATH" --output-path "$OUTPUT_PATH" --requires-license
else
echo "warning: swift-package-list not installed"
fi
Expand All @@ -78,7 +105,7 @@ you just need a slightly modified script for the Run Script Phase:
if command -v swift-package-list &> /dev/null; then
OUTPUT_PATH=$SOURCE_ROOT/$TARGETNAME
WORKSPACE_FILE_PATH=${PROJECT_FILE_PATH%.xcodeproj}.xcworkspace
swift-package-list "$WORKSPACE_FILE_PATH" --output-path "$OUTPUT_PATH" --requires-license
swift-package-list generate "$WORKSPACE_FILE_PATH" --output-path "$OUTPUT_PATH" --requires-license
else
echo "warning: swift-package-list not installed"
fi
Expand Down
Loading

0 comments on commit 2a3d629

Please sign in to comment.