Skip to content

Instantly share code, notes, and snippets.

@vjpr
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vjpr/e29a6006a3436552de2d to your computer and use it in GitHub Desktop.
Save vjpr/e29a6006a3436552de2d to your computer and use it in GitHub Desktop.
Research of existing Node.js plugin systems used by various modules.

Research of existing Node.js plugin systems used by various modules.

Hexo

https://hexo.io/docs/plugins.html

Place file in scripts folder.

or

Module name must be prefixed with hexo-.

Ghost

package.json should include version and dependencies:

// package.json

{
  "name":"my-app",
  "version": "0.x",
  "dependencies": {
    "ghost-app": "0.0.2"
  }
}

// index.js

var App = require('ghost-app'), MyApp

MyApp = App.extend({

  install: function () {},

  uninstall: function () {},

  activate: function () {},

  deactivate: function () {}

})

module.exports = MyApp

DocPad

# Export Plugin
module.exports = (BasePlugin) ->
    # Define Plugin
    class YourpluginnamePlugin extends BasePlugin
        # Plugin name
        name: 'yourpluginname'

Grunt

grunt.registerTask(taskName, [description, ] taskList)

Gulp

https://www.npmjs.com/package/gulp-load-plugins

gulpLoadPlugins({
  pattern: ['gulp-*', 'gulp.*'], // the glob(s) to search for 
  config: 'package.json', // where to find the plugins, by default searched up from process.cwd() 
  scope: ['dependencies', 'devDependencies', 'peerDependencies'], // which keys in the config to look within 
  replaceString: /^gulp(-|\.)/, // what to remove from the name of the module when adding it to the context 
  camelize: true, // if true, transforms hyphenated plugins names to camel case 
  lazy: true, // whether the plugins should be lazy loaded on demand 
  rename: {} // a mapping of plugins to rename 
})

Nash

https://github.com/scottcorgan/nash

Example of registering a plugin:

var nash = require('nash');
var myPlugin = require('my-plugin');
var cli = nash();

cli.register([{
  register: myPlugin,
  options: {
    key: 'value'
  }
}], function (err) {

  // Done loading plugins
});
Example plugin:

module.exports = function (cli, options, done) {

  cli.command('something')
    .handler(function (data, flags, done) {

      // Do something here
      done();
    });

  done();
};

Webpack Loader

AuraJS

this.sandbox.on('cats.update', this.render, this)

components.afterAppStart
emit
off
on
once
start
stopListening

Scatter

angular/di.js

import Bar from 'bar'

@Inject(Bar)
class Foo {

  constructor(bar) {

  }
  
}

@Provide(Bar)
class BarMock {

  
}

Atom

// atom/package-generator

MyPackageView = require './my-package-view'

module.exports =
  myPackageView: null

  activate: (state) ->
    @myPackageView = new MyPackageView(state.myPackageViewState)

  deactivate: ->
    @myPackageView.destroy()

  serialize: ->
    myPackageViewState: @myPackageView.serialize()

Backbone.Radio

https://github.com/marionettejs/backbone.radio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment