LicensesPlugin is a swift package plugin that provides license information of the libraries your swift package depends on. Currently, the licenses of only swift packages are collected.
This plugin has the following features.
Just add the package to your Package.swift
.
let package = Package(
// ...
dependencies: [
.package(url: "https://github.com/maiyama18/LicensesPlugin", from: "0.1.0")
],
// ...
)
Apply the plugin as the dependency of the target you can show licenses.
let package = Package(
// ...
targets: [
// ...
.target(
name: "SomeFeature",
plugins: [
.plugin(name: "LicensesPlugin", package: "LicensesPlugin"),
]
),
// ...
]
// ...
)
In the target the plugin applied, the information of all the licenses of the libraries your package depends on is provided asLicensesPlugin.licenses
, and you can use it to make UI showing the licenses. The type of the elements of LicensePlugin.licenses
is below.
public enum LicensesPlugin {
public struct License: Identifiable, Equatable, Hashable {
public let id: String
public let name: String
public let licenseText: String?
}
}
For example, you can construct the UI like this.
/// SomeFeature/LicensesScreen.swift
struct LicensesScreen: View {
@State private var selectedLicense: LicensesPlugin.License?
var body: some View {
List {
ForEach(LicensesPlugin.licenses) { license in
Button {
selectedLicense = license
} label: {
Text(license.name)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
}
.sheet(item: $selectedLicense) { license in
NavigationStack {
Group {
if let licenseText = license.licenseText {
ScrollView {
Text(licenseText)
.padding()
}
} else {
Text("No License Found")
}
}
.navigationTitle(license.name)
}
}
.navigationTitle("Licenses")
}
}
Note that this plugin provides the licenses of all the libraries your swift package depends on, not just the target this plugin applied depends on.
link |
Stars: 43 |
Last commit: 1 week ago |
Full Changelog: https://github.com/maiyama18/LicensesPlugin/compare/0.1.2...0.1.3
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics