GithubHelp home page GithubHelp logo

maiyama18 / licensesplugin Goto Github PK

View Code? Open in Web Editor NEW
68.0 1.0 2.0 53 KB

A Swift Package build tool plugin to collect licenses of the library used in your swift package

License: MIT License

Swift 100.00%
ios swift swiftpm

licensesplugin's Introduction

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.

licensesplugin's People

Contributors

maiyama18 avatar noppefoxwolf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

licensesplugin's Issues

Provide default UI

This plugin provides only data of licenses. It would be nice if default simple UI is also provided.

Cannot find "cp" when executed from command line

Currently, my project is configured with the following Package.swift.

let package = Package(
     ...
     .target(
            name: "Licence",
            plugins: [
                 .plugin(name: "LicensesPlugin", package: "LicensesPlugin")
            ]
     ),
     ...
     .executableTarget(
           name: "SomeBinary"
     )
)

When I try to use SomeBinary in a swift build, the following error occurs.

error: Plugin does not have access to a tool named "cp".

It seems that the location of the cp command has not been discovered.

This does not affect the execution of SomeBinary.

Publish `License` struct as a package

I would like to use LicensesPlugin in my app, but I have found that it is a bit difficult to use with multi moduled package.

For my usecase, there is one App module and other feature modules (ListFeature, DetailFeature, SettingsFeature and so on.). Probably I can introduce LicensesPlugin in App module but I need to convey the generated list into SettingsFeature to show on UI in SettingsPage. but License struct is unavailable outside of App module.
I think this usecase is not supported as of v0.1.3.

To solve it, I would like you to export interface of LicensesPlugin.License as a package to use it in other package except for App package.

Provide example license

Provide license of this plugin as an example that can be used from previews or tests. Only for debug build.

Format generated code

Generated code is now not formatted correctly like below example. It works, but it looks better if it is formatted.

public enum LicensesPlugin {
    public struct License: Identifiable, Equatable, Hashable {
        public let id: String
        public let name: String
        public let licenseText: String?
    }

    public static let licenses: [License] = [
        License(
    id: "swift-async-algorithms",
    name: "AsyncAlgorithms",
    licenseText: """

// ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.