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)

Constructor.

Parameters:
NameTypeDescription
pkgNamestring

Package name (the one in package.json)

appObject

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

Members

(readonly) 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

app :App

Reference to the app instance

Type:

config :Object

Configuration object.

Type:
  • Object
See
  • config

log :Log

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

Type:

ns :string

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

Type:
  • string

pkgName :string

Package name, the one from package.json.

Type:
  • string

Methods

(async) dispose() → {Promise.<void>}

Dispose internal references.

Returns:
Type: 
Promise.<void>

dump(…args) → {void}

Alias to this.app.dump().

Parameters:
NameTypeAttributesDescription
argsany<repeatable>

Arguments

Returns:
Type: 
void

error(msg, …argsopt) → {Err}

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: 
Err

fatal(msg, …argsopt) → {void}

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

Parameters:
NameTypeAttributesDescription
msgstring

Error message

argsany<optional>
<repeatable>

Argument variables you might want to add to the error object

Returns:
Type: 
void

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 object

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) → {Object}

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

Returns:

Package info object

Type: 
Object

selfBind(names) → {void}

Force bind methods to self (this).

Parameters:
NameTypeDescription
namesArray.<string>

Method's names

Returns:
Type: 
void

t(text, …params) → {string}

Translate text and interpolate with given args.

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

Parameters:
NameTypeAttributesDescription
textstring

Text to translate

paramsany<repeatable>

Variables to interpolate to text

Returns:
Type: 
string

te(text, …params) → {string}

Check whether translation text/key exists.

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

Parameters:
NameTypeAttributesDescription
textstring

Text to translate

paramsany<repeatable>

Variables to interpolate to text

Returns:
Type: 
string