twm-weapp
Version:
208 lines (152 loc) • 9.18 kB
JavaScript
;
require("core-js/modules/es.symbol");
require("core-js/modules/es.symbol.description");
require("core-js/modules/es.symbol.iterator");
require("core-js/modules/es.array.concat");
require("core-js/modules/es.array.from");
require("core-js/modules/es.array.is-array");
require("core-js/modules/es.array.iterator");
require("core-js/modules/es.array.map");
require("core-js/modules/es.array.slice");
require("core-js/modules/es.date.to-string");
require("core-js/modules/es.function.name");
require("core-js/modules/es.object.define-property");
require("core-js/modules/es.object.to-string");
require("core-js/modules/es.promise");
require("core-js/modules/es.regexp.to-string");
require("core-js/modules/es.set");
require("core-js/modules/es.string.iterator");
require("core-js/modules/web.dom-collections.iterator");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GlobbyPathPlugin = void 0;
require("regenerator-runtime/runtime");
var _globby = _interopRequireDefault(require("globby"));
var _utils = require("../utils");
var _helper = require("../helper");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var GlobbyPathPlugin = /*#__PURE__*/function () {
function GlobbyPathPlugin() {
_classCallCheck(this, GlobbyPathPlugin);
}
_createClass(GlobbyPathPlugin, [{
key: "apply",
value: function apply(twm) {
var _this = this;
twm.hooks.initialHooks.tapPromise('GlobbyPath', function (context) {
return new Promise( /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(resolve) {
var root;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
root = context.root;
_context.next = 3;
return _this.createFileResourceMap((0, _utils.joinPath)(root, '/**'), context);
case 3:
resolve(context);
case 4:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}());
});
}
/**
* 创建文件对象
*/
}, {
key: "createFileResourceMap",
value: function () {
var _createFileResourceMap = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(globbyPath, context) {
var paths, _iterator, _step, filePath;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return this.getGlobbyPaths(globbyPath, context);
case 2:
paths = _context2.sent;
_iterator = _createForOfIteratorHelper(paths);
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
filePath = _step.value;
(0, _helper.processAddDir)((0, _utils.dirname)(filePath), context);
(0, _helper.processAddFile)(filePath, context);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
case 5:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
function createFileResourceMap(_x2, _x3) {
return _createFileResourceMap.apply(this, arguments);
}
return createFileResourceMap;
}()
/**
* 获取扫描目录集合
*/
}, {
key: "getGlobbyPaths",
value: function () {
var _getGlobbyPaths = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(globbyPath, context) {
var output, miniprogram, root, ignores, path, gPathSet, gPath;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
output = context.output, miniprogram = context.miniprogram, root = context.root, ignores = context.ignores;
path = typeof globbyPath === 'string' ? [globbyPath] : globbyPath;
gPathSet = new Set(["!".concat((0, _utils.joinPath)(root, 'node_modules')), "!".concat((0, _utils.joinPath)(root, 'miniprogram_npm')), "!".concat((0, _utils.joinPath)(miniprogram, 'node_modules')), "!".concat((0, _utils.joinPath)(miniprogram, 'miniprogram_npm'))]);
gPath = [].concat(_toConsumableArray(path), _toConsumableArray(gPathSet), _toConsumableArray(ignores.map(function (i) {
return "!".concat(i);
})), ["!".concat(output)]);
_context3.next = 6;
return (0, _globby["default"])(gPath);
case 6:
return _context3.abrupt("return", _context3.sent);
case 7:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
function getGlobbyPaths(_x4, _x5) {
return _getGlobbyPaths.apply(this, arguments);
}
return getGlobbyPaths;
}()
}]);
return GlobbyPathPlugin;
}();
exports.GlobbyPathPlugin = GlobbyPathPlugin;