From 8496a9bebd9e001b42fc64fb1ef79e1e5e3ae194 Mon Sep 17 00:00:00 2001 From: Badr AZIZBI Date: Fri, 4 Nov 2016 13:42:23 +0100 Subject: [PATCH] Initial commit --- packages/xo-server-test-plugin/README.md | 44 ++++++++++++++++++++++++ packages/xo-server-test-plugin/index.js | 22 +++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/packages/xo-server-test-plugin/README.md b/packages/xo-server-test-plugin/README.md index c223094b9..098e86e79 100644 --- a/packages/xo-server-test-plugin/README.md +++ b/packages/xo-server-test-plugin/README.md @@ -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. + + + diff --git a/packages/xo-server-test-plugin/index.js b/packages/xo-server-test-plugin/index.js index 09c7b80e5..9107992df 100644 --- a/packages/xo-server-test-plugin/index.js +++ b/packages/xo-server-test-plugin/index.js @@ -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') } } }