-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simple plugin system for schnack #99
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sto3psl
reviewed
Mar 12, 2019
sto3psl
reviewed
Mar 15, 2019
create-schnack/index.js
Outdated
|
||
const { plugins } = require(configPath); | ||
|
||
const packages = Object.keys(plugins).map(id => `schnack-plugin-${id}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script will crash if plugins is undefined
gka
force-pushed
the
feature/plugins
branch
2 times, most recently
from
May 24, 2020 17:36
62f16c5
to
8b0f213
Compare
just curious about the timeline for this, is this still under consideration? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refactors all of our currently supported authentication and notification methods into plugins.
The plugins are for now still part of this repo, but in theory they could already live in separate npm packages (and probably should be moved out soon as some might come with have hefty dependencies)
Plugin configuration
Plugins can be defined and configured via the new
config.plugins
section. To enable the twitter authentication and slack notifications, one would set the plugins config to this:Plugin loading
In this PR plugins are loaded (=
require
d) using the loadPlugins function. The function checks whether a plugin exists in one of two locations:src/plugins/${pluginId}
folder inside the Schnack repo, andschnack-plugin-${pluginId}
As mentioned above, we should probably at some point move all "core" plugins into npm packages at some point to get them out of our package.dependencies.
The
loadPlugins
function is currently evoked at two occasions: in src/auth.js and in src/notify.js (formerly known assrc/push/index.js
).There are two entry points that plugins can currently use:
auth
andnotify
.Plugin interface
As said, the plugins are being loaded at two locations, and each is only regarding plugins relevant to the part of Schnack where it's being loaded. In src/auth.js we are only invoking plugins that define the
auth()
hook, while in src/notify.js we only invoke plugins that define thenotify()
hook.So while at this point, all auth and notify plugins are separate, in the future there could be plugins that handle both authentication and notification.
The hook functions
auth()
andnotify()
are really only passing some internal variables to the plugins (which cannot easilyrequire
them if they live in a separate npm package). This separation between the Schnack "core" and the plugins is meant to discourage ugly hacking and dependencies on internal helper functions etc. Essentially, whatever we're passing as arguments through these two hook functions become part of the new "public" API of Schnack and changes to those will potentially break backwards compatibility.Example plugins
I already ported all existing auth and notify methods into plugins so you see plenty examples. Here's how the slack notification plugin looks like. It uses the
events
object to observe new comments and then send http requests to the Slack API.