Plugin

This is the mother of all plugin classes. All Bajo plugin classess inherit from this class respectfully.

There are currently only two main plugins available:

  • Bajo - Core plugin class, responsible for system wide setup and boot process. You should not touch this obviously.
  • Base - Base plugin class your own plugin should inherite from.

Constructor

new Plugin(pkgName, app)

Parameters:
NameTypeDescription
pkgNamestring

Package name (the one you use in package.json).

appObject

App instance reference. Usefull to call app method inside a plugin.

Members

app :Object

Reference to the app instance.

Type:
  • Object

config :Object

Config object.

Type:
  • Object
See
  • config

dispose

Dispose internal references.

dump

Alias to this.app.dump().

log :Log

Shortcut to App#log with prefix parameter set to this plugin namespace.

Type:

t

Translate text and interpolate with given args.

Shortcut to App#t with ns parameter set to this plugin namespace.

te

Check whether translation text/key exists.

Shortcut to App#te with ns parameter set to this plugin namespace.

(static, readonly) this.alias :string

Plugin alias. Derived plugin must provide its own, unique alias. If it left blank, Bajo will provide this automatically (by using the kebab-cased version of plugin name).

Type:
  • string

(static, constant) this.ns :string

Namespace (ns) or plugin's name. Simply the camel cased version of plugin's package name.

Type:
  • string

(static, constant) this.pkgName :string

Package name, the one from package.json.

Type:
  • string

Methods

error(msg, …argsopt) → {Object}

Create an instance of Err object.

Parameters:
NameTypeAttributesDescription
msgstring

Error message.

argsany<optional>
<repeatable>

Argument variables you might want to add to the error object.

Returns:

Err instance.

Type: 
Object

fatal(msg, …argsopt)

Create an instance of Err object, display it on screen and then force terminate the app process.

Parameters:
NameTypeAttributesDescription
msgstring

Error message.

argsany<optional>
<repeatable>

Argument variables you might want to add to the error object.

getConfig(pathopt, optionsopt) → {Object}

Get plugin's config value.

Parameters:
NameTypeAttributesDefaultDescription
pathstring<optional>

dot separated config path (think of lodash's 'get'). If not provided, the full config will be given.

optionsObject<optional>
{}

Options.

Properties
NameTypeAttributesDefaultDescription
defValueany<optional>
{}

Default value to use if returned object is undefined.

omitArray.<string><optional>
[]

Omit these keys from returned object.

noCloneboolean<optional>
false

Set true to NOT clone returned object.

Returns:

Returned object. If no path provided, the whole config object is returned.

Type: 
Object

getPkgInfo(diropt, keysopt)

Get package info.

Parameters:
NameTypeAttributesDefaultDescription
dirstring<optional>

Package directory. Defaults to the current plugin's package dir.

keysArray<optional>
['name', 'version', 'description', 'author', 'license', 'homepage', 'bajo']

Field keys to be use. Set empty to use all keys.

selfBind(names)

Force bind methods to self (this).

Parameters:
NameTypeDescription
namesArray.<string>

Method's names.