module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;
/******/
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// identity function for calling harmory imports with the correct context
/******/ 	__webpack_require__.i = function(value) { return value; };
/******/
/******/ 	// define getter function for harmory exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		Object.defineProperty(exports, name, {
/******/ 			configurable: false,
/******/ 			enumerable: true,
/******/ 			get: getter
/******/ 		});
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "/";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 132);
/******/ })
/************************************************************************/
/******/ ({

/***/ "./src/cache.js":
/***/ function(module, exports, __webpack_require__) {

"use strict";
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Cache = undefined;

var _defineProperty = __webpack_require__(22);

var _defineProperty2 = _interopRequireDefault(_defineProperty);

var _map = __webpack_require__(69);

var _map2 = _interopRequireDefault(_map);

var _classCallCheck2 = __webpack_require__(2);

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = __webpack_require__(3);

var _createClass3 = _interopRequireDefault(_createClass2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var Cache = exports.Cache = function () {
  function Cache(init) {
    var _this = this;

    (0, _classCallCheck3.default)(this, Cache);

    hide(this, 'hide', function () {
      for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }

      return hide.apply(undefined, [_this].concat(args));
    });

    this.clear(init);
    this.write = function (k, v) {
      return _this.set(k, v).get(k);
    };
  }

  (0, _createClass3.default)(Cache, [{
    key: 'fetch',
    value: function fetch(k, defaultValue) {
      if (this.has(k)) {
        return this.get(k);
      } else {
        this.set(k, typeof defaultValue === 'function' ? defaultValue(k) : defaultValue);
        return this.get(k);
      }
    }
  }, {
    key: 'clear',
    value: function clear(init) {
      delete this._wm;
      this._wm = new _map2.default(init);
    }
  }, {
    key: 'delete',
    value: function _delete(k) {
      return this._wm.delete(k);
    }
  }, {
    key: 'get',
    value: function get(k) {
      return this._wm.get(k);
    }
  }, {
    key: 'has',
    value: function has(k) {
      return this._wm.has(k);
    }
  }, {
    key: 'set',
    value: function set(k, v) {
      this._wm.set(k, v);
      return this;
    }
  }]);
  return Cache;
}();

exports.default = Cache;


function hide(target, propName, value) {
  var configurable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;

  (0, _defineProperty2.default)(target, propName, {
    enumerable: false,
    configurable: configurable,
    value: value
  });

  return target;
}

/***/ },

/***/ "./src/collection/index.js":
/***/ function(module, exports, __webpack_require__) {

"use strict";
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PatternMapping = exports.Collection = undefined;

var _typeof2 = __webpack_require__(23);

var _typeof3 = _interopRequireDefault(_typeof2);

var _promise = __webpack_require__(6);

var _promise2 = _interopRequireDefault(_promise);

var _toConsumableArray2 = __webpack_require__(5);

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

var _defineProperty2 = __webpack_require__(29);

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

var _extends2 = __webpack_require__(0);

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = __webpack_require__(2);

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = __webpack_require__(3);

var _createClass3 = _interopRequireDefault(_createClass2);

var _values = __webpack_require__(30);

var _values2 = _interopRequireDefault(_values);

exports.create = create;

var _lodash = __webpack_require__(35);

var _lodash2 = _interopRequireDefault(_lodash);

var _path = __webpack_require__(12);

var _properties = __webpack_require__(11);

var _query = __webpack_require__(68);

var _query2 = _interopRequireDefault(_query);

var _router = __webpack_require__(77);

var _router2 = _interopRequireDefault(_router);

var _document = __webpack_require__("./src/document/index.js");

var _document2 = _interopRequireDefault(_document);

var _nodeVinyl = __webpack_require__("./src/importers/node-vinyl.js");

var _vinyl = __webpack_require__(80);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var compact = _lodash2.default.compact,
    set = _lodash2.default.set,
    groupBy = _lodash2.default.groupBy,
    snakeCase = _lodash2.default.snakeCase,
    uniq = _lodash2.default.uniq,
    chain = _lodash2.default.chain,
    mapValues = _lodash2.default.mapValues;
var values = _values2.default;

var Collection = exports.Collection = function () {
  (0, _createClass3.default)(Collection, null, [{
    key: 'mount',
    value: function mount(cwd) {
      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

      return create((0, _extends3.default)({
        cwd: cwd }, options)).imported.withDocuments;
    }

    /**
    * Create a collection which wraps a directory and creates a queryable index
    * of all of the files inside of it.  Files exist as VFile (@see https://github.com/wooorm/vfile) and are
    * wrapped by Document classes which provide the interface for metadata, transformations, and things of that nature.
    * A collection also provides a lodash wrapper interface for building extraction functions from the collections
    * files and data.
    *
    * @param {Object} options - the options hash
    * @param {String} options.type - the type of document - will determine which document model wrapper is used
    * @param {String} options.cwd - the root of the collection, defaults to process.cwd()
    * @param {String} options.cwd - the cwd, if different from the base
    * @param {Array} options.include - an array of glob patterns to include
    * @param {Array} options.exclude - an array of glob patterns to exclude
    * @param {Object} options.documentOptions - an object that will be passed to the document wrapper when created
    * @param {Object} options.importerOptions - an object that will be passed to the document importer when created
    */

  }]);

  function Collection() {
    var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    (0, _classCallCheck3.default)(this, Collection);

    (0, _properties.mixinPropertyUtils)(this);

    this.hide('cwd', options.cwd || options.root || options.base || options.basePath);
    this.hide('options', normalize(options));

    this.pathId = this.cwd.split('/').reverse().slice(0, 2).join('-');
    this.instanceId = this.pathId + '-' + Math.floor(Date.now() / 1000);

    this.hideGetter('collection', options.collection);
    this.hide('filesIndex', {});
    this.hide('documentsIndex', {});
    this.hide('project', options.project);
  }

  (0, _createClass3.default)(Collection, [{
    key: 'shouldRejectFile',
    value: function shouldRejectFile(file) {
      if (typeof this.options.rejectFile === 'function') {
        return this.options.rejectFile.call(this, file);
      }

      if (file.path.indexOf('/ios/') >= 0) {
        return true;
      }

      if (file.path.indexOf('/android/') >= 0) {
        return true;
      }

      return !file.path.startsWith(this.cwd);
    }
  }, {
    key: 'createDocuments',
    value: function createDocuments() {
      var _this = this;

      var documentOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

      var Document = this.Document;

      _lodash2.default.mapValues(this.filesIndex, function (file, path) {
        path = (0, _path.relative)(_this.cwd, path);

        _this.documentsIndex[path] = _this.documentsIndex[path] || new Document(file, (0, _extends3.default)({}, _this.documentOptions, documentOptions, {
          project: _this.project,
          collection: _this
        }));
      });

      return this;
    }
  }, {
    key: 'isDirectory',
    value: function isDirectory(file) {
      var path = file.path ? file.path : file;

      return typeof file.isDirectory === 'function' ? file.isDirectory() : !path.match(/\.\w+$/);
    }
  }, {
    key: 'add',
    value: function add(file) {
      if (file.path && !this.isDirectory(file)) {
        _lodash2.default.assign(this.filesIndex, (0, _defineProperty3.default)({}, (0, _path.relative)(this.cwd, file.path), file));
      }
    }
  }, {
    key: 'prepareImportedFilesForIndexing',
    value: function prepareImportedFilesForIndexing() {
      var _this2 = this;

      var files = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];

      var cwd = this.cwd;

      return _lodash2.default.chain(files).reject(function (f) {
        return _this2.isDirectory(f);
      }).reject(function (f) {
        return _this2.shouldRejectFile(f);
      }).compact().sortBy(function (f) {
        return f.path.length;
      }).keyBy(function (f) {
        return (0, _path.relative)(cwd, f.path);
      }).value();
    }
  }, {
    key: 'indexFiles',
    value: function indexFiles() {
      var _this3 = this;

      var files = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];

      files.forEach(function (file) {
        return _this3.loadFile(file);
      });
      return this;
    }
  }, {
    key: 'loadFile',
    value: function loadFile() {
      var file = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var cwd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.cwd;

      _lodash2.default.assign(this.filesIndex, (0, _defineProperty3.default)({}, this.resolve(cwd, file.path), this.prepareFileObject(file, cwd)));

      return this;
    }
  }, {
    key: 'prepareFileObject',
    value: function prepareFileObject(file) {
      var cwd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.cwd;

      return this.options.prepareFile ? this.options.prepareFile.call(this, file) : ensureVFile(file, cwd);
    }
  }, {
    key: 'loadFiles',
    value: function loadFiles() {
      var _this4 = this;

      var files = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];

      _lodash2.default.compact(files).filter(function (f) {
        return !_this4.isDirectory(f);
      }).forEach(function (f) {
        return _this4.loadFile(f);
      });

      return this;
    }
  }, {
    key: 'loadFilesFromImporter',
    value: function loadFilesFromImporter() {
      var _this5 = this;

      return this.importer.fileWrappers.then(files = this.prepareImportedFilesForIndexing(files)).then(function (files) {
        return _this5.indexFiles(files.map(function (file) {
          return file.toVFile ? file.toVFile() : file;
        }));
      }).then(function (collection) {
        return collection.withDocuments;
      }).catch(function (error) {
        return error;
      });
    }
  }, {
    key: 'createRouter',
    value: function createRouter(name) {
      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

      if (options.getter) {
        options.pathsGetter = options.getter;
      }
      if (options.property) {
        options.pathProperty = options.property;
      }

      (0, _router2.default)(this._routers, (0, _extends3.default)({
        routerProperty: name,
        pathsGetter: name,
        pathProperty: 'id'
      }, options, {
        host: this,
        matchesOnly: true
      }));
    }
  }, {
    key: 'createDelegators',
    value: function createDelegators(receiver) {
      var _this6 = this;

      for (var _len = arguments.length, propNames = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
        propNames[_key - 1] = arguments[_key];
      }

      propNames.forEach(function (propName) {
        receiver.hideGetter(propName, function () {
          return _this6[propName];
        });
      });
    }
  }, {
    key: 'getFileByRelativePath',
    value: function getFileByRelativePath(relativeFilePath) {
      var index = this.filesIndex[relativeFilePath].index;

      return this.files[index];
    }
  }, {
    key: 'join',
    value: function join() {
      for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
        args[_key2] = arguments[_key2];
      }

      return _path.join.apply(undefined, [this.cwd].concat(args));
    }
  }, {
    key: 'relative',
    value: function relative() {
      for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
        args[_key3] = arguments[_key3];
      }

      return _path.relative.apply(undefined, [this.cwd].concat(args));
    }
  }, {
    key: 'resolve',
    value: function resolve() {
      for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
        args[_key4] = arguments[_key4];
      }

      return _path.resolve.apply(undefined, [this.cwd].concat(args));
    }
  }, {
    key: 'select',
    value: function select() {
      return this.selectChain.apply(this, arguments).value();
    }
  }, {
    key: 'selectChain',
    value: function selectChain() {
      var _chain;

      for (var _len5 = arguments.length, paths = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
        paths[_key5] = arguments[_key5];
      }

      var set = function set(obj, path, val) {
        _lodash2.default.set(obj, path, val);
        return obj;
      };

      return (_chain = this.chain).at.apply(_chain, (0, _toConsumableArray3.default)(_lodash2.default.sortBy(paths, function (p) {
        return p.length;
      }))).map(function (value, index) {
        return [paths[index], value];
      }).reduce(function (memo, pair) {
        return set.apply(undefined, [memo].concat((0, _toConsumableArray3.default)(pair)));
      }, {});
    }
  }, {
    key: 'selectByObject',
    value: function selectByObject(pathObject) {
      var _chain2;

      var keys = keys(pathObject);
      var paths = values(pathObject);

      return (_chain2 = this.chain).at.apply(_chain2, (0, _toConsumableArray3.default)(paths)).reduce(function (memo, val, index) {
        return set(memo, keys[index], val);
      }, {}).value();
    }
  }, {
    key: 'findDocumentById',
    value: function findDocumentById(documentId) {
      return this.documents.find(function (doc) {
        return doc.id === documentId;
      });
    }
  }, {
    key: 'applyFilesRoute',
    value: function applyFilesRoute(pattern) {
      var path = route()(pattern);
      var results = this.files.map(function (f) {
        return { path: f.relative, pathData: path(f.relative) };
      }).filter(function (f) {
        return f.pathData;
      });

      return {
        results: results,
        pattern: pattern
      };
    }
  }, {
    key: 'gitInfo',
    get: function get() {
      try {
        return __webpack_require__("./src/git/index.js")(this.cwd);
      } catch (error) {
        return {};
      }
    }
  }, {
    key: 'importer',
    get: function get() {
      return new this.Importer(this.cwd, (0, _extends3.default)({}, this.importerOptions, { patterns: this.patterns
      }));
    }
  }, {
    key: 'type',
    get: function get() {
      return snakeCase(this.options.type || 'Project').replace(/s$/i, '');
    }
  }, {
    key: 'files',
    get: function get() {
      return _lodash2.default.chain(this.filesIndex).values().compact().sortBy(function (d) {
        return d.path;
      }).value();
    }
  }, {
    key: 'documents',
    get: function get() {
      return _lodash2.default.chain(this.documentsIndex).values().compact().sortBy(function (d) {
        return d.file.path;
      }).value();
    }
  }, {
    key: 'documentClass',
    get: function get() {
      return this.options.documentClass || _document2.default;
    }
  }, {
    key: 'importerOptions',
    get: function get() {
      var c = this;

      return (0, _extends3.default)({}, c.options.importerOptions, {
        patterns: _lodash2.default.uniq([].concat((0, _toConsumableArray3.default)(c.patterns || []), (0, _toConsumableArray3.default)(c.options.importerOptions.patterns || [])))
      });
    }
  }, {
    key: 'documentOptions',
    get: function get() {
      var collection = this;

      return (0, _extends3.default)({
        collectionType: collection.type
      }, collection.options.documentOptions || {}, {
        cwd: collection.cwd
      });
    }
  }, {
    key: 'Document',
    get: function get() {
      return this.documentClass;
    }
  }, {
    key: 'withDocuments',
    get: function get() {
      this.createDocuments();
      return this;
    }
  }, {
    key: 'loaderPrefix',
    get: function get() {
      return this.get('options.loaderPrefix', '');
    }
  }, {
    key: 'documentEntryPoints',
    get: function get() {
      var _this7 = this;

      return this.chain.get('documents').keyBy('id').mapValues(function (doc) {
        return ['' + _this7.loaderPrefix + doc.file.path];
      }).mapValues(function (array) {
        return compact(array);
      }).value();
    }
  }, {
    key: 'documentsMappedById',
    get: function get() {
      return this.chain.get('documents').keyBy('id').value();
    }
  }, {
    key: 'documentsMap',
    get: function get() {
      return this.documentsIndex;
    }
  }, {
    key: 'Importer',
    get: function get() {
      return this.options.importer ? __webpack_require__(72)("./" + this.options.importer + '.js') : __webpack_require__("./src/importers/node-vinyl.js").DocumentImporter;
    }
  }, {
    key: 'patterns',
    get: function get() {
      return _lodash2.default.uniq(this.includePatterns.concat(this.excludePatterns));
    }
  }, {
    key: 'includePatterns',
    get: function get() {
      return _lodash2.default.uniq(this.options.include.concat(this.typePatterns));
    }
  }, {
    key: 'typePatterns',
    get: function get() {
      switch (this.type.toUpperCase()) {
        case PACKAGE:
          return PatternMapping.Package;
          break;
        case SCRIPT:
          return PatternMapping.Script;
          break;
        case (SETTINGS_FILE, COPY_FILE):
          return PatternMapping.SettingsFile;
          break;
        case DOCUMENT:
          return PatternMapping.Document;
          break;
        case STYLESHEET:
          return PatternMapping.Stylesheet;
          break;
        case VECTOR:
          return PatternMapping.Vector;
          break;
        case PROJECT:
        default:
          return PatternMapping.Project;
      }
    }
  }, {
    key: 'router',
    get: function get() {
      return this.routers.documents;
    }
  }, {
    key: 'routers',
    get: function get() {
      if (!this._routers) {
        this.hide('_routers', {});

        this.createRouter('files', {
          pathProperty: 'relative'
        });

        this.createRouter('documents', {
          pathProperty: 'baseRelativePath',
          pathsGetter: 'documents'
        });

        this.createRouter('folders', {
          pathProperty: 'toString',
          pathsGetter: 'subFolderNames'
        });
      }

      return mapValues(this._routers, function (router) {
        return router.get.bind(router);
      });
    }
  }, {
    key: 'chain',
    get: function get() {
      return chain(this);
    }
  }, {
    key: 'relativeObjectPaths',
    get: function get() {
      var _this8 = this;

      return this.chain.get('files').sortBy(function (f) {
        return f.dirname.length;
      }).map(function (f) {
        return [_this8.relative(f.dirname).replace(/\//g, '.'), f.basename, f.relative];
      }).groupBy(function (i) {
        return i.shift();
      }).value();
    }
  }, {
    key: 'subFolderObjectPaths',
    get: function get() {
      return this.chain.get('subFolderNames').sortBy(function (v) {
        return v.length;
      }).map(function (p) {
        return p.replace(/\//g, '.');
      }).value();
    }
  }, {
    key: 'excludePatterns',
    get: function get() {
      if (this.options.includeAll || this.options.exclude === false) {
        return [];
      }

      return this.options.exclude
      // HACK tmp
      .concat(this.project ? this.project.skypagerIgnoreContents || [] : []).map(function (p) {
        return p.startsWith('!') ? p : '!' + p;
      }).concat(['!**/node_modules/**', '*.xcodeproj', '!_*']);
    }
  }, {
    key: 'imported',
    get: function get() {
      if (this.files.length === 0) {
        this.indexFiles(this.importer.readFilesSync(false));
      }

      return this;
    }
  }, {
    key: 'rootFiles',
    get: function get() {
      return this.chains.files.filter(function (f) {
        return f.dirname === project.root;
      }).value();
    }
  }, {
    key: 'groupedByChildFolder',
    get: function get() {
      var _this9 = this;

      return this.chains.files.groupBy(function (f) {
        return _this9.relative(f.dirname).split('/').shift();
      }).pickBy(function (v, k) {
        return k.length > 0;
      }).value();
    }
  }, {
    key: 'groupedByChildFolderAndExtension',
    get: function get() {
      var _this10 = this;

      return this.chains.files.groupBy(function (f) {
        return _this10.relative(f.dirname).split('/').shift();
      }).mapValues(function (v) {
        return groupBy(v, function (v) {
          return v.extname;
        });
      }).pickBy(function (v, k) {
        return k.length > 0;
      }).value();
    }
  }, {
    key: 'chains',
    get: function get() {
      return {
        documents: chain(this.documents),
        files: chain(this.files)
      };
    }
  }, {
    key: 'query',
    get: function get() {
      var collection = this;

      return {
        get files() {
          return _query2.default.bind(_query2.default, collection.files);
        },
        get documents() {
          return _query2.default.bind(_query2.default, collection.documents);
        }
      };
    }
  }, {
    key: 'depths',
    get: function get() {
      var _this11 = this;

      return this.chains.files.map(function (f) {
        return _this11.relative(f.dirname);
      }).uniq().groupBy(function (f) {
        return f.split(_path.sep).length - 1;
      }).omit('').value();
    }
  }, {
    key: 'relativeFilePaths',
    get: function get() {
      var _this12 = this;

      return this.files.map(function (file) {
        return (0, _path.relative)(_this12.cwd, file.path);
      });
    }
  }, {
    key: 'relativeSubFolderPaths',
    get: function get() {
      var _this13 = this;

      return this.files.map(function (file) {
        return (0, _path.relative)(_this13.cwd, file.dirname);
      });
    }
  }, {
    key: 'subFolderPaths',
    get: function get() {
      return uniq(this.files.map(function (f) {
        return f.dirname;
      }));
    }
  }, {
    key: 'subFolderNames',
    get: function get() {
      var _this14 = this;

      return this.subFolderPaths.map(function (f) {
        return (0, _path.relative)(_this14.cwd, f);
      }).filter(function (f) {
        return f.length > 0;
      });
    }
  }, {
    key: 'subFolderBasenames',
    get: function get() {
      var _this15 = this;

      return this.subFolderPaths.map(function (f) {
        return (0, _path.relative)(_this15.cwd, f);
      }).map(function (f) {
        return (0, _path.basename)(f);
      });
    }
  }, {
    key: 'childFolderNames',
    get: function get() {
      return uniq(this.subFolderNames.map(function (p) {
        return p.split('/').shift();
      }));
    }
  }, {
    key: 'childFolderPaths',
    get: function get() {
      var _this16 = this;

      return uniq(this.childFolderNames.map(function (p) {
        return _this16.join(p);
      }));
    }
  }, {
    key: 'ready',
    get: function get() {
      var _this17 = this;

      return this.importer.status === 'LOADED' ? _promise2.default.resolve(this) : this.loadFilesFromImporter().then(function () {
        return _this17;
      });
    }
  }], [{
    key: 'create',
    value: function create() {
      var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var ready = arguments[1];

      var collection = new Collection(options);

      return typeof ready === 'function' ? ready(collection, Collection) : collection;
    }
  }, {
    key: 'Document',
    get: function get() {
      return _document2.default;
    }
  }]);
  return Collection;
}();

