JezK
Edit File: _build-sub-commands.js
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = _default; function _regenerator() { var data = _interopRequireDefault(require("@babel/runtime/regenerator")); _regenerator = function _regenerator() { return data; }; return data; } function _asyncToGenerator2() { var data = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); _asyncToGenerator2 = function _asyncToGenerator2() { return data; }; return data; } function _errors() { var data = require("../../errors.js"); _errors = function _errors() { return data; }; return data; } function _misc() { var data = require("../../util/misc.js"); _misc = function _misc() { return data; }; return data; } function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { 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 = it.call(o); }, 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 _default(rootCommandName, subCommands) { var usage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; var subCommandNames = Object.keys(subCommands).map(_misc().hyphenate); function setFlags(commander) { commander.usage("".concat(rootCommandName, " [").concat(subCommandNames.join('|'), "] [flags]")); } function run(_x, _x2, _x3, _x4, _x5) { return _run.apply(this, arguments); } function _run() { _run = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee(config, reporter, commander, flags, args) { var subName, command, res, _iterator, _step, msg; return _regenerator()["default"].wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: subName = (0, _misc().camelCase)(args.shift() || ''); if (!(subName && subCommands[subName])) { _context.next = 8; break; } command = subCommands[subName]; _context.next = 5; return command(config, reporter, commander, flags, args); case 5: res = _context.sent; if (!(res !== false)) { _context.next = 8; break; } return _context.abrupt("return", Promise.resolve()); case 8: if (usage && usage.length) { reporter.error("".concat(reporter.lang('usage'), ":")); _iterator = _createForOfIteratorHelper(usage); try { for (_iterator.s(); !(_step = _iterator.n()).done;) { msg = _step.value; reporter.error("yarn ".concat(rootCommandName, " ").concat(msg)); } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } } return _context.abrupt("return", Promise.reject(new (_errors().MessageError)(reporter.lang('invalidCommand', subCommandNames.join(', '))))); case 10: case "end": return _context.stop(); } }, _callee); })); return _run.apply(this, arguments); } function hasWrapper(commander, args) { return true; } var examples = usage.map(function (cmd) { return "".concat(rootCommandName, " ").concat(cmd); }); return { run: run, setFlags: setFlags, hasWrapper: hasWrapper, examples: examples }; } //# sourceMappingURL=_build-sub-commands.js.map