Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

const _require = require("./Chains"),
      ChainedMap = _require.ChainedMap,
      ChainedSet = _require.ChainedSet;

const Use = require("./Use");

module.exports = class extends ChainedMap {
  constructor(parent) {
    super(parent); // @chainup

    this.plugin = name => this.parent.plugin(name);

    this.rule = name => this.parent.rule(name);

    this.module = this.parent.module;
    this.output = this.parent.output;
    this.uses = new ChainedMap(this);
    this.included = new ChainedSet(this);
    this.excluded = new ChainedSet(this);
    this.extend(['parser', 'test', 'enforce']);
  }

  prepend(name) {
    // const uses = this.uses
    // .entries()
    const uses = new ChainedMap(this);
    uses.set(name, new Use(this)); // const cleaner = require('fliplog')
    //   .cleaner(true)
    //   .keys([/parent/])
    //   .data(uses)
    //   .clean()
    //   .get('cleaned')
    //
    // require('fliplog').quick(cleaner)
    // process.exit()

    for (var _ref of this.uses) {
      var _ref2 = _slicedToArray(_ref, 2);

      var key = _ref2[0];
      var val = _ref2[1];
      uses.set(key, val);
    }

    this.uses = uses;
    return this.uses.get(name);
  }

  include(args) {
    if (Array.isArray(args)) {
      args.forEach(arg => this.included.add(arg));
    } else {
      this.included.add(args);
    }

    return this;
  }

  exclude(args) {
    if (Array.isArray(args)) {
      args.forEach(arg => this.excluded.add(arg));
    } else {
      this.excluded.add(args);
    }

    return this;
  }

  use(name) {
    if (!this.uses.has(name)) {
      this.uses.set(name, new Use(this));
    }

    return this.uses.get(name);
  }

  pre() {
    return this.enforce('pre');
  }

  post() {
    return this.enforce('post');
  }

  toConfig() {
    return this.clean(Object.assign(this.entries() || {}, {
      include: this.included.values(),
      exclude: this.excluded.values(),
      use: this.uses.values().map(use => use.toConfig())
    }));
  }

  merge(obj) {
    Object.keys(obj).forEach(key => {
      const value = obj[key];

      switch (key) {
        case 'include':
        case 'exclude':
          {
            return this[key + 'd'].merge(value);
          }

        case 'use':
          {
            return Object.keys(value).forEach(name => this.use(name).merge(value[name]));
          }

        case 'test':
          {
            return this.test(value instanceof RegExp ? value : new RegExp(value));
          }

        default:
          {
            this.set(key, value);
          }
      }
    });
    return this;
  }

};