{"id":22416430,"url":"https://github.com/lewandowskit93/plug","last_synced_at":"2025-03-27T04:20:06.924Z","repository":{"id":42443648,"uuid":"240723352","full_name":"lewandowskit93/Plug","owner":"lewandowskit93","description":null,"archived":false,"fork":false,"pushed_at":"2022-07-22T05:19:12.000Z","size":244,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-01T20:47:18.890Z","etag":null,"topics":["ios","linux","macos","osx","plug","plugin-architecture","plugin-managemen","plugin-manager","plugin-sdk","plugin-system","swift","tvos","watchos"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lewandowskit93.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-15T14:09:36.000Z","updated_at":"2020-02-29T03:57:30.000Z","dependencies_parsed_at":"2022-08-25T11:21:39.894Z","dependency_job_id":null,"html_url":"https://github.com/lewandowskit93/Plug","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lewandowskit93%2FPlug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lewandowskit93%2FPlug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lewandowskit93%2FPlug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lewandowskit93%2FPlug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lewandowskit93","download_url":"https://codeload.github.com/lewandowskit93/Plug/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245779485,"owners_count":20670688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","linux","macos","osx","plug","plugin-architecture","plugin-managemen","plugin-manager","plugin-sdk","plugin-system","swift","tvos","watchos"],"created_at":"2024-12-05T15:16:16.537Z","updated_at":"2025-03-27T04:20:06.904Z","avatar_url":"https://github.com/lewandowskit93.png","language":"Swift","readme":"[![Build Status](https://travis-ci.org/lewandowskit93/Plug.svg?branch=master)](https://travis-ci.org/lewandowskit93/Plug)\n[![codecov](https://codecov.io/gh/lewandowskit93/Plug/branch/master/graph/badge.svg)](https://codecov.io/gh/lewandowskit93/Plug)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-Compatible-brightgreen.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Cocoapods](https://img.shields.io/cocoapods/v/Plug.svg?style=flat)](https://cocoapods.org/pods/Plug)\n[![Platform](https://img.shields.io/cocoapods/p/Plug.svg?style=flat)](https://cocoapods.org/pods/Plug)\n[![Platform](https://img.shields.io/badge/Platform-linux-brightgreen.svg)](#)\n[![License](https://img.shields.io/cocoapods/l/Plug.svg?style=flat)](https://cocoapods.org/pods/Plug)\n\nPlug is a multi-platform plugin architecture micro-framework and plugin manager written in pure Swift. It allows to define rules that has to be met to activate plugins at given plugin point.\n\n## Requirements\n\n### Development\nProject uses following tools for development\n1. [XCodeGen](https://github.com/yonaskolb/XcodeGen)\n2. [Cocoapods](https://cocoapods.org)\n3. [SwiftLint](https://github.com/realm/SwiftLint)\n\n## Installation\n\nTo get started with the **Plug** you first have to decide how you will integrate it with your project. Plug supports following tools:\n\n### Cocoapods\n\nTo install Plug using Cocoapods go through following steps:\n\n1. Add the following entry in your **Podfile**:\n```\npod 'Plug'\n```\n2. Then run `pod install`.\n\n\n### Carthage\n\nTo install Plug using Carthage go through following steps:\n\n1. Add the following entry to your **Cartfile**\n\n```\ngithub \"lewandowskit93/Plug\"\n```\n\n2. Then run ```carthage update```\n\n### Swift Package Manager\n\nTo install Plug using **Swift Package Manager** go through following steps:\n\n1. Add following package dependency in you **Package.swift** ``` .package(url: \"https://github.com/lewandowskit93/Plug.git\", from: \"0.4.0\") ```\n2. Add following target dependency in your **Package.swift** ``` dependencies: [\"Plug\"]) ```\n\nFor instance this is how it might look like:\n```swift\nimport PackageDescription\n\nlet package = Package(\n    name: \"YourLibrary\",\n    products: [\n        .library(\n            name: \"YourLibrary\",\n            targets: [\"YourLibrary\"])\n    ],\n    dependencies: [\n        .package(url: \"https://github.com/lewandowskit93/Plug.git\", from: \"0.4.0\")\n    ],\n    targets: [\n        .target(\n            name: \"YourLibrary\",\n            dependencies: [\"Plug\"])\n    ]\n)\n```\n\n## Overview\n\nHere is a quick overview of functionalities and concepts used in **Plug**.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"Resources/Plug.png\" alt=\"Plug example\"/\u003e\n\u003c/p\u003e\n\n### Plugin\n\n**Plugin** is anything that implements **PPlugin** protocol. You can define what your plugins are and what they do.\n\nAs an example here you can see *ViewPlugin* which can return single SwiftUI view:\n```swift\npublic final class ViewPlugin\u003cV: View\u003e: PPlugin {\n    private let builder: () -\u003e V\n    \n    public init(builder: @escaping () -\u003e V) {\n        self.builder = builder\n    }\n    \n    public var view: some View {\n        return builder()\n    }\n}\n```\n\n### RuleResolvingContext\n\n**RuleResolvingContext** is anything that implements **PRuleResolvingContext**. Everything in the Plug is generic over PRuleResolvingContext. It can provide additional information to decide if the plugins are enabled.\n\n### Rule\n\n**Rule** decides whether plugins should be returned or not depending on the context. You can define your own rules by implementing **PRule** protocol.\nThere are a few rules available for you: *AtomRule*, *EnabledRule*, *DisabledRule*, *InvertedRule*, *AllOfRule*, *AnyOfRule*, *NoneOfRule*, *AnyRule*.\n\n### PluginPoint\n\n**PluginPoint** defines a single slot to which plugins can be attached. Single plugin point can have multiple plugins and rules that describes them.\nIt has a hierarchical structure meaning that a plugin point can have *children* plugin points.\nThe rules applied to a plugin point are also applied to it's children. Plugin points can be built with **PluginPointBuilder**\n\n### DSL\nPlug defines some operators and DSL to shorten building of plugin points. Available operators are:\n- Adding plugin with operator: *Builder \u003c+ Plugin*\n- Removign plugin with operator: *Builder \u003c- Plugin*\n- Adding rule with operator: *Builder §+ Rule*\n- Removing rule with operator: *Builder §- Rule*\n- Adding child with operator: *Builder |+ PluginPoint*\n- Removing child with operator: *Builder |- PluginPoint*\n- Finalize building with operator: *Builder^*\n\nThere are also operators available for rules building:\n- Inverting a rule: *!AnyRule*\n- AllOfRule: *\u0026\u0026[AnyRule]*\n- NoneOfRule: *~~[AnyRule]*\n- AnyOfRule: *||[AnyRule]*\n\n\n## Example\n\nThis is an example definition of plugin point which allows two plugin features to exist if they are enabled in FooContext.\n\n```swift\nvar pluginPoint = PluginPointBuilder()\n    .add(child: PluginPointBuilder()\n        .add(plugin: pluginFactory.feature1Plugin())\n        .add(rule: FeatureEnabledRule(id: \"feature_1\").any())\n        .build()\n    )\n    .add(child: PluginPointBuilder()\n        .add(plugin: pluginFactory.feature2Plugin())\n        .add(rule: FeatureEnabledRule(id: \"feature_2\").any())\n        .build()\n    ).build()\nvar availablePlugins = pluginPoint.getAvailablePlugins(context: FooContext())\n```\n\nThe same plugin point could be defined using operators as follows:\n\n\n```swift\nvar pluginPoint = (\n        PluginPointBuilder()\n        |+ (\n            PluginPointBuilder()\n            \u003c+ pluginFactory.feature1Plugin()\n            §+ FeatureEnabledRule(id: \"feature_1\").any()\n           )^\n        |+ (\n            PluginPointBuilder()\n            \u003c+ pluginFactory.feature2Plugin()\n            §+ FeatureEnabledRule(id: \"feature_2\").any()\n           )^\n    )^\nvar availablePlugins = pluginPoint.getAvailablePlugins(context: FooContext())\n```\n\nor using DSL as follows:\n\n```swift\nvar pluginPoint = PluginPoint {\n    child {\n        PluginPoint {\n            plugin(contextType: Context.self) { pluginFactory.feature1Plugin() }\n            rule(pluginType: Plugin.self) { FeatureEnabledRule(id: \"feature_1\").any() }\n        }\n    }\n    child {\n        PluginPoint {\n            plugin(contextType: Context.self) { pluginFactory.feature2Plugin() }\n            rule(pluginType: Plugin.self) { FeatureEnabledRule(id: \"feature_2\").any() }\n        }\n    }\n}\n```\n\nFor more detailed example please see the source code.\n\n## Contribution\n\nProject is created and maintained by **Tomasz Lewandowski**.\n\nIf you created some new feature or fixed a bug you can create a pull request. Please feel free to submit your feature requests if you have any.\n\n## License\n\nPlug is released under an MIT license. See [License.md](LICENSE.md) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flewandowskit93%2Fplug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flewandowskit93%2Fplug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flewandowskit93%2Fplug/lists"}