From d1690bda81514b7ec4804552b0fe4ab546bceb5d Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Fri, 27 May 2016 17:00:49 +0200 Subject: [PATCH 1/6] Initial commit --- packages/xo-server-test-plugin/index.js | 23 +++++++++++++++++++++ packages/xo-server-test-plugin/package.json | 5 +++++ 2 files changed, 28 insertions(+) create mode 100644 packages/xo-server-test-plugin/index.js create mode 100644 packages/xo-server-test-plugin/package.json diff --git a/packages/xo-server-test-plugin/index.js b/packages/xo-server-test-plugin/index.js new file mode 100644 index 000000000..ded94014e --- /dev/null +++ b/packages/xo-server-test-plugin/index.js @@ -0,0 +1,23 @@ +exports.default = function (opts) { + return { + configure: function (configuration) { + console.log('stub configured', configuration) + }, + load: function () { + console.log('stub loaded') + }, + unload: function () { + console.log('stub unloaded') + } + } +} + +exports.configurationSchema = { + type: 'object', + properties: { + foo: { + type: 'string' + } + }, + required: ['foo'] +} diff --git a/packages/xo-server-test-plugin/package.json b/packages/xo-server-test-plugin/package.json new file mode 100644 index 000000000..70f531bc4 --- /dev/null +++ b/packages/xo-server-test-plugin/package.json @@ -0,0 +1,5 @@ +{ + "private": true, + "name": "xo-server-test-plugin", + "version": "0.0.0" +} From 02e1a32fae7595de55ce42df2f3b779122f407fa Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Fri, 27 May 2016 17:03:03 +0200 Subject: [PATCH 2/6] feat(README) --- packages/xo-server-test-plugin/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 packages/xo-server-test-plugin/README.md diff --git a/packages/xo-server-test-plugin/README.md b/packages/xo-server-test-plugin/README.md new file mode 100644 index 000000000..c223094b9 --- /dev/null +++ b/packages/xo-server-test-plugin/README.md @@ -0,0 +1,15 @@ +# xo-server-test-plugin + +## Install + +Either in xo-server's directory: + +``` +> npm i vatesfr/xo-server-test-plugin +``` + +Or globally: + +``` +> npm i -g vatesfr/xo-server-test-plugin +``` From b120146cdc2c04730b94c5bbc9531a845c3ae077 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Wed, 12 Oct 2016 17:21:45 +0200 Subject: [PATCH 3/6] chore(package): lots of comments --- packages/xo-server-test-plugin/index.js | 60 +++++++++++++++++++------ 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/packages/xo-server-test-plugin/index.js b/packages/xo-server-test-plugin/index.js index ded94014e..09c7b80e5 100644 --- a/packages/xo-server-test-plugin/index.js +++ b/packages/xo-server-test-plugin/index.js @@ -1,17 +1,10 @@ -exports.default = function (opts) { - return { - configure: function (configuration) { - console.log('stub configured', configuration) - }, - load: function () { - console.log('stub loaded') - }, - unload: function () { - console.log('stub unloaded') - } - } -} +// This is one of the simplest xo-server's plugin than can be created. +// This (optional) schema is used to describe the expected +// configuration of the plugin. +// +// It will be used to generate a configuration UI (xo-web) and to +// validate the provided configuration. exports.configurationSchema = { type: 'object', properties: { @@ -21,3 +14,44 @@ exports.configurationSchema = { }, required: ['foo'] } + +// 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. +// +// 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 { + + // This (optional) method is called each time the plugin is + // (re-)configured. + // + // Note: before being called, the configuration is validated + // against the provided configuration schema. + configure: function (configuration) { + console.log('stub configured', configuration) + }, + + // This method is called to load the plugin. + // + // Note 1: will only be called if the plugin is currently + // unloaded. + // + // Note 2: if the plugin is configurable, will only be called if + // the plugin has been successfully configured. + load: function () { + console.log('stub loaded') + }, + + // This (optional) method is called to unload the plugin. + // + // Note: will only be called if the plugin is currently loaded. + unload: function () { + console.log('stub unloaded') + } + } +} From 8496a9bebd9e001b42fc64fb1ef79e1e5e3ae194 Mon Sep 17 00:00:00 2001 From: Badr AZIZBI Date: Fri, 4 Nov 2016 13:42:23 +0100 Subject: [PATCH 4/6] 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') } } } From a2afe2fa1ab38d739ca1ff613515395b79db643f Mon Sep 17 00:00:00 2001 From: Badr AZIZBI Date: Fri, 4 Nov 2016 15:47:45 +0100 Subject: [PATCH 5/6] Error correction --- packages/xo-server-test-plugin/README.md | 30 +++++++++++------------- packages/xo-server-test-plugin/index.js | 9 +++---- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/packages/xo-server-test-plugin/README.md b/packages/xo-server-test-plugin/README.md index 098e86e79..4eff3c078 100644 --- a/packages/xo-server-test-plugin/README.md +++ b/packages/xo-server-test-plugin/README.md @@ -16,19 +16,19 @@ Or globally: ## Documentation -### The life cycle of plugins +### Plugin life cyle -#### First step: Initialising plugins +#### Initialization -When the xo-server start, he initialize and load plugins. Then, he recuperates the configuration schema and the test schema to store them. +When xo-server starts, it initializes and loads plugins. Then, he recuperates the configuration schema and the test schema to store them. -#### Second step: Get schemas +#### 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 +#### Test configuration -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. +Xo-web send data to xo-server for testing the configuration and saving it if successful. ### Principal Methods @@ -37,23 +37,21 @@ Xo-web send an object which contains the configuration schema and the test schem 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 +#### `configure(configuration) ` -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 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 +#### `unload() ` This method is called to unload the plugin. -#### Test +#### `test(data) ` 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. - - +Its only parameter is an object which contains the test values. diff --git a/packages/xo-server-test-plugin/index.js b/packages/xo-server-test-plugin/index.js index 9107992df..ade9ccf62 100644 --- a/packages/xo-server-test-plugin/index.js +++ b/packages/xo-server-test-plugin/index.js @@ -66,12 +66,13 @@ exports.default = function (opts) { }, // 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 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 configuration schema. + // 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 valid') + 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. } } } From a5ea24311ac78710f8882d052de12a9f28094975 Mon Sep 17 00:00:00 2001 From: Badr AZIZBI Date: Wed, 9 Nov 2016 15:53:16 +0100 Subject: [PATCH 6/6] Errors fixed --- packages/xo-server-test-plugin/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/xo-server-test-plugin/README.md b/packages/xo-server-test-plugin/README.md index 4eff3c078..d71006141 100644 --- a/packages/xo-server-test-plugin/README.md +++ b/packages/xo-server-test-plugin/README.md @@ -20,15 +20,15 @@ Or globally: #### Initialization -When xo-server starts, it initializes and loads plugins. Then, he recuperates the configuration schema and the test schema to store them. +When xo-server starts, it initializes plugins. -#### Get schemas +#### Loading plugins -The xo-web recuperates the configuration schema and the test schema from xo-server to generate a UI. +After initializing the plugins, the xo-server load them. -#### Test configuration +#### Test -Xo-web send data to xo-server for testing the configuration and saving it if successful. +XO clients send data to xo-server for testing the configuration and saving it if successful. ### Principal Methods @@ -41,7 +41,7 @@ Its only parameter is an object which currently only contains the instance of th 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.