skypager-project
Version:
skypager project framework
1,835 lines (1,456 loc) • 303 kB
JavaScript
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 = 147);
/******/ })
/************************************************************************/
/******/ ({
/***/ "../../node_modules/find-up/index.js":
/***/ function(module, exports, __webpack_require__) {
"use strict";
'use strict';
var path = __webpack_require__(12);
var pathExists = __webpack_require__("../../node_modules/path-exists/index.js");
var Promise = __webpack_require__(95);
function splitPath(x) {
return path.resolve(x || '').split(path.sep);
}
function join(parts, filename) {
return path.resolve(parts.join(path.sep) + path.sep, filename);
}
module.exports = function (filename, opts) {
opts = opts || {};
var parts = splitPath(opts.cwd);
return new Promise(function (resolve) {
(function find() {
var fp = join(parts, filename);
pathExists(fp).then(function (exists) {
if (exists) {
resolve(fp);
} else if (parts.pop()) {
find();
} else {
resolve(null);
}
});
})();
});
};
module.exports.sync = function (filename, opts) {
opts = opts || {};
var parts = splitPath(opts.cwd);
var len = parts.length;
while (len--) {
var fp = join(parts, filename);
if (pathExists.sync(fp)) {
return fp;
}
parts.pop();
}
return null;
};
/***/ },
/***/ "../../node_modules/path-exists/index.js":
/***/ function(module, exports, __webpack_require__) {
"use strict";
'use strict';
var fs = __webpack_require__(64);
var Promise = __webpack_require__(95);
module.exports = function (fp) {
var fn = typeof fs.access === 'function' ? fs.access : fs.stat;
return new Promise(function (resolve) {
fn(fp, function (err) {
resolve(!err);
});
});
};
module.exports.sync = function (fp) {
var fn = typeof fs.accessSync === 'function' ? fs.accessSync : fs.statSync;
try {
fn(fp);
return true;
} catch (err) {
return false;
}
};
/***/ },
/***/ "../skypager/node_modules/webpack/buildin/module.js":
/***/ function(module, exports) {
module.exports = function(module) {
if(!module.webpackPolyfill) {
module.deprecate = function() {};
module.paths = [];
// module.parent = undefined by default
if(!module.children) module.children = [];
Object.defineProperty(module, "loaded", {
enumerable: true,
configurable: false,
get: function() { return module.l; }
});
Object.defineProperty(module, "id", {
enumerable: true,
configurable: false,
get: function() { return module.i; }
});
module.webpackPolyfill = 1;
}
return module;
}
/***/ },
/***/ "./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__(67);
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__(66);
var _query2 = _interopRequireDefault(_query);
var _router = __webpack_require__(76);
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__(79);
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__(70)("./" + 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/config/Expression.js":
/***/ function(module, exports, __webpack_require__) {
"use strict";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
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 Expression = function () {
function Expression(expression) {
(0, _classCallCheck3.default)(this, Expression);
this.expression = expression;
}
(0, _createClass3.default)(Expression, [{
key: "toString",
value: function toString() {
return this.expression.toString();
}
}, {
key: "value",
value: function value() {
return this.expression();
}
}]);
return Expression;
}();
exports.default = Expression;
/***/ },
/***/ "./src/config/features/collection.js":
/***/ function(module, exports, __webpack_require__) {
"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _toConsumableArray2 = __webpack_require__(5);
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
exports.default = collection;
var _isEmpty = __webpack_require__(32);
var _isEmpty2 = _interopRequireDefault(_isEmpty);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function collection(existing) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
if (!(0, _isEmpty2.default)(args)) {
return [].concat((0, _toConsumableArray3.default)(existing || []), [args]);
} else {
return existing;
}
}
/***/ },
/***/ "./src/config/features/feature.js":
/***/ function(module, exports, __webpack_require__) {
"use strict";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _defineProperty2 = __webpack_require__(29);
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends3 = __webpack_require__(0);
var _extends4 = _interopRequireDefault(_extends3);
exports.default = feature;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function feature(existing, id) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!id) {
return existing;
}
var settings = (0, _extends4.default)({}, existing && existing[id] || {}, options, {
id: id
});
return (0, _extends4.default)({}, existing || {}, (0, _defineProperty3.default)({}, id, settings));
}
/***/ },
/***/ "./src/config/features/scope.js":
/***/ function(module, exports, __webpack_require__) {
"use strict";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _toConsumableArray2 = __webpack_require__(5);
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
exports.default = scope;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function scope(existing) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
if (args.length > 0) {
return [].concat((0, _toConsumableArray3.default)(existing), [args]);
} else {
return existing;
}
}
/***/ },
/***/ "./src/config/features/selector.js":
/***/ function(module, exports, __webpack_require__) {
"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _defineProperty2 = __webpack_require__(29);
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends3 = __webpack_require__(0);
var _extends4 = _interopRequireDefault(_extends3);
exports.default = selector;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function selector(existing, id, handler) {
if (!id || typeof handler !== 'function') {
return existing;
}
return (0, _extends4.default)({}, existing || {}, (0, _defineProperty3.default)({}, id, handler.bind ? handler.bind(this) : handler));
}
/***/ },
/***/ "./src/config/index.js":
/***/ function(module, exports, __webpack_require__) {
"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.defaultReducers = exports.defaultFeatures = undefined;
var _toConsumableArray2 = __webpack_require__(5);
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _defineProperty2 = __webpack_require__(29);
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends8 = __webpack_require__(0);
var _extends9 = _interopRequireDefault(_extends8);
exports.api = api;
var _stringify = __webpack_require__("./src/config/stringify.js");
var _stringify2 = _interopRequireDefault(_stringify);
var _string = __webpack_require__(15);
var _mapKeys = __webpack_require__(107);
var _mapKeys2 = _interopRequireDefault(_mapKeys);
var _mapValues = __webpack_require__(21);
var _mapValues2 = _interopRequireDefault(_mapValues);
var _reduce = __webpack_require__(128);
var _reduce2 = _interopRequireDefault(_reduce);
var _isUndefined = __webpack_require__(126);
var _isUndefined2 = _interopRequireDefault(_isUndefined);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var featuresReq = __webpack_require__(114);
var reducersReq = __webpack_require__(115);
var es6 = function es6(mod) {
return mod.default ? mod.default : mod;
};
var defaultFeatures = exports.defaultFeatures = featuresReq.keys().reduce(function (memo, key) {
return (0, _extends9.default)({}, memo, (0, _defineProperty3.default)({}, key.replace(/\.\//, '').replace(/\.js$/, ''), es6(featuresReq(key))));
}, {});
var defaultReducers = exports.defaultReducers = reducersReq.keys().reduce(function (memo, key) {
return (0, _extends9.default)({}, memo, (0, _defineProperty3.default)({}, key.replace(/\.\//, '').replace(/\.js$/, ''), es6(reducersReq(key))));
}, {});
function api() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _options$history = options.history,
history = _options$history === undefined ? [] : _options$history,
_options$scope = options.scope,
scope = _options$scope === undefined ? this : _options$scope,
_options$features = options.features,
features = _options$features === undefined ? {} : _options$features,
_options$reducers = options.reducers,
reducers = _options$reducers === undefined ? {} : _options$reducers,
_options$keyFn = options.keyFn,
keyFn = _options$keyFn === undefined ? _string.pluralize : _options$keyFn;
features = (0, _mapValues2.default)((0, _extends9.default)({}, defaultFeatures, features), function (fn) {
return fn.bind ? fn.bind(scope) : fn;
});
reducers = (0, _mapValues2.default)((0, _extends9.default)({}, defaultReducers, reducers), function (fn) {
return fn.bind ? fn.bind(scope) : fn;
});
var getState = function getState() {
var initialState = (0, _reduce2.default)(features, function (acc, feature, name) {
var defaultValue = feature();
if ((0, _isUndefined2.default)(defaultValue)) {
return acc;
}
return (0, _extends9.default)({}, acc, (0, _defineProperty3.default)({}, name, defaultValue));
}, {});
var state = history.reduce(function (acc, _ref) {
var name = _ref.name,
args = _ref.args;
var featureState = acc[name];
var feature = features[name];
return (0, _extends9.default)({}, acc, (0, _defineProperty3.default)({}, name, feature.apply(undefined, [featureState].concat((0, _toConsumableArray3.default)(args)))));
}, initialState);
Object.defineProperty(state, "toString", {
value: function value() {
return (0, _stringify2.default)(state);
}
});
return state;
};
var _getConfig = function _getConfig() {
var tap = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : options.tap;
var state = getState();
var config = (0, _reduce2.default)(reducers, function (config, reducer, name) {
var reduced = reducer(state);
if ((0, _isUndefined2.default)(reduced)) {
return config;
}
return (0, _extends9.default)({}, config, (0, _defineProperty3.default)({}, name, reducer(state)));
}, {});
if (typeof tap === 'function') {
config = tap.call(scope, config, options);
}
Object.defineProperty(config, "toString", {
value: function value() {
return (0, _stringify2.default)(config);
}
});
return config;
};
var when = function when(env, configure) {
var envs = Array.isArray(env) ? env : [env];
var _process$env$NODE_ENV = process.env.NODE_ENV,
NODE_ENV = _process$env$NODE_ENV === undefined ? "development" : _process$env$NODE_ENV;
if (env === true || envs.indexOf(NODE_ENV) !== -1) {
return configure(api({ features: features, reducers: reducers, history: history }));
} else if (typeof env === 'function' && env(getState(), _getConfig)) {
return configure({ features: features, reducers: reducers, history: history });
}
return api({ features: features, reducers: reducers, history: history });
};
return (0, _reduce2.default)(features, function (acc, feature, name) {
return (0, _extends9.default)({}, acc, (0, _defineProperty3.default)({}, name, function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return api({
features: features,
reducers: reducers,
history: history.concat({ args: args, name: name })
});
}));
}, {
getConfig: function getConfig() {
return (0, _mapKeys2.default)(_getConfig.apply(undefined, arguments), function (v, k) {
return keyFn(k);
});
},
getState: getState,
history: history,
when: when
});
}
exports.default = api;
/***/ },
/***/ "./src/config/reducers/collection.js":
/***/ function(module, exports, __webpack_require__) {
"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends2 = __webpack_require__(0);
var _extends3 = _interopRequireDefault(_extends2);
exports.default = collection;
var _path = __webpack_require__(12);
var _lang = __webpack_require__(127);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function collection(state) {
var collection = state.collection;
if (!collection) {
return undefined;
}
var args = collection.map(function (val) {
if (val.length === 1 && (0, _lang.isString)(val[0])) {
return {
name: (0, _path.basename)(val[0]),
cwd: val[0]
};
}
if (val.length === 1 && (0, _lang.isObject)(val[0])) {
return val[0];
}
if (val.length === 1 && (0, _lang.isString)(val[0]) && (0, _lang.isString)(val[1])) {
return {
name: val[0],
cwd: (0, _path.resolve)(val[1], state.context || process.cwd())
};
}
if (val.length === 1 && (0, _lang.isString)(val[0]) && (0, _lang.isObject)(val[1])) {
return (0, _extends3.default)({
name: val[0]
}, val[1]);
}
return val;
});
return args.filter(function (i) {
return i.length > 0;
});
}
/***/ },
/***/ "./src/config/reducers/feature.js":
/***/ function(module, exports) {
"use strict";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = feature;
function feature(state) {
return state.feature;
}
/***/ },
/***/ "./src/config/reducers/scope.js":
/***/ function(module, exports) {
"use strict";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = scope;
function scope(state) {
var scope = state.scope;
return scope;
}
/***/ },
/***/ "./src/config/reducers/selector.js":
/***/ function(module, exports) {
"use strict";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = selector;
function selector(state) {
return state.selector;
}
/***/ },
/***/ "./src/config/stringify.js":
/***/ function(module, exports, __webpack_require__) {
"use strict";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _stringify = __webpack_require__(96);
var _stringify2 = _interopRequireDefault(_stringify);
var _keys = __webpack_require__(13);
var _keys2 = _interopRequireDefault(_keys);
exports.default = stringify;
var _isPlainObject = __webpack_require__(125);
var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
var _Expression = __webpack_require__("./src/config/Expression.js");
var _Expression2 = _interopRequireDefault(_Expression);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function stringify(value) {
var replacements = [];
var replace = function replace(replacement) {
return "__REPLACEMENT_" + (replacements.push(replacement) - 1) + "__";
};
var sort = function sort(object) {
return (0, _keys2.default)(object).sort().reduce(function (sorted, key) {
sorted[key] = object[key];
return sorted;
}, {});
};
var replacer = function replacer(key, value) {
if (value instanceof _Expression2.default) {
return replace(value.toString());
}
if (value instanceof RegExp) {
return replace(value.toString());
}
return value;
};
var string = (0, _stringify2.default)(_isPlainObject2.default ? sort(value) : value, replacer, 2);
return string.replace(/(^[\s]+)?"__REPLACEMENT_([\d]+)__"/gm, function (match) {
var indent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
var index = arguments[2];
return ("" + indent + replacements[index]).split("\n").join("\n" + indent);
});
}
/***/ },
/***/ "./src/document-types/asset.js":
/***/ function(module, exports, __webpack_require__) {
"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.testDocument = exports.rules = undefined;
var _pathMatcher = __webpack_require__(7);
var _pathMatcher2 = _interopRequireDefault(_pathMatcher);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var rules = exports.rules = [/\.(png|jpg|gif)$/i];
var testDocument = exports.testDocument = function testDocument(doc) {
return typeof rules.find(function (rule) {
return (0, _pathMatcher2.default)(rule, doc.fileBaseName);
}) !== 'undefined';
};
/***/ },
/***/ "./src/document-types/babel-es6.js":
/***/ function(module, exports, __webpack_require__) {
"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.decorate = exports.transpile = exports.toAST = exports.compile = exports.testDocument = exports.rules = exports.docblockParser = undefined;
var _assign = __webpack_require__(1);
var _assign2 = _interopRequireDefault(_assign);
var _pathMatcher = __webpack_require__(7);
var _pathMatcher2 = _interopRequireDefault(_pathMatcher);
var _pick = __webpack_require__(33);
var _pick2 = _interopRequireDefault(_pick);
var _omit = __webpack_require__(17);
var _omit2 = _interopRequireDefault(_omit);
var _mapValues = __webpack_require__(21);
var _mapValues2 = _interopRequireDefault(_mapValues);
var _omitBy = __webpack_require__(68);
var _omitBy2 = _interopRequireDefault(_omitBy);
var _isEmpty = __webpack_require__(32);
var _isEmpty2 = _interopRequireDefault(_isEmpty);
var _docblockParser = __webpack_require__(19);
var _docblockParser2 = _interopRequireDefault(_docblockParser);
var _entity = __webpack_require__(34);
var _entity2 = _interopRequireDefault(_entity);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var docblockParser = exports.docblockParser = (0, _docblockParser2.default)({
tags: {
name: _docblockParser2.default.singleParameterTag
}
});
var rules = exports.rules = [/\.(js|es6|jsx)$/];
var testDocument = exports.testDocument = function testDocument(doc) {
return typeof rules.find(function (rule) {
return (0, _pathMatcher2.default)(rule, doc.fileBaseName);
}) !== 'undefined';
};
var compile = exports.compile = function compile(code, options) {
return transpile(code, options).code;
};
var toAST = exports.toAST = function toAST(code, options) {
return __webpack_require__(27).transform(code, babelOptions(options)).ast;
};
var transpile = exports.transpile = function transpile() {
var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return __webpack_require__(27).transform(code, babelOptions(options));
};
var decorate = exports.decorate = function decorate(doc) {
(0, _assign2.default)(doc, {
toEntity: function toEntity() {
var exportables = doc.exportables;
var frontmatter = exportables.frontmatter;
return (0, _assign2.default)({ id: doc.id }, frontmatter, {
imports: exportables.imports,
exports: exportables.exports
});
},
/**
multilineTilTag
multilineTilEmptyLineOrTag
booleanTag
singleParameterTag
multiParameterTag(delimiter)
*/
docblockParser: function docblockParser() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var parser = (0, _docblockParser2.default)({
tags: (0, _assign2.default)({
name: _docblockParser2.default.singleParameterTag
}, options)
});
return parser.parse;
},
createExportable: function createExportable() {
var exportable = (0, _entity2.default)({
id: doc.id,
file: (0, _omit2.default)(doc.file, 'contents')
});
exportable.lazy('babel', function () {
return doc.transformBabel();
});
exportable.lazy('ast', function () {
return exportable.babel.ast;
});
exportable.lazy('code', function () {
return exportable.babel.code;
});
exportable.lazy('meta', function () {
return exportable.babel.metadata;
});
exportable.lazy('commentNodes', function () {
return exportable.get('ast.comments', []);
});
exportable.lazy('imports', function () {
return exportable.get('babel.metadata.modules.i