exports.default = Collection;


var PACKAGE = 'PACKAGE';
var SCRIPT = 'SCRIPT';
var DOCUMENT = 'DOCUMENT';
var SETTINGS_FILE = 'SETTINGS_FILE';
var COPY_FILE = 'COPY_FILE';
var PROJECT = 'PROJECT';
var VECTOR = 'VECTOR';
var STYLESHEET = 'STYLESHEET';

var PatternMapping = exports.PatternMapping = {
  'Package': ['**/package.json'],
  'Document': ['**/*.md'],
  'Script': ['**/*.js', '**/*.jsx'],
  'Stylesheet': ['**/*.{css,less,sass,scss,styl'],
  'SettingsFile': ['**/*.yml'],
  'CopyFile': ['**/*.yml'],
  'Vector': ['**/*.svg'],
  'DataSource': ['**/*.json', '**/*.yml', '**/*.data.js'],
  'Project': ['**/*']
};

function create() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

  return Collection.create(options);
}

function normalize() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

  return (0, _extends3.default)({}, options, {
    importerOptions: options.importerOptions || {},
    documentOptions: options.documentOptions || {},
    include: [].concat((0, _toConsumableArray3.default)(options.include || []), (0, _toConsumableArray3.default)(options.patterns || [])),
    exclude: [].concat((0, _toConsumableArray3.default)(options.exclude || []), (0, _toConsumableArray3.default)(options.ignore || []))
  });
}

