commit
5b8cdf06b3
@ -13,3 +13,45 @@ Or globally:
|
|||||||
```
|
```
|
||||||
> npm i -g vatesfr/xo-server-test-plugin
|
> npm i -g vatesfr/xo-server-test-plugin
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
### Plugin life cyle
|
||||||
|
|
||||||
|
#### Initialization
|
||||||
|
|
||||||
|
When xo-server starts, it initializes plugins.
|
||||||
|
|
||||||
|
#### Loading plugins
|
||||||
|
|
||||||
|
After initializing the plugins, the xo-server load them.
|
||||||
|
|
||||||
|
#### Test
|
||||||
|
|
||||||
|
XO clients send data to xo-server for testing the configuration and saving it if successful.
|
||||||
|
|
||||||
|
### Principal Methods
|
||||||
|
|
||||||
|
#### The default export
|
||||||
|
|
||||||
|
It is just a factory function which will create an instance of the plugin. Usually it will be called only once, at startup.
|
||||||
|
Its only parameter is an object which currently only contains the instance of the currently running xo-server.
|
||||||
|
|
||||||
|
#### `configure(configuration) `
|
||||||
|
|
||||||
|
This method is called each time the plugin is (re-)configured.
|
||||||
|
Its only parameter is an object which contains the configuration values.
|
||||||
|
|
||||||
|
#### `load() `
|
||||||
|
|
||||||
|
This method is called to load the plugin.
|
||||||
|
|
||||||
|
#### `unload() `
|
||||||
|
|
||||||
|
This method is called to unload the plugin.
|
||||||
|
|
||||||
|
#### `test(data) `
|
||||||
|
|
||||||
|
This method is called if the test option is activated.
|
||||||
|
Its only parameter is an object which contains the test values.
|
||||||
|
|
||||||
|
@ -15,6 +15,18 @@ exports.configurationSchema = {
|
|||||||
required: ['foo']
|
required: ['foo']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This (optional) schema is used to test the configuration
|
||||||
|
// of the plugin.
|
||||||
|
exports.testSchema = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
test: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
required: ['test']
|
||||||
|
}
|
||||||
|
|
||||||
// The default export is just a factory function which will create an
|
// The default export is just a factory function which will create an
|
||||||
// instance of the plugin.
|
// instance of the plugin.
|
||||||
// Usually it will be called only once, at startup.
|
// Usually it will be called only once, at startup.
|
||||||
@ -22,7 +34,6 @@ exports.configurationSchema = {
|
|||||||
// Its only parameter is an object which currently only contains a
|
// Its only parameter is an object which currently only contains a
|
||||||
// `xo` property: the instance of the currently running xo-server.
|
// `xo` property: the instance of the currently running xo-server.
|
||||||
exports.default = function (opts) {
|
exports.default = function (opts) {
|
||||||
|
|
||||||
// For simplicity's sake, this plugin returns a plain object, but
|
// For simplicity's sake, this plugin returns a plain object, but
|
||||||
// usually it returns a new instance of an existing class.
|
// usually it returns a new instance of an existing class.
|
||||||
return {
|
return {
|
||||||
@ -52,6 +63,16 @@ exports.default = function (opts) {
|
|||||||
// Note: will only be called if the plugin is currently loaded.
|
// Note: will only be called if the plugin is currently loaded.
|
||||||
unload: function () {
|
unload: function () {
|
||||||
console.log('stub unloaded')
|
console.log('stub unloaded')
|
||||||
|
},
|
||||||
|
|
||||||
|
// This (optional) method is called to test the configuration of the plugin.
|
||||||
|
// Note 1: will only be called if the plugin has been successfully configured and is loaded.
|
||||||
|
// Note 2: before being called, the test configuration is validated
|
||||||
|
// against the provided test data.
|
||||||
|
// Note 3: will only be called if the test option is activated.
|
||||||
|
test: function (data) {
|
||||||
|
console.log('the configuration is about to be tested')
|
||||||
|
// TODO: test the configuration, i.e, use the main feature of the plugin and throws any errors.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user