Skip to content

Plugin Architecture

Konstantin Käfer edited this page May 17, 2011 · 2 revisions

Modules providing functionality to a Bones application are called plugins. Every plugin has the same structure: An index.js file, and models, views, controllers, commands and/or servers in subdirectories. Bones’ core functionality is also implemented as a plugin; the only difference is that Bones loads it automatically.

index.js

// Load child plugins
require('tilestream');
require('bones-auth');

// Load this plugin
require('bones').load(__dirname);

if (module.parent) {
    // Start processing commands
    require('bones').start();
}

Load order

Within a plugin, the default load order is:

  • Controllers
  • Models
  • Templates
  • Views
  • Servers
  • Commands

Among each kind, files are loaded alphabetically. If this doesn't work for you (e.g. when your Countries collection depends on the Country model), add requires to these files to index.js:

// Required to initialize loader for *.bones files
require('bones');

// Explicit load order
require('./models/country');
require('./models/countries');

// Load the rest of this plugin
require('bones').load(__dirname);

When loading multiple plugins, all files of one plugin are loaded before Bones proceeds to load the next plugin.

Components are sent to the client in the same order they were loaded on the server, i.e. you can influence the client's load order by using require() in index.js.

Clone this wiki locally