function ensureVFile() {
  var object = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var cwd = arguments[1];

  if (cwd) {
    object.cwd = cwd;
  }

  if (typeof object.toVFile === 'function') {
    return object.toVFile();
  } else if ((0, _vinyl.isVinyl)(object)) {
    return (0, _nodeVinyl.toVFile)(object);
  } else if ((typeof object === 'undefined' ? 'undefined' : (0, _typeof3.default)(object)) === 'object' && object.contents && object.path) {
    return (0, _nodeVinyl.toVFile)({
      contents: new Buffer(object.contents.toString()),
      path: object.path,
      cwd: object.cwd
    });
  } else {
    return (0, _nodeVinyl.toVFile)(object);
  }
}

/***/ },

/***/ "./src/document/index.js":
/***/ function(module, exports, __webpack_require__) {

"use strict";
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Document = exports.patterns = exports.DefaultPatterns = exports.PATH_SEPARATOR = undefined;

var _values = __webpack_require__(30);

var _values2 = _interopRequireDefault(_values);

var _assign = __webpack_require__(1);

var _assign2 = _interopRequireDefault(_assign);

var _keys = __webpack_require__(13);

var _keys2 = _interopRequireDefault(_keys);

var _toConsumableArray2 = __webpack_require__(5);

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

var _defineProperty2 = __webpack_require__(29);

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

var _extends3 = __webpack_require__(0);

var _extends4 = _interopRequireDefault(_extends3);

var _classCallCheck2 = __webpack_require__(2);

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = __webpack_require__(3);

var _createClass3 = _interopRequireDefault(_createClass2);

var _class, _temp;

exports.normalizeUri = normalizeUri;

var _url = __webpack_require__(78);

var _url2 = _interopRequireDefault(_url);

var _path = __webpack_require__(12);

var _properties = __webpack_require__(11);

var _string = __webpack_require__(15);

var stringUtils = _interopRequireWildcard(_string);

var _pathIsAbsolute = __webpack_require__(76);

var _pathIsAbsolute2 = _interopRequireDefault(_pathIsAbsolute);

var _collection = __webpack_require__("./src/collection/index.js");

var _collection2 = _interopRequireDefault(_collection);

var _context = __webpack_require__(20);

var _context2 = _interopRequireDefault(_context);

var _cache = __webpack_require__("./src/cache.js");

var _cache2 = _interopRequireDefault(_cache);

var _mapValues = __webpack_require__(21);

var _mapValues2 = _interopRequireDefault(_mapValues);

var _isFunction = __webpack_require__(36);

var _isFunction2 = _interopRequireDefault(_isFunction);

var _vfile = __webpack_require__(46);

var _vfile2 = _interopRequireDefault(_vfile);

var _set = __webpack_require__(66);

var _set2 = _interopRequireDefault(_set);

var _omit = __webpack_require__(17);

var _omit2 = _interopRequireDefault(_omit);

var _pick = __webpack_require__(33);

var _pick2 = _interopRequireDefault(_pick);

var _uniq = __webpack_require__(28);

var _uniq2 = _interopRequireDefault(_uniq);

var _isEmpty = __webpack_require__(32);

var _isEmpty2 = _interopRequireDefault(_isEmpty);

var _castArray = __webpack_require__(31);

var _castArray2 = _interopRequireDefault(_castArray);

var _objectHash = __webpack_require__(67);

var _objectHash2 = _interopRequireDefault(_objectHash);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var PATH_SEPARATOR = exports.PATH_SEPARATOR = _path.sep;

var DefaultPatterns = exports.DefaultPatterns = ['**/*.{js,md,yml,json,svg,html,css,scss,less,json}', '!node_modules/**'];

var patterns = exports.patterns = DefaultPatterns;

var Document = exports.Document = (_temp = _class = function () {
  (0, _createClass3.default)(Document, null, [{
    key: 'mountCollection',
    value: function mountCollection(cwd) {
      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

      if (!cwd) {
        throw new Error('Must pass a folder to Document.mountCollection');
      }

      return _collection2.default.mount(cwd, options);
    }
  }]);

  function Document(vFileOrPath) {
    var _this = this;

    var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    (0, _classCallCheck3.default)(this, Document);

    (0, _properties.mixinPropertyUtils)(this);

    if (options.project) {
      this.hide('project', options.project);
      delete options.project;
    }

    if (options.collection) {
      this.hide('collection', options.collection);
      delete options.collection;
    }

    this.hide('options', options);
    this.hide('cwd', options.cwd);

    var originalURI = normalizeUri(vFileOrPath.path ? vFileOrPath.path : vFileOrPath, options.cwd);

    this.hide('originalURI', originalURI);
    this.hide('parsedURI', _url2.default.parse(this.originalURI));
    this.hide('url', this.parsedURI.href);
    this.hide('uri', this.url);
    this.hide('path', unescape(this.parsedURI.path));
    this.hide('_appliedDocTypes', {});

    if (vFileOrPath.path) {
      this.options.file = vFileOrPath;
    }

    this.lazy('file', function () {
      return _this.toVFile((0, _extends4.default)({
        cwd: _this.cwd
      }, _this.options.file || {}));
    });

    this.hide('data', {});
    this.lazy('id', this.buildId.bind(this));

    this.lazy('fileStat', function () {
      return _this.get('file.stat', {});
    });
    this.lazy('createdAt', function () {
      return _this.result('fileStat.ctime', function () {
        return Math.floor(new Date() / 1000);
      });
    });

    this.lazy('pathInfo', function () {
      return (0, _path.parse)(_this.path);
    });

    this.lazy('vmSandbox', function () {
      return _this.project.vm.createContext((0, _extends4.default)({}, _this.project.sandbox, {
        doc: _this,
        global: {}
      }));
    });
  }

  (0, _createClass3.default)(Document, [{
    key: 'touch',
    value: function touch() {
      try {
        this.set('data.updatedAt', Math.floor(new Date() / 1000));
      } catch (e) {}

      return this;
    }
  }, {
    key: 'createContext',
    value: function createContext() {
      var sandbox = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

      return (0, _extends4.default)({}, sandbox, {
        doc: this,
        project: this.project
      });
    }
  }, {
    key: 'relativeDoc',
    value: function relativeDoc(relativeDocId) {
      return this.project.documentsMap[this.project.relative(this.pathToRelative(relativeDocId))];
    }
  }, {
    key: 'pathToRelative',
    value: function pathToRelative(relativePath) {
      return (0, _path.resolve)(this.fileDirname, relativePath);
    }
  }, {
    key: 'getTransformPresets',
    value: function getTransformPresets() {
      return this.getTransforms();
    }
  }, {
    key: 'getTransforms',
    value: function getTransforms() {
      return this.matchingDocTypes.reduce(function (memo, docType) {
        return (0, _extends4.default)({}, memo, (0, _defineProperty3.default)({}, docType.name, docType.getTransforms ? docType.getTransforms() : {}));
      }, {});
    }
  }, {
    key: 'getUtils',
    value: function getUtils() {
      return this.matchingDocTypes.reduce(function (memo, docType) {
        return (0, _extends4.default)({}, memo, docType.getUtils ? docType.getUtils() : {});
      });
    }
  }, {
    key: 'buildId',
    value: function buildId() {
      var usingPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.path;
      var cwd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.cwd;

      if ((0, _isFunction2.default)(this.options.buildId)) {
        return this.options.buildId((0, _path.relative)(cwd, usingPath));
      } else if (this.collection && (0, _isFunction2.default)(this.collection.buildId)) {
        return this.collection.buildId((0, _path.relative)(cwd, usingPath));
      } else {
        return (0, _path.relative)(cwd, usingPath).replace(/\.\w+$/g, '').replace(/\.js$/g, '');
      }
    }
  }, {
    key: 'select',
    value: function select(selector) {
      for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
        args[_key - 1] = arguments[_key];
      }

      if ((0, _isFunction2.default)(selector)) {
        var result = selector.call.apply(selector, [this, this.exporter].concat(args));
        return result && typeof result.value === 'function' ? result.value() : result;
      } else if (typeof selector === 'string') {
        return this.constructor.selectors.lookup(selector).apply(undefined, [this].concat(args));
      }
    }
  }, {
    key: 'selectChain',
    value: function selectChain(selector) {
      var _chain;

      for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
        args[_key2 - 1] = arguments[_key2];
      }

      return (_chain = this.chain).invoke.apply(_chain, ['select', selector].concat(args));
    }
  }, {
    key: 'selectorMap',
    value: function selectorMap() {
      var _this2 = this;

      var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var resolveChain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;

      var c = this.chain.plant(config).mapValues(function (selector) {
        return _this2.select.apply(_this2, (0, _toConsumableArray3.default)((0, _castArray2.default)(selector)));
      });

      return resolveChain ? c.value() : c;
    }
  }, {
    key: 'sliceId',
    value: function sliceId() {
      var removeFromBeginning = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
      var removeFromEnd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;

      if (removeFromEnd < 0) {
        removeFromEnd = removeFromEnd * -1;
      }

      return this.idParts.slice(removeFromBeginning, removeFromEnd < 0 ? removeFromEnd * -1 : this.idParts.length);
    }
  }, {
    key: 'applyDoctypes',
    value: function applyDoctypes() {
      var _this3 = this;

      if ((0, _isEmpty2.default)(this.appliedDocTypes)) {
        this.matchingDocTypes.forEach(function (docType) {
          docType.decorate(_this3);
          _this3.appliedDocTypes[docType.name] = true;
        });
      }

      return this;
    }
  }, {
    key: 'toJson',
    value: function toJson() {
      var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

      return (0, _extends4.default)({
        id: this.id,
        file: (0, _omit2.default)(this.file, 'contents', '_contents'),
        metadata: this.metadata,
        idParts: this.idParts,
        categoryFolder: this.categoryFolder,
        categoryFolderName: this.categoryFolderName,
        baseFolder: this.baseFolder,
        variations: this.variations
      }, options.pick ? (0, _pick2.default)(this, options.pick) : {}, options.pickBy ? pickBy(this, options.pickBy) : {}, options.includeContents ? { contents: this.file.contents } : { contents: null });
    }
  }, {
    key: 'toVFile',
    value: function toVFile() {
      var fileOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

      return (0, _vfile2.default)((0, _extends4.default)({
        path: this.path,
        cwd: this.cwd
      }, fileOptions));
    }
  }, {
    key: 'readFile',
    value: function readFile() {
      var cache = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;

      if (cache && this.contents && this.contents.length > 0) {
        this.file.contents = this.contents;
        return this;
      }

      this.file.contents = this.contents = this.project.readFileSync(this.file.path).toString();

      return this.touch();
    }
  }, {
    key: 'readFileAsync',
    value: function readFileAsync() {
      var _this4 = this;

      return this.project.readFileAsync(this.file.path).then(function (contents) {
        return _this4.contents = contents.toString();
      });
    }
  }, {
    key: 'slice',


    /**
     * Create a lodash chain by picking some properties from the project.
     * @param  {Array[String]} properties List of properties you want to be a part of the chain
     * @return {Chain}           The lodash chain whose initial value consists of the properties given
     */
    value: function slice() {
      var _this5 = this;

      for (var _len3 = arguments.length, properties = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
        properties[_key3] = arguments[_key3];
      }

      return properties.reduce(function (memo, prop) {
        (0, _set2.default)(memo, prop, _this5.result(prop));
        return memo;
      }, {});
    }
  }, {
    key: 'createEntityFrom',
    value: function createEntityFrom() {
      var _ready;

      var src = (_ready = this.ready).slice.apply(_ready, arguments);
      return __webpack_require__("./src/entity.js").createEntity(src);
    }
  }, {
    key: 'asyncRunner',
    value: function asyncRunner(code) {
      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

      return this.project.createSandboxedScriptRunner(code, {
        sandbox: this.vmSandbox
      });
    }
  }, {
    key: 'createStemVariations',
    value: function createStemVariations() {
      var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.variationsBase;
      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      var startCase = stringUtils.startCase,
          camelCase = stringUtils.camelCase,
          kebabCase = stringUtils.kebabCase,
          snakeCase = stringUtils.snakeCase,
          humanize = stringUtils.humanize,
          titleize = stringUtils.titleize;


      return (0, _mapValues2.default)({
        classified: startCase(camelCase(base)).replace(/\s+/g, ''),
        camel: camelCase(base),
        kebab: kebabCase(base),
        snake: snakeCase(base),
        underscored: kebabCase(base).replace(/\-/g, '_'),
        humanized: humanize(kebabCase(base).replace(/\-/g, '_')),
        titleized: titleize(humanize(kebabCase(base).replace(/\-/g, '_')))
      }, function (v) {
        var value = '' + (options.prefix || '') + v + (options.suffix || '');
        var modifier = options.pluralize ? stringUtils.pluralize : options.singularize ? stringUtils.singularize : function (v) {
          return v;
        };

        return modifier(value);
      });
    }
  }, {
    key: 'reloadFileContents',
    value: function reloadFileContents() {
      return this.contents = this.file.contents = this.readFileSync(false);
    }
  }, {
    key: 'getFileContents',
    value: function getFileContents() {
      return this.result('file.contents', '').toString();
    }
  }, {
    key: 'appliedDocTypes',
    get: function get() {
      return (0, _keys2.default)(this._appliedDocTypes);
    }
  }, {
    key: 'updatedAt',
    get: function get() {
      return Math.floor(this.get('data.updatedAt', this.createdAt) / 1000);
    }
  }, {
    key: 'decorated',
    get: function get() {
      this.applyDoctypes();
      return this;
    }
  }, {
    key: 'selectors',
    get: function get() {
      return this.constructor.selectors;
    }
  }, {
    key: 'chain',
    get: function get() {
      return this.project.chain.plant(this);
    }
  }, {
    key: 'exporter',
    get: function get() {
      return this.project.chain.plant(this.ready);
    }
  }, {
    key: 'ready',
    get: function get() {
      return this.readFile(true).decorated;
    }
  }, {
    key: 'doctypes',
    get: function get() {
      return this.docTypes;
    }
  }, {
    key: 'docTypes',
    get: function get() {
      var project = this.project;


      return project.chain.get('documentTypes.available', []).thru(function (list) {
        return list.map(function (docType) {
          return project.documentType(docType);
        });
      }).value();
    }
  }, {
    key: 'matchingDocTypes',
    get: function get() {
      var _this6 = this;

      var project = this.project;


      return project.chain.get('documentTypes.available', []).thru(function (list) {
        return list.map(function (docType) {
          return project.documentType(docType);
        });
      }).flatten().filter(function (docType) {
        return docType.testDocument(_this6);
      }).value();
    }
  }, {
    key: 'idParts',
    get: function get() {
      return this.id.split(PATH_SEPARATOR);
    }
  }, {
    key: 'baseFolder',
    get: function get() {
      return this.idParts[0];
    }
  }, {
    key: 'categoryFolderName',
    get: function get() {
      var length = this.idParts.length;
      return this.isIndex ? this.idParts[length - 3] || this.idParts[1] : this.idParts[length - 2] || this.idParts[1];
    }
  }, {
    key: 'categoryFolder',
    get: function get() {
      return (this.isIndex ? this.idParts.slice(0, this.idparts.length - 2) : this.idParts.slice(0, this.idparts.length - 1)).join(PATH_SEPARATOR);
    }
  }, {
    key: 'metadata',
    get: function get() {
      return (0, _extends4.default)({}, this.fileData, this.data, this.get('exportables.frontmatter', {}));
    }
  }, {
    key: 'idPair',
    get: function get() {
      return [this.id, this];
    }
  }, {
    key: 'isIndex',
    get: function get() {
      return !!(this.id.match(/index$/) || this.fileStem === 'index' || this.fileBaseName.startsWith('index'));
    }
  }, {
    key: 'isPackageManifest',
    get: function get() {
      return this.fileBaseName === 'package.json';
    }
  }, {
    key: 'variationsBase',
    get: function get() {
      return this.isIndex ? this.fileDirnameBasename : this.fileStem;
    }
  }, {
    key: 'fileExtname',
    get: function get() {
      return this.file.extname;
    }
  }, {
    key: 'isMarkdown',
    get: function get() {
      return this.fileExtname && this.fileExtname.match(/.md$/);
    }
  }, {
    key: 'isJavascript',
    get: function get() {
      return this.fileExtname && this.fileExtname.match(/.js$/);
    }
  }, {
    key: 'fileData',
    get: function get() {
      var _this7 = this;

      return (0, _isFunction2.default)(this.options.getFileData) ? this.options.getFileData.call(this, this.file) : this.result('file.data', function () {
        return (0, _assign2.default)(_this7.file, {
          data: {}
        });
      });
    }
  }, {
    key: 'fileMessages',
    get: function get() {
      return this.get('file.messages', {});
    }
  }, {
    key: 'variationsWithDirname',
    get: function get() {
      var base = this.fileDirnameBasename + '_' + this.fileStem;

      return (0, _extends4.default)({}, this.createStemVariations(base), {
        singularized: this.createStemVariations(base, {
          singularize: true
        }),
        pluralized: this.createStemVariations(base, {
          pluralize: true
        })
      });
    }
  }, {
    key: 'variations',
    get: function get() {
      return (0, _extends4.default)({}, this.createStemVariations(this.variationsBase), {
        singularized: this.createStemVariations(this.variationsBase, {
          singularize: true
        }),
        pluralized: this.createStemVariations(this.variationsBase, {
          pluralize: true
        })
      });
    }
  }, {
    key: 'nameVariations',
    get: function get() {
      var variations = this.variations;

      return (0, _uniq2.default)((0, _values2.default)((0, _omit2.default)(variations, 'pluralized', 'singularized')).concat((0, _values2.default)(variations.pluralized), (0, _values2.default)(variations.singularized)));
    }
  }, {
    key: 'indexVariations',
    get: function get() {
      return this.createStemVariations(this.variationsBase, {
        suffix: '/index' + this.fileExtname
      });
    }
  }, {
    key: 'filenameVariations',
    get: function get() {
      return (0, _extends4.default)({}, this.createStemVariations(this.variationsBase, {
        suffix: this.fileExtname
      }));
    }
  }, {
    key: 'fileStem',
    get: function get() {
      return this.file.stem;
    }
  }, {
    key: 'fileBaseName',
    get: function get() {
      return this.file.basename;
    }
  }, {
    key: 'fileDirname',
    get: function get() {
      return this.file.dirname;
    }
  }, {
    key: 'relativeDirname',
    get: function get() {
      return (0, _path.relative)(this.cwd, this.fileDirname);
    }
  }, {
    key: 'fileDirnameBasename',
    get: function get() {
      return (0, _path.basename)(this.fileDirname);
    }
  }, {
    key: 'baseRelativePath',
    get: function get() {
      return (0, _path.relative)(this.cwd, this.path);
    }
  }, {
    key: 'contentLength',
    get: function get() {
      var statSize = this.result('stat.size');

      if (typeof statSize === 'undefined') {
        return 0;
      } else {
        return (this.get('contents', this.get('file.contents', '')) || '').length;
      }
    }
  }, {
    key: 'stat',
    get: function get() {
      return this.get('file.stat', {});
    }
  }, {
    key: 'cacheKey',
    get: function get() {
      return [this.baseRelativePath, this.updatedAt.toString(), this.contentLength.toString()].join(':');
    }
  }, {
    key: 'isRemote',
    get: function get() {
      return this.uri.protocol.indexOf('http') !== -1;
    }
  }]);
  return Document;
}(), _class.patterns = DefaultPatterns, _class.cache = new _cache2.default(), _class.selectors = new _context2.default('documentSelectors', {
  context: __webpack_require__(73),
  wrapper: function wrapper(fn, id) {
    return function (doc) {
      for (var _len4 = arguments.length, args = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
        args[_key4 - 1] = arguments[_key4];
      }

      return Document.cache.fetch('selectors:' + id + ':' + (0, _objectHash2.default)({ args: args }) + ':' + doc.cacheKey, function () {
        return fn.call.apply(fn, [doc, doc.exporter].concat(args)).value();
      });
    };
  }
}), _temp);
exports.default = Document;
function normalizeUri(input) {
  var cwd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : process.cwd();

  if (typeof input !== 'string') {
    throw 'Must pass the URI as a string';
  }

  var parsed = _url2.default.parse(input);

  var isFilePath = parsed.protocol === null || parsed.protocol.indexOf('file') !== -1;
  var isRemoteUrl = !isFilePath && parsed.protocol.indexOf('http') !== -1;
  var isAbsoluteFilePath = isFilePath && (0, _pathIsAbsolute2.default)(parsed.path);

  if (isRemoteUrl) {
    return _url2.default.format(parsed);
  }

  if (isFilePath && isAbsoluteFilePath) {
    return _url2.default.format({
      protocol: 'file:',
      slashes: true,
      pathname: parsed.path
    });
  } else {
    return _url2.default.format({
      protocol: 'file:',
      slashes: true,
      pathname: (0, _path.resolve)(cwd, parsed.path)
    });
  }

  return input;
}

/***/ },

/***/ "./src/entity.js":
/***/ function(module, exports, __webpack_require__) {

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_babel_runtime_core_js_object_define_property__ = __webpack_require__(22);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_babel_runtime_core_js_object_define_property___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_babel_runtime_core_js_object_define_property__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_babel_runtime_core_js_object_keys__ = __webpack_require__(13);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_babel_runtime_core_js_object_keys___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_babel_runtime_core_js_object_keys__);
'use strict';



Object.defineProperty(exports, "__esModule", {
  value: true
});

var _entity = __webpack_require__(34);

__WEBPACK_IMPORTED_MODULE_1_babel_runtime_core_js_object_keys___default()(_entity).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;

  __WEBPACK_IMPORTED_MODULE_0_babel_runtime_core_js_object_define_property___default()(exports, key, {
    enumerable: true,
    get: function get() {
      return _entity[key];
    }
  });
});

/***/ },

/***/ "./src/git/index.js":
/***/ function(module, exports, __webpack_require__) {

"use strict";
'use strict';

var fs = __webpack_require__(65);
var path = __webpack_require__(12);
var zlib = __webpack_require__(82);

var GIT_DIR = '.git';

function findRepo(startingPath) {
  var gitPath = void 0,
      lastPath = void 0;
  var currentPath = startingPath;

  if (!currentPath) {
    currentPath = process.cwd();
  }

  do {
    gitPath = path.join(currentPath, GIT_DIR);

    if (fs.existsSync(gitPath)) {
      return gitPath;
    }

    lastPath = currentPath;
    currentPath = path.resolve(currentPath, '..');
  } while (lastPath !== currentPath);

  return null;
}

function findPackedTag(gitPath, sha) {
  var packedRefsFilePath = path.join(gitPath, 'packed-refs');
  if (fs.existsSync(packedRefsFilePath)) {
    var packedRefsFile = fs.readFileSync(packedRefsFilePath, { encoding: 'utf8' });
    var tagLine = packedRefsFile.split('\n').filter(function (line) {
      return line.indexOf('refs/tags') > -1 && line.indexOf(sha) > -1;
    })[0];

    if (tagLine) {
      return tagLine.split('tags/')[1];
    }
  }
}

function commitForTag(gitPath, tag) {
  var tagPath = path.join(gitPath, 'refs', 'tags', tag);
  var taggedObject = fs.readFileSync(tagPath, { encoding: 'utf8' }).trim();
  var objectPath = path.join(gitPath, 'objects', taggedObject.slice(0, 2), taggedObject.slice(2));

  if (!zlib.inflateSync || !fs.existsSync(objectPath)) {
    // we cannot support annotated tags on node v0.10 because
    // zlib does not allow sync access
    return taggedObject;
  }

  var objectContents = zlib.inflateSync(fs.readFileSync(objectPath)).toString();

  // 'tag 172\u0000object c1ee41c325d54f410b133e0018c7a6b1316f6cda\ntype commit\ntag awesome-tag\ntagger Robert Jackson <robert.w.jackson@me.com> 1429100021 -0400\n\nI am making an annotated tag.\n'
  if (objectContents.slice(0, 3) === 'tag') {
    var sections = objectContents.split(/\0|\n/);
    var sha = sections[1].slice(7);

    return sha;
  } else {
    // this will return the tag for lightweight tags
    return taggedObject;
  }
}

function findTag(gitPath, sha) {
  var tag = findPackedTag(gitPath, sha);
  if (tag) {
    return tag;
  }

  var tagsPath = path.join(gitPath, 'refs', 'tags');
  if (!fs.existsSync(tagsPath)) {
    return false;
  }

  var tags = fs.readdirSync(tagsPath);

  for (var i = 0, l = tags.length; i < l; i++) {
    tag = tags[i];
    var commitAtTag = commitForTag(gitPath, tags[i]);

    if (commitAtTag === sha) {
      return tag;
    }
  }
}

module.exports = function (gitPath) {
  gitPath = findRepo(gitPath);

  var result = {
    sha: null,
    abbreviatedSha: null,
    branch: null,
    tag: null,
    root: path.resolve(gitPath, '..')
  };

  try {
    var headFilePath = path.join(gitPath, 'HEAD');

    if (fs.existsSync(headFilePath)) {
      var headFile = fs.readFileSync(headFilePath, { encoding: 'utf8' });
      var branchName = headFile.split('/').slice(2).join('/').trim();
      if (!branchName) {
        branchName = headFile.split('/').slice(-1)[0].trim();
      }
      var refPath = headFile.split(' ')[1];

      // Find branch and SHA
      if (refPath) {
        var branchPath = path.join(gitPath, refPath.trim());

        result.branch = branchName;
        result.sha = fs.readFileSync(branchPath, { encoding: 'utf8' }).trim();
      } else {
        result.sha = branchName;
      }

      result.abbreviatedSha = result.sha.slice(0, 10);

      // Find tag
      var tag = findTag(gitPath, result.sha);
      if (tag) {
        result.tag = tag;
      }
    }
  } catch (e) {
    if (!module.exports._suppressErrors) {
      throw e; // helps with testing and scenarios where we do not expect errors
    } else {
        // eat the error
      }
  }

  return result;
};

module.exports._suppressErrors = true;
module.exports._findRepo = findRepo;

/***/ },

/***/ "./src/importers/node-vinyl.js":
/***/ function(module, exports, __webpack_require__) {

"use strict";
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DocumentImporter = exports.toVFile = exports.DefaultOptions = undefined;

var _toConsumableArray2 = __webpack_require__(5);

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

var _extends2 = __webpack_require__(0);

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = __webpack_require__(2);

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = __webpack_require__(3);

var _createClass3 = _interopRequireDefault(_createClass2);

var _defineProperty = __webpack_require__(22);

var _defineProperty2 = _interopRequireDefault(_defineProperty);

var _class, _temp;

var _isArray = __webpack_require__(49);

var _isArray2 = _interopRequireDefault(_isArray);

var _uniq = __webpack_require__(28);

var _uniq2 = _interopRequireDefault(_uniq);

var _vinylRead = __webpack_require__(81);

var _vinylRead2 = _interopRequireDefault(_vinylRead);

var _properties = __webpack_require__(11);

var _vfile = __webpack_require__(46);

var _vfile2 = _interopRequireDefault(_vfile);

var _document = __webpack_require__("./src/document/index.js");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var defineProperty = _defineProperty2.default;
var DefaultOptions = exports.DefaultOptions = {
  patterns: _document.DefaultPatterns
};

var toVFile = exports.toVFile = function toVFile(vinyl, cwd) {
  var options = {
    path: vinyl.path,
    contents: vinyl.contents,
    cwd: cwd || vinyl.cwd
  };

  return new _vfile2.default(options);
};

var DocumentImporter = exports.DocumentImporter = (_temp = _class = function () {
  (0, _createClass3.default)(DocumentImporter, null, [{
    key: 'create',
    value: function create(cwd) {
      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

      if (typeof options === 'string') {
        options = {
          patterns: [options],
          cwd: cwd
        };
      }

      if ((0, _isArray2.default)(options)) {
        options = {
          cwd: cwd,
          patterns: options
        };
      }

      var importer = new DocumentImporter(cwd, (0, _extends3.default)({
        cwd: cwd
      }, options));

      return importer;
    }
  }]);

  function DocumentImporter(cwd) {
    var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    (0, _classCallCheck3.default)(this, DocumentImporter);

    (0, _properties.mixinPropertyUtils)(this);

    if (typeof cwd !== 'string') {
      throw 'Document Importers must be created with a cwd path';
    }

    this.cwd = cwd;

    this.hide('options', (0, _extends3.default)({}, DefaultOptions, options));

    delete this.options.cwd;

    this.patterns = [].concat((0, _toConsumableArray3.default)(this.options.patterns || DefaultOptions.patterns || []), ['!**/*.lock']);

    if (this.options.collection) {
      var _patterns;

      (_patterns = this.patterns).push.apply(_patterns, (0, _toConsumableArray3.default)(this.options.collection.patterns || []));
    }

    this.patterns = (0, _uniq2.default)(this.patterns);

    var status = 'CREATED';

    defineProperty(this, 'status', {
      configurable: false,
      get: function get() {
        return status;
      },
      set: function set(newValue) {
        return status = newValue;
      }
    });
  }

  (0, _createClass3.default)(DocumentImporter, [{
    key: 'readFilesSync',
    value: function readFilesSync(includeContents) {
      return _vinylRead2.default.sync(this.patterns, (0, _extends3.default)({
        base: this.cwd,
        cwd: this.cwd,
        read: includeContents !== false && this.options.includeContents === true
      }, this.options));
    }
  }, {
    key: 'readFiles',
    value: function readFiles() {
      var includeContents = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;

      return (0, _vinylRead2.default)(this.patterns, (0, _extends3.default)({
        base: this.cwd,
        cwd: this.cwd,
        read: includeContents === true
      }, this.options));
    }
  }, {
    key: 'fileWrappersSync',
    get: function get() {
      return _vinylRead2.default.sync(this.patterns, (0, _extends3.default)({
        base: this.cwd,
        cwd: this.cwd,
        read: this.options.includeContents === true
      }, this.options));
    }
  }, {
    key: 'fileWrappers',
    get: function get() {
      return (0, _vinylRead2.default)(this.patterns, (0, _extends3.default)({
        base: this.cwd,
        cwd: this.cwd,
        read: this.options.includeContents === true
      }, this.options));
    }
  }]);
  return DocumentImporter;
}(), _class.patterns = _document.DefaultPatterns, _temp);
exports.default = DocumentImporter;

/***/ },

/***/ "./src/selectors/document/active-entity.js":
/***/ function(module, exports, __webpack_require__) {

"use strict";
'use strict';

var _properties = __webpack_require__(11);

module.exports = function (chain) {
  var api = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  return chain.invoke('select', 'entity', api).thru(function (result) {
    return (0, _properties.mixinPropertyUtils)(result, true, true);
  });
};

/***/ },

/***/ "./src/selectors/document/code-blocks.js":
/***/ function(module, exports, __webpack_require__) {

"use strict";
'use strict';

var _require = __webpack_require__(15),
    camelCase = _require.camelCase,
    kebabCase = _require.kebabCase;

module.exports = function (chain) {
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  var doc = this;

  var c = chain.invoke('selectCodeBlocks', 'javascript', ', code[lang="jsx"], code[lang="es6"], code[lang="react"]').map(function (v) {
    var docPath = v.getHeadingPath();
    var pathParts = docPath.split('/');

    var codeBlock = {
      docPath: docPath,
      pathParts: pathParts,
      accessor: camelCase(kebabCase(docPath.replace(/\//g, '_'))),
      heading: pathParts[pathParts.length - 1],
      section: pathParts.length > 2 ? pathParts[pathParts.length - 2] : pathParts[pathParts.length - 1],
      index: v.index,
      value: v.value,
      docId: doc.id,
      lang: v.lang
    };

    return codeBlock;
  });

  if (options.keyBy) {
    return c.keyBy(options.keyBy);
  } else if (options.groupBy) {
    return c.groupBy(options.groupBy);
  } else {
    return c.groupBy('docPath');
  }
};

/***/ },

/***/ "./src/selectors/document/entity.js":
/***/ function(module, exports, __webpack_require__) {

"use strict";
'use strict';

var _assign = __webpack_require__(1);

var _assign2 = _interopRequireDefault(_assign);

var _mapValues = __webpack_require__(21);

var _mapValues2 = _interopRequireDefault(_mapValues);

var _pickBy = __webpack_require__(75);

var _pickBy2 = _interopRequireDefault(_pickBy);

var _isFunction = __webpack_require__(36);

var _isFunction2 = _interopRequireDefault(_isFunction);

var _bindAll = __webpack_require__(48);

var _bindAll2 = _interopRequireDefault(_bindAll);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

module.exports = function (chain) {
  var api = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  var doc = this;
  var entity = selectEntity(doc);

  var mixin = (0, _mapValues2.default)((0, _pickBy2.default)(api, _isFunction2.default), function (meth, id) {
    return meth.bind(doc);
  });

  return (0, _bindAll2.default)((0, _assign2.default)(entity, mixin));
};

function selectEntity(doc) {
  try {
    if (typeof doc.createExportable === 'function') {
      return doc.exporter.invoke('createExportable').defaults({ id: doc.id, baseRelativePath: doc.baseRelativePath, relativeDirname: doc.relativeDirname });
    } else if (typeof doc.toProjectConfiguration === 'function') {
      return doc.exporter.invoke('toProjectConfiguration').defaults({ id: doc.id, baseRelativePath: doc.baseRelativePath, relativeDirname: doc.relativeDirname });
    } else if (typeof doc.readDataSync === 'function') {
      return doc.exporter.invoke('readDataSync').defaults({ id: doc.id, baseRelativePath: doc.baseRelativePath, relativeDirname: doc.relativeDirname });
    } else {
      return doc.exporter.pick('id', 'relativeDirname', 'baseRelativePath', 'idParts', 'cacheKey', 'file', 'data').defaults({ id: doc.id, baseRelativePath: doc.baseRelativePath, relativeDirname: doc.relativeDirname });
    }
  } catch (error) {
    return doc.chain.pick('id', 'baseRelativePath', 'relativeDirname', 'idParts', 'file', 'data').assign({ error: error });
  }
}

/***/ },

/***/ "./src/selectors/document/links.js":
/***/ function(module, exports) {

"use strict";
'use strict';

module.exports = function (chain) {
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  return chain.invoke('createHeadingsMap', 'accessorMethod').mapValues(function (heading) {
    return heading.selectChildren('link');
  });
};

/***/ },

/***/ "./src/selectors/document/tree.js":
/***/ function(module, exports) {

"use strict";
'use strict';

module.exports = function (chain) {
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  return chain.invoke('createTree');
};

/***/ },

/***/ 0:
/***/ function(module, exports) {

module.exports = require("babel-runtime/helpers/extends");

/***/ },

/***/ 1:
/***/ function(module, exports) {

module.exports = require("babel-runtime/core-js/object/assign");

/***/ },

/***/ 11:
/***/ function(module, exports) {

module.exports = require("skypager-util/lib/properties");

/***/ },

/***/ 12:
/***/ function(module, exports) {

module.exports = require("path");

/***/ },

/***/ 13:
/***/ function(module, exports) {

module.exports = require("babel-runtime/core-js/object/keys");

/***/ },

/***/ 132:
/***/ function(module, exports, __webpack_require__) {

module.exports = __webpack_require__("./src/document/index.js");


/***/ },

/***/ 15:
/***/ function(module, exports) {

module.exports = require("skypager-util/lib/string");

/***/ },

/***/ 17:
/***/ function(module, exports) {

module.exports = require("lodash/omit");

/***/ },

/***/ 2:
/***/ function(module, exports) {

module.exports = require("babel-runtime/helpers/classCallCheck");

/***/ },

/***/ 20:
/***/ function(module, exports) {

module.exports = require("skypager-registry/lib/context");

/***/ },

/***/ 21:
/***/ function(module, exports) {

module.exports = require("lodash/mapValues");

/***/ },

/***/ 22:
/***/ function(module, exports) {

module.exports = require("babel-runtime/core-js/object/define-property");

/***/ },

/***/ 23:
/***/ function(module, exports) {

module.exports = require("babel-runtime/helpers/typeof");

/***/ },

/***/ 28:
/***/ function(module, exports) {

module.exports = require("lodash/uniq");

/***/ },

/***/ 29:
/***/ function(module, exports) {

module.exports = require("babel-runtime/helpers/defineProperty");

/***/ },

/***/ 3:
/***/ function(module, exports) {

module.exports = require("babel-runtime/helpers/createClass");

/***/ },

/***/ 30:
/***/ function(module, exports) {

module.exports = require("babel-runtime/core-js/object/values");

/***/ },

/***/ 31:
/***/ function(module, exports) {

module.exports = require("lodash/castArray");

/***/ },

/***/ 32:
/***/ function(module, exports) {

module.exports = require("lodash/isEmpty");

/***/ },

/***/ 33:
/***/ function(module, exports) {

module.exports = require("lodash/pick");

/***/ },

/***/ 34:
/***/ function(module, exports) {

module.exports = require("skypager-util/lib/entity");

/***/ },

/***/ 35:
/***/ function(module, exports) {

module.exports = require("lodash");

/***/ },

/***/ 36:
/***/ function(module, exports) {

module.exports = require("lodash/isFunction");

/***/ },

/***/ 46:
/***/ function(module, exports) {

module.exports = require("vfile");

/***/ },

/***/ 48:
/***/ function(module, exports) {

module.exports = require("lodash/bindAll");

/***/ },

/***/ 49:
/***/ function(module, exports) {

module.exports = require("lodash/isArray");

/***/ },

/***/ 5:
/***/ function(module, exports) {

module.exports = require("babel-runtime/helpers/toConsumableArray");

/***/ },

/***/ 6:
/***/ function(module, exports) {

module.exports = require("babel-runtime/core-js/promise");

/***/ },

/***/ 65:
/***/ function(module, exports) {

module.exports = require("fs");

/***/ },

/***/ 66:
/***/ function(module, exports) {

module.exports = require("lodash/set");

/***/ },

/***/ 67:
/***/ function(module, exports) {

module.exports = require("object-hash");

/***/ },

/***/ 68:
/***/ function(module, exports) {

module.exports = require("skypager-util/lib/query");

/***/ },

/***/ 69:
/***/ function(module, exports) {

module.exports = require("babel-runtime/core-js/map");

/***/ },

/***/ 72:
/***/ function(module, exports, __webpack_require__) {

var map = {
	"./node-vinyl.js": "./src/importers/node-vinyl.js"
};
function webpackContext(req) {
	return __webpack_require__(webpackContextResolve(req));
};
function webpackContextResolve(req) {
	var id = map[req];
	if(!(id + 1)) // check for number
		throw new Error("Cannot find module '" + req + "'.");
	return id;
};
webpackContext.keys = function webpackContextKeys() {
	return Object.keys(map);
};
webpackContext.resolve = webpackContextResolve;
module.exports = webpackContext;
webpackContext.id = 72;


/***/ },

/***/ 73:
/***/ function(module, exports, __webpack_require__) {

var map = {
	"./active-entity.js": "./src/selectors/document/active-entity.js",
	"./code-blocks.js": "./src/selectors/document/code-blocks.js",
	"./entity.js": "./src/selectors/document/entity.js",
	"./links.js": "./src/selectors/document/links.js",
	"./tree.js": "./src/selectors/document/tree.js"
};
function webpackContext(req) {
	return __webpack_require__(webpackContextResolve(req));
};
function webpackContextResolve(req) {
	var id = map[req];
	if(!(id + 1)) // check for number
		throw new Error("Cannot find module '" + req + "'.");
	return id;
};
webpackContext.keys = function webpackContextKeys() {
	return Object.keys(map);
};
webpackContext.resolve = webpackContextResolve;
module.exports = webpackContext;
webpackContext.id = 73;


/***/ },

/***/ 75:
/***/ function(module, exports) {

module.exports = require("lodash/pickBy");

/***/ },

/***/ 76:
/***/ function(module, exports) {

module.exports = require("path-is-absolute");

/***/ },

/***/ 77:
/***/ function(module, exports) {

module.exports = require("skypager-util/lib/router");

/***/ },

/***/ 78:
/***/ function(module, exports) {

module.exports = require("url");

/***/ },

/***/ 80:
/***/ function(module, exports) {

module.exports = require("vinyl");

/***/ },

/***/ 81:
/***/ function(module, exports) {

module.exports = require("vinyl-read");

/***/ },

/***/ 82:
/***/ function(module, exports) {

module.exports = require("zlib");

/***/ }

/******/ });
//# sourceMappingURL=document.js.map