Initial commit
This commit is contained in:
parent
b120146cdc
commit
8496a9bebd
@ -13,3 +13,47 @@ Or globally:
|
||||
```
|
||||
> npm i -g vatesfr/xo-server-test-plugin
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
### The life cycle of plugins
|
||||
|
||||
#### First step: Initialising plugins
|
||||
|
||||
When the xo-server start, he initialize and load plugins. Then, he recuperates the configuration schema and the test schema to store them.
|
||||
|
||||
#### Second step: Get schemas
|
||||
|
||||
The xo-web recuperates the configuration schema and the test schema from xo-server to generate a UI.
|
||||
|
||||
#### Third step: Test configuration schema
|
||||
|
||||
Xo-web send an object which contains the configuration schema and the test schema 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
|
||||
|
||||
This method is called each time the plugin is (re-configured).
|
||||
Its only parameter is an object which contains the values putted on the confirmation form.
|
||||
|
||||
#### Load
|
||||
|
||||
This method is called to load the plugin.
|
||||
|
||||
#### Unload
|
||||
|
||||
This method is called to unload the plugin.
|
||||
|
||||
#### Test
|
||||
|
||||
This method is called if the test option is activated.
|
||||
Its only parameter is an object which contains the values putted on the test form.
|
||||
|
||||
|
||||
|
||||
|
@ -15,6 +15,18 @@ exports.configurationSchema = {
|
||||
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
|
||||
// instance of the plugin.
|
||||
// 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
|
||||
// `xo` property: the instance of the currently running xo-server.
|
||||
exports.default = function (opts) {
|
||||
|
||||
// For simplicity's sake, this plugin returns a plain object, but
|
||||
// usually it returns a new instance of an existing class.
|
||||
return {
|
||||
@ -52,6 +63,15 @@ exports.default = function (opts) {
|
||||
// Note: will only be called if the plugin is currently loaded.
|
||||
unload: function () {
|
||||
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.
|
||||
// Note 2: before being called, the test configuration is validated
|
||||
// against the provided test configuration schema.
|
||||
// Note 3: will only be called if the test option is activated.
|
||||
test: function(data){
|
||||
console.log('the configuration is valid')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user