mirror of https://github.com/Seich/Beau.git
Added beau-std as an auto-loaded plugin. (#18)
This means that beau-std will automatically be loaded if available in the same space as Beau. beau-std is a set of commonly used plugins, these map directly to nodejs features that are commonly needed within Beau.
This commit is contained in:
parent
59f85fac8c
commit
4bf7a60e9c
|
|
@ -0,0 +1,7 @@
|
|||
class BeauStd {
|
||||
constructor(registry, settings) {
|
||||
registry.defineDynamicValue('createReadStream', () => {});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BeauStd;
|
||||
|
|
@ -1,3 +1,15 @@
|
|||
module.exports = function(name) {
|
||||
return require(name);
|
||||
function requireg(name) {
|
||||
return require(name);
|
||||
}
|
||||
|
||||
requireg.std_resolving = false;
|
||||
|
||||
requireg.resolve = function(name) {
|
||||
if (requireg.std_resolving) {
|
||||
return '';
|
||||
} else {
|
||||
throw new Error(`Failed to resolve.`);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = requireg;
|
||||
|
|
|
|||
|
|
@ -3,14 +3,16 @@ const Config = require('../config');
|
|||
const Plugins = require('../plugins');
|
||||
const Request = require('../request');
|
||||
const RequestCache = require('../requestCache');
|
||||
const requireg = require('requireg');
|
||||
|
||||
describe(`Beau's plugin system`, () => {
|
||||
let config;
|
||||
let request;
|
||||
let plugins;
|
||||
let doc;
|
||||
|
||||
beforeEach(() => {
|
||||
const doc = yaml.safeLoad(`
|
||||
doc = yaml.safeLoad(`
|
||||
version: 1
|
||||
endpoint: 'http://example.com'
|
||||
|
||||
|
|
@ -32,6 +34,13 @@ describe(`Beau's plugin system`, () => {
|
|||
expect(plugins.registry.dynamicValues.length).toBe(1);
|
||||
});
|
||||
|
||||
it(`should load autoload plugins`, () => {
|
||||
requireg.std_resolving = true;
|
||||
config = new Config(doc);
|
||||
expect(config.PLUGINS.registry.dynamicValues.length).toBe(2);
|
||||
requireg.std_resolving = false;
|
||||
});
|
||||
|
||||
it(`should throw if given an invalid configuration`, () => {
|
||||
expect(() => new Plugins([{ test1: true, test2: true }])).toThrow();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const { toKebabCase, dynamicValueRegex, replaceInObject } = require('./shared');
|
|||
const isPlainObject = require('is-plain-object');
|
||||
|
||||
class Plugins {
|
||||
constructor(plugins = []) {
|
||||
constructor(plugins = [], autoload = ['std']) {
|
||||
this.registry = {
|
||||
preRequestModifiers: [],
|
||||
postRequestModifiers: [],
|
||||
|
|
@ -15,6 +15,12 @@ class Plugins {
|
|||
this.context = {};
|
||||
|
||||
plugins.forEach(plugin => this.loadPlugin(plugin));
|
||||
autoload.forEach(plugin => {
|
||||
try {
|
||||
requireg.resolve(plugin);
|
||||
this.loadPlugin(plugin);
|
||||
} catch (e) {}
|
||||
});
|
||||
}
|
||||
|
||||
loadPlugin(plugin) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue