Esempio n. 1
0
function tryCreatePlugin(plugin) {
    if (!plugin.bind) return true;

    var meta = plugin.__meta || {};
    var imports = getImports(plugin);

    var dep = resolveDependencies(imports, plugin);
    if (dep.missing.length == 0) {
        var instance = {
            __dir: plugin.__dir,
            __path: plugin.__path,
            __name: plugin.__name
        };
        if (!(typeof meta.exports === "string"))
            meta.exports = path.parse(plugin.__name).name;
        instance.__exports = meta.exports;

        instance = plugin.bind.apply(plugin, [instance].concat(dep.params))() || instance;

        exported.push({ key: meta.exports, value: instance });
        return true;
    } else {
        plugin.__missing = dep.missing;
    }

    return false;
}
Esempio n. 2
0
        internals.forOwn(this.settings.reporters, (reporterName, streamsSpec) => {

            const streamObjs = [];
            for (let i = 0; i < streamsSpec.length; ++i) {
                const spec = streamsSpec[i];

                // Already created stream
                if (typeof spec.pipe === 'function') {
                    streamObjs.push(spec);
                    continue;
                }

                // if this is stderr or stdout
                if (process[spec]) {
                    streamObjs.push(process[spec]);
                    continue;
                }

                let Ctor = require(spec.module);
                Ctor = spec.name ? Ctor[spec.name] : Ctor;
                Hoek.assert(typeof Ctor === 'function', `Error in ${reporterName}. ${spec.module} must be a constructor function.`);

                const ctorArgs = spec.args ? spec.args.slice() : [];
                ctorArgs.unshift(null);

                Ctor = Ctor.bind.apply(Ctor, ctorArgs);
                const stream = new Ctor();
                Hoek.assert(typeof stream.pipe === 'function', `Error in ${reporterName}. ${spec.module} must create a stream that has a pipe function.`);

                streamObjs.push(stream);
            }

            if (streamObjs.length === 1) {
                streamObjs.unshift(new Utils.NoOp());
            }

            this._reporters[reporterName] = Pumpify.obj(streamObjs);
            this._reporters[reporterName].on('error', () => {

                console.error(`There was a problem in ${reporterName} and it has been destroyed.`);
            });
        });