Swiftpack.co - maiyama18/LicensesPlugin as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by maiyama18.
maiyama18/LicensesPlugin 0.1.6
A Swift Package build tool plugin to collect licenses of the library used in your swift package
⭐️ 67
🕓 47 weeks ago
.package(url: "https://github.com/maiyama18/LicensesPlugin.git", from: "0.1.6")

Banner


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.

  • License information is automatically updated during build process. No manual command execution needed
  • You can make custom UI to show the licenses. This plugin only provides data of the licenses, not UI containing them

Installation

Just add the package to your Package.swift.

let package = Package(
    // ...
    dependencies: [
        .package(url: "https://github.com/maiyama18/LicensesPlugin", from: "0.1.0")
    ],
    // ...
)

Usage

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.

GitHub

link
Stars: 67
Last commit: 47 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

0.1.6
47 weeks ago

What's Changed

Full Changelog: https://github.com/maiyama18/LicensesPlugin/compare/0.1.5...0.1.6

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