index.js 536 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. /*
  3. Copyright 2012-2015, Yahoo Inc.
  4. Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
  5. */
  6. const path = require('path');
  7. module.exports = {
  8. create(name, cfg) {
  9. cfg = cfg || {};
  10. let Cons;
  11. try {
  12. Cons = require(path.join(__dirname, 'lib', name));
  13. } catch (e) {
  14. if (e.code !== 'MODULE_NOT_FOUND') {
  15. throw e;
  16. }
  17. Cons = require(name);
  18. }
  19. return new Cons(cfg);
  20. }
  21. };