Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extension SwiftPackageListPlugin.Configuration {
let requiresLicense: Bool? // swiftlint:disable:this discouraged_optional_boolean
let ignorePackages: [String]? // swiftlint:disable:this discouraged_optional_collection
let customPackagesFilePaths: [String]? // swiftlint:disable:this discouraged_optional_collection
let customSourcePackagesPath: Path?
}
}

Expand Down
29 changes: 26 additions & 3 deletions Plugins/SwiftPackageListPlugin/SwiftPackageListPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ struct SwiftPackageListPlugin: Plugin {
projectPath: Path,
pluginWorkDirectory: Path
) throws -> [Command] {
let sourcePackagesPath = try sourcePackagesDirectory(pluginWorkDirectory: pluginWorkDirectory)
let sourcePackagesPath = try sourcePackagesDirectory(
pluginWorkDirectory: pluginWorkDirectory,
customSourcePackagesDirectory: targetConfiguration?.customSourcePackagesPath
)
let outputType = targetConfiguration?.outputType ?? .json
let outputPath = pluginWorkDirectory
let requiresLicense = targetConfiguration?.requiresLicense ?? true
Expand Down Expand Up @@ -52,7 +55,10 @@ struct SwiftPackageListPlugin: Plugin {
]
}

private func sourcePackagesDirectory(pluginWorkDirectory: Path) throws -> Path {
private func sourcePackagesDirectory(
pluginWorkDirectory: Path,
customSourcePackagesDirectory: Path?
) throws -> Path {
var path = pluginWorkDirectory
while path.string != "/" {
let potentialLocation = path.appending(subpath: "SourcePackages")
Expand All @@ -61,6 +67,23 @@ struct SwiftPackageListPlugin: Plugin {
}
path = path.removingLastComponent()
}
throw SwiftPackageListPlugin.Error.sourcePackagesNotFound(pluginWorkDirectory: pluginWorkDirectory)

guard let projectDirectory else {
throw SwiftPackageListPlugin.Error.sourcePackagesNotFound(pluginWorkDirectory: pluginWorkDirectory)
}
var possibleSourcePackagesPaths = [
path.appending([projectDirectory, "SourcePackages"]),
path.appending("SourcePackages"),
]
if let customSourcePackagesDirectory {
possibleSourcePackagesPaths.append(customSourcePackagesDirectory)
}
let sourcePackagesPath = possibleSourcePackagesPaths.first { path in
return FileManager.default.fileExists(atPath: path.string)
}
guard let sourcePackagesPath else {
throw SwiftPackageListPlugin.Error.sourcePackagesNotFound(pluginWorkDirectory: pluginWorkDirectory)
}
return sourcePackagesPath
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ By default this will use the JSON output with `--requires-license` but you can c
customPackagesFilePaths: [
"custom-packages.json",
],
"customSourcePackagesPath" : "./SourcePackages",
},
},
}
Expand Down