Comparing version 1.2.0 to 2.0.0
100
lib/index.js
@@ -32,11 +32,10 @@ 'use strict'; | ||
internals.convertToGlue = function(epoxyManifest) { | ||
var glueManifest = Hoek.clone(epoxyManifest); | ||
var glueManifest = Hoek.cloneWithShallow(epoxyManifest, ['plugins']); | ||
if (epoxyManifest.hasOwnProperty('plugins')) { | ||
var gluePlugins = {}; | ||
var glueRegistrations = []; | ||
var epoxyPlugins = epoxyManifest.plugins; | ||
delete glueManifest.plugins; | ||
Object.keys(epoxyPlugins).forEach(function (epoxyPluginKey) { | ||
var glueRegistrations = []; | ||
// NB: The plugin may have no options to pass to it, or an implicit single registration | ||
@@ -48,29 +47,36 @@ var epoxyPlugin = epoxyPlugins[epoxyPluginKey] || {}; | ||
pluginRegistrations.forEach(function(epoxyRegistration) { | ||
var glueRegistration = {}; | ||
var glueRegistration = {plugin: {}}; | ||
if (epoxyRegistration.hasOwnProperty('registrationOptions')) { | ||
Hoek.merge(glueRegistration, epoxyRegistration.registrationOptions); | ||
glueRegistration.options = {}; | ||
Hoek.merge(glueRegistration.options, epoxyRegistration.registrationOptions); | ||
} | ||
if (epoxyRegistration.hasOwnProperty('pluginOptions')) { | ||
glueRegistration.options = {}; | ||
Hoek.merge(glueRegistration.options, epoxyRegistration.pluginOptions); | ||
glueRegistration.plugin.options = {}; | ||
Hoek.merge(glueRegistration.plugin.options, epoxyRegistration.pluginOptions); | ||
} | ||
glueRegistrations.push(glueRegistration); | ||
}); | ||
// Create the new Glue registration entry for each plugin. Assume node module by default | ||
var gluePluginName = epoxyPluginKey; | ||
var pluginPath = epoxyPlugin.pluginPath; | ||
// Create the new Glue manifest entry for each plugin. Assume node module by default | ||
var gluePluginName = epoxyPluginKey; | ||
var pluginPath = epoxyPlugin.pluginPath; | ||
if (pluginPath) { | ||
// Path.join will actually not include the relative path, so set it manually if it's there | ||
gluePluginName = pluginPath[0] === '.' ? './' : ''; | ||
gluePluginName += Path.join(pluginPath, epoxyPluginKey); | ||
} | ||
if (pluginPath) { | ||
// Path.join will actually not include the relative path, so set it manually if it's there | ||
gluePluginName = pluginPath[0] === '.' ? './' : ''; | ||
gluePluginName += Path.join(pluginPath, epoxyPluginKey); | ||
} | ||
if (glueRegistration.plugin.hasOwnProperty('options')) { | ||
glueRegistration.plugin.register = gluePluginName; | ||
} | ||
else { | ||
glueRegistration.plugin = gluePluginName; | ||
} | ||
gluePlugins[gluePluginName] = glueRegistrations; | ||
glueRegistrations.push(glueRegistration); | ||
}); | ||
}) | ||
glueManifest.plugins = gluePlugins; | ||
glueManifest.registrations = glueRegistrations; | ||
} | ||
@@ -103,46 +109,30 @@ | ||
exports.convertToEpoxy = function(glueManifest) { | ||
var epoxyManifest = Hoek.clone(glueManifest); | ||
var epoxyManifest = Hoek.cloneWithShallow(glueManifest, ['registrations']); | ||
if (epoxyManifest.hasOwnProperty('plugins')) { | ||
if (glueManifest.hasOwnProperty('registrations')) { | ||
var epoxyPlugins = {}; | ||
var gluePlugins = glueManifest.plugins; | ||
var glueRegistrations = glueManifest.registrations; | ||
delete epoxyManifest.registrations; | ||
Object.keys(gluePlugins).forEach(function (gluePluginKey) { | ||
var epoxyRegistrations = []; | ||
glueRegistrations.forEach(function (glueRegistration) { | ||
// Figure out the new Epoxy plugin name and path | ||
var epoxyPluginName = Path.basename(gluePluginKey); | ||
var epoxyPluginPath = epoxyPluginName === gluePluginKey ? '' : Path.dirname(gluePluginKey); | ||
var gluePluginRegister = glueRegistration.plugin.register || glueRegistration.plugin; | ||
var epoxyPluginName = Path.basename(gluePluginRegister); | ||
var epoxyPluginPath = epoxyPluginName === gluePluginRegister ? '' : Path.dirname(gluePluginRegister); | ||
// NB: The plugin may have no options to pass to it, or an implicit single registration | ||
var pluginRegistrations = gluePlugins[gluePluginKey]; | ||
if (!Array.isArray(pluginRegistrations)) { | ||
var hasOptions = pluginRegistrations && Object.keys(pluginRegistrations).length; | ||
pluginRegistrations = hasOptions ? [{options: pluginRegistrations}] : [{}]; | ||
var epoxyRegistration = {}; | ||
if (glueRegistration.plugin.options) { | ||
epoxyRegistration.pluginOptions = Hoek.clone(glueRegistration.plugin.options); | ||
} | ||
if (glueRegistration.options) { | ||
epoxyRegistration.registrationOptions = Hoek.clone(glueRegistration.options); | ||
} | ||
// Perform plugin munging | ||
pluginRegistrations.forEach(function(glueRegistration) { | ||
var epoxyRegistration = {}; | ||
// Make sure we have options before doing work. Purely aesthetic. | ||
if (Object.keys(glueRegistration).length) { | ||
if (glueRegistration.hasOwnProperty('options')) { | ||
epoxyRegistration.pluginOptions = glueRegistration.options; | ||
delete glueRegistration.options; | ||
} | ||
var remainingOptions = Object.keys(glueRegistration); | ||
if (remainingOptions.length) { | ||
epoxyRegistration.registrationOptions = glueRegistration; | ||
} | ||
} | ||
epoxyRegistrations.push(epoxyRegistration); | ||
}); | ||
epoxyPlugins[epoxyPluginName] = { | ||
var epoxyPlugin = epoxyPlugins[epoxyPluginName] || { | ||
pluginPath: epoxyPluginPath, | ||
registrations: epoxyRegistrations, | ||
registrations: [], | ||
}; | ||
epoxyPlugin.registrations.push(epoxyRegistration); | ||
epoxyPlugins[epoxyPluginName] = epoxyPlugin; | ||
}); | ||
@@ -149,0 +139,0 @@ |
{ | ||
"name": "hapi-epoxy", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "Flexible YAML configuration for Hapi", | ||
@@ -21,6 +21,6 @@ "license": "MIT", | ||
}, | ||
"engines": {"node": ">=0.10.41", "npm": ">=2.0.0"}, | ||
"engines": {"node": ">=4.0.0", "npm": ">=2.0.0"}, | ||
"devDependencies": { | ||
"hapi": "^10.x.x", | ||
"glue": "^2.4.0", | ||
"hapi": "^13.x.x", | ||
"glue": "^3.0.0", | ||
"gulp": "^3.9.0", | ||
@@ -33,6 +33,6 @@ "gulp-istanbul": "^0.10.2", | ||
"dependencies": { | ||
"bossy": "^2.0.0", | ||
"hoek": "^2.16.3", | ||
"bossy": "^3.0.0", | ||
"hoek": "^4.0.0", | ||
"js-yaml": "^3.4.3" | ||
} | ||
} |
@@ -72,3 +72,3 @@ 'use strict'; | ||
Fs.readFileSync('./test/fixtures/basic-plugin-noop.yaml'), EPOXY_DEFAULT_CONFIG) | ||
).toEqual({plugins: {'./noop': [{}], './noop-two': [{}]}}); | ||
).toEqual({registrations: [{plugin: './noop'}, {plugin: './noop-two'}]}); | ||
done(); | ||
@@ -81,7 +81,7 @@ }); | ||
).toEqual({ | ||
plugins: { | ||
'./sample/plugin/path/basicReg': [{}], | ||
'/var/plugin/path/absReg': [{}], | ||
'./dotReg': [{}], | ||
}, | ||
registrations: [ | ||
{plugin: './sample/plugin/path/basicReg'}, | ||
{plugin: '/var/plugin/path/absReg'}, | ||
{plugin: './dotReg'}, | ||
], | ||
}); | ||
@@ -94,3 +94,3 @@ done(); | ||
Fs.readFileSync('./test/fixtures/basic-module-path.yaml'), EPOXY_DEFAULT_CONFIG) | ||
).toEqual({plugins: {npmReg: [{}]}}); | ||
).toEqual({registrations: [{plugin: 'npmReg'}]}); | ||
done(); | ||
@@ -103,5 +103,5 @@ }); | ||
).toEqual({ | ||
plugins: { | ||
'./sample/plugin/path/regOptions': [{once: true, routes: {prefix: '/api/reg'}}], | ||
}, | ||
registrations: [ | ||
{plugin: './sample/plugin/path/regOptions', options: {once: true, routes: {prefix: '/api/reg'}}}, | ||
], | ||
}); | ||
@@ -115,5 +115,5 @@ done(); | ||
).toEqual({ | ||
plugins: { | ||
'./sample/plugin/path/pluginOptions': [{options: {debugLevel: 'INFO'}}], | ||
}, | ||
registrations: [ | ||
{plugin: {register: './sample/plugin/path/pluginOptions', options: {debugLevel: 'INFO'}}}, | ||
], | ||
}); | ||
@@ -127,5 +127,5 @@ done(); | ||
).toEqual({ | ||
plugins: { | ||
'./sample/plugin/path/allOptions': [{once: true, options: {debugLevel: 'INFO'}}], | ||
}, | ||
registrations: [ | ||
{plugin: {register: './sample/plugin/path/allOptions', options: {debugLevel: 'INFO'}}, options: {once: true}}, | ||
], | ||
}); | ||
@@ -139,8 +139,6 @@ done(); | ||
).toEqual({ | ||
plugins: { | ||
multiples: [ | ||
{select: 'primary', options: {debugLevel: 'WARN'}}, | ||
{select: 'secondary', options: {debugLevel: 'INFO'}}, | ||
], | ||
}, | ||
registrations: [ | ||
{plugin: {register: 'multiples', options: {debugLevel: 'WARN'}}, options: {select: 'primary'}}, | ||
{plugin: {register: 'multiples', options: {debugLevel: 'INFO'}}, options: {select: 'secondary'}}, | ||
], | ||
}); | ||
@@ -165,25 +163,11 @@ done(); | ||
connections: [{host: '127.0.0.1', port: 8001}], | ||
plugins: { | ||
auth: [{}], | ||
utils: [{}], | ||
'/var/path/to/session': [{ | ||
options: { | ||
allowedDomains: ['localhost', 's.example.com'], | ||
}, | ||
},], | ||
'./plugins/api': [{ | ||
routes: {prefix: '/api/v1'}, | ||
options: {showdocs: false}, | ||
},], | ||
'./plugins/uxtest': [{ | ||
select: 'uxr-group-142', | ||
options: {useVersion: 20150901}, | ||
}, { | ||
select: 'uxr-group-589', | ||
options: {useVersion: 20151020}, | ||
},], | ||
cdn: [{ | ||
routes: {prefix: '/assetfarm'}, | ||
},], | ||
}, | ||
registrations: [ | ||
{plugin: 'auth'}, | ||
{plugin: 'utils'}, | ||
{plugin: {register: '/var/path/to/session', options: {allowedDomains: ['localhost', 's.example.com']}}}, | ||
{plugin: {register: './plugins/api', options: {showdocs: false}}, options: {routes: {prefix: '/api/v1'}}}, | ||
{plugin: {register: './plugins/uxtest', options: {useVersion: 20150901}}, options: {select: 'uxr-group-142'}}, | ||
{plugin: {register: './plugins/uxtest', options: {useVersion: 20151020}}, options: {select: 'uxr-group-589'}}, | ||
{plugin: 'cdn', options: {routes: {prefix: '/assetfarm'}}}, | ||
], | ||
} | ||
@@ -190,0 +174,0 @@ ); |
{ | ||
"plugins": { | ||
"./lib/foodtrucks": [ | ||
{"select": "lunch", "options": {"location": "Broadway"}} | ||
] | ||
} | ||
"registrations": [ | ||
{"plugin": { | ||
"register": "./lib/foodtrucks", | ||
"options": {"location": "Broadway"} | ||
}, "options": {"select": "lunch"}} | ||
] | ||
} |
{ | ||
"plugins": { | ||
"markets": [ | ||
{"select": "bnm", "options": {"location": "Main St.", "allyear": true}}, | ||
{"select": "oam", "options": {"location": "Market Square", "allyear": false}} | ||
] | ||
} | ||
"registrations": [ | ||
{"plugin": { | ||
"register": "markets", | ||
"options": {"location": "Main St.", "allyear": true} | ||
}, "options": {"select": "bnm"}}, | ||
{"plugin": { | ||
"register": "markets", | ||
"options": {"location": "Market Square", "allyear": false} | ||
}, "options": {"select": "oam"}} | ||
] | ||
} |
{ | ||
"plugins": { | ||
"amodule": null, | ||
"./a/relpath": {}, | ||
"./relpath2": [{}], | ||
"/an/abspath": [{}] | ||
} | ||
"registrations": [ | ||
{"plugin": "amodule"}, | ||
{"plugin": "./a/relpath"}, | ||
{"plugin": "./relpath2"}, | ||
{"plugin": "/an/abspath"} | ||
] | ||
} |
{ | ||
"plugins": { | ||
"stand": { | ||
"fruits": [ | ||
"apple", | ||
"orange" | ||
] | ||
}, | ||
"market": [ | ||
{"options": {"location": "Main St.", "allyear": true}} | ||
] | ||
} | ||
"registrations": [ | ||
{"plugin": { | ||
"register": "stand", | ||
"options": { | ||
"fruits": [ | ||
"apple", | ||
"orange" | ||
] | ||
} | ||
}}, | ||
{"plugin": { | ||
"register": "market", | ||
"options": {"location": "Main St.", "allyear": true} | ||
}} | ||
] | ||
} |
{ | ||
"plugins": { | ||
"authy": [{ | ||
"registrations": [ | ||
{"plugin": { | ||
"register": "authy" | ||
}, "options": { | ||
"once": true, | ||
@@ -8,4 +10,4 @@ "routes": { | ||
} | ||
}] | ||
} | ||
}} | ||
] | ||
} |
@@ -27,43 +27,46 @@ { | ||
], | ||
"plugins": { | ||
"auth": {}, | ||
"utils": [{}], | ||
"/var/path/to/session": { | ||
"allowedDomains": [ | ||
"localhost", | ||
"s.example.com" | ||
] | ||
}, | ||
"./plugins/api": [ | ||
{ | ||
"routes": { | ||
"prefix": "/api/v1" | ||
}, | ||
"options": { | ||
"showdocs": false | ||
} | ||
"registrations": [ | ||
{"plugin": "auth"}, | ||
{"plugin": "utils"}, | ||
{"plugin": { | ||
"register": "/var/path/to/session", | ||
"options": { | ||
"allowedDomains": [ | ||
"localhost", | ||
"s.example.com" | ||
] | ||
} | ||
], | ||
"./plugins/uxtest": [ | ||
{ | ||
"select": "uxr-group-142", | ||
"options": { | ||
"useVersion": 20150901 | ||
} | ||
}, | ||
{ | ||
"select": "uxr-group-589", | ||
"options": { | ||
"useVersion": 20151020 | ||
} | ||
}}, | ||
{"plugin": { | ||
"register": "./plugins/api", | ||
"options": { | ||
"showdocs": false | ||
} | ||
], | ||
"cdn": [ | ||
{ | ||
"routes": { | ||
"prefix": "/assetfarm" | ||
} | ||
}, "options": { | ||
"routes": { | ||
"prefix": "/api/v1" | ||
} | ||
] | ||
} | ||
}}, | ||
{"plugin": { | ||
"register": "./plugins/uxtest", | ||
"options": { | ||
"useVersion": 20150901 | ||
} | ||
}, "options": { | ||
"select": "uxr-group-142" | ||
}}, | ||
{"plugin": { | ||
"register": "./plugins/uxtest", | ||
"options": { | ||
"useVersion": 20151020 | ||
} | ||
}, "options": { | ||
"select": "uxr-group-589" | ||
}}, | ||
{"plugin": "cdn", "options": { | ||
"routes": { | ||
"prefix": "/assetfarm" | ||
} | ||
}} | ||
] | ||
} |
30144
775
+ Addedbossy@3.0.4(transitive)
+ Addedhoek@4.3.1(transitive)
+ Addedisemail@2.2.1(transitive)
+ Addeditems@2.2.1(transitive)
+ Addedjoi@10.6.0(transitive)
+ Addedtopo@2.1.1(transitive)
- Removedbossy@2.0.1(transitive)
- Removedhoek@2.16.3(transitive)
- Removedisemail@1.2.0(transitive)
- Removedjoi@6.10.1(transitive)
- Removedmoment@2.30.1(transitive)
- Removedtopo@1.1.0(transitive)
Updatedbossy@^3.0.0
Updatedhoek@^4.0.0