Constructor
new Plugin(pkgName, app)
Constructor.
| Name | Type | Description |
|---|---|---|
pkgName | string | Package name (the one in package.json) |
app | Object | App instance reference. Usefull to call app method inside a plugin |
- Source
Members
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).
By convention, plugin alias should be all lower case, alphanumeric, and without any space or special character except -. It should be unique across all plugins in the Bajo framework, as it is used to identify the plugin in the system beside its namespace.
- string
- Source
app :App
Reference to the app instance
- Source
config :TConfig
Configuration object.
- Source
- See
- config
log :Log
Shortcut to App#log with prefix parameter set to this plugin namespace.
- Source
ns :string
Namespace (ns) or plugin's name. It is the camel cased version of plugin's package name.
- string
- Source
pkgName :string
Package name, the one from package.json.
- string
- Source
Methods
bindThis(…names) → {void}
Force bind methods to this context.
Since JavaScript's this is dynamic, this method is useful to ensure that the methods always refer to the correct instance of the class.
Typically, you would call this method in the constructor of your plugin class, passing an array of method names or imported functions that you want to bind.
| Name | Type | Attributes | Description |
|---|---|---|---|
names | string | | <repeatable> | Method's names or function references to bind to |
- Source
- Type:
- void
(async) dispose() → {Promise.<void>}
Dispose internal references.
- Source
- Type:
- Promise.<void>
dump(…args) → {void}
Shortcut to this.app.dump().
| Name | Type | Attributes | Description |
|---|---|---|---|
args | * | <repeatable> | Arguments |
- Source
- Type:
- void
error(msg, …argsopt) → {Err}
Create an instance of Err object by providing an error message and optional arguments. Error instance will then be displayed on console and returned so you can chain it with other methods if you want.
Typically, you would use this method to throw an error and the framework will handle it gracefully.
This method is a shortcut to create a new Err instance.
| Name | Type | Attributes | Description |
|---|---|---|---|
msg | string | Error message | |
args | * | <optional> <repeatable> | Argument variables you might want to add to the error object |
- Source
- See
Err instance
- Type:
- Err
fatal(msg, …argsopt) → {void}
Same as Plugin#error but will forcefully terminate the process after printing the error to console.
| Name | Type | Attributes | Description |
|---|---|---|---|
msg | string | Error message | |
args | * | <optional> <repeatable> | Argument variables you might want to add to the error object |
- Source
- Type:
- void
getConfig(pathopt, optionsopt) → {Object}
Get plugin's configuration object's value.
Note: Configuration object is frozen after boot process, so you can't modify it at runtime. If you want to change its values, you need to do it in the config file, program options or via environment variables. Hooks are also available to modify the configuration before the boot process.
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
path | string | <optional> | dot separated config path (think of lodash's 'get'). If not provided, the full config will be given | |||||||||||||||||||||
options | Object | <optional> | {} | Options object Properties
|
- Source
Returned object. If no path provided, the whole config object is returned
- Type:
- Object
getPkgInfo(diropt, keysopt) → {Object}
Get package info. Basically it reads the package.json file and returns the requested fields
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
dir | string | <optional> | Package directory. Defaults to the current plugin's package dir | |
keys | Array | <optional> | ['name', 'version', 'description', 'author', 'license', 'homepage', 'bajo'] | Field keys to be use. Set empty to use all keys |
- Source
Package info object
- Type:
- Object
t(text, …args) → {string}
Translate text and interpolate with given args.
Shortcut to App#t with ns parameter set to this plugin namespace.
| Name | Type | Attributes | Description |
|---|---|---|---|
text | string | Text to translate | |
args | * | <repeatable> | Arguments to interpolate to |
- Source
- See
- Type:
- string
te(text, …args) → {boolean}
Check whether translation text (key) exists.
Shortcut to App#te with ns parameter set to this plugin namespace.
| Name | Type | Attributes | Description |
|---|---|---|---|
text | string | Text to translate | |
args | * | <repeatable> | Arguments to interpolate to |
- Source
- See
- Type:
- boolean