UNPKG

bit-bin

Version:

<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b

154 lines (122 loc) 3.95 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.findLegacyDetails = findLegacyDetails; exports.LegacyCommandAdapter = void 0; function _bluebird() { const data = require("bluebird"); _bluebird = function () { return data; }; return data; } function _defineProperty2() { const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); _defineProperty2 = function () { return data; }; return data; } function _allHelp() { const data = _interopRequireDefault(require("../../cli/templates/all-help")); _allHelp = function () { return data; }; return data; } function _() { const data = require("."); _ = function () { return data; }; return data; } class LegacyCommandAdapter { constructor(cmd, cliExtension) { this.cmd = cmd; (0, _defineProperty2().default)(this, "alias", void 0); (0, _defineProperty2().default)(this, "name", void 0); (0, _defineProperty2().default)(this, "description", void 0); (0, _defineProperty2().default)(this, "options", void 0); (0, _defineProperty2().default)(this, "shortDescription", void 0); (0, _defineProperty2().default)(this, "group", void 0); (0, _defineProperty2().default)(this, "loader", void 0); (0, _defineProperty2().default)(this, "commands", void 0); (0, _defineProperty2().default)(this, "private", void 0); (0, _defineProperty2().default)(this, "migration", void 0); (0, _defineProperty2().default)(this, "internal", void 0); (0, _defineProperty2().default)(this, "_packageManagerArgs", void 0); this.name = cmd.name; this.description = cmd.description; this.options = cmd.opts || []; this.alias = cmd.alias; const commandID = (0, _().getID)(cmd.name); const { summery, group } = findLegacyDetails(commandID, cliExtension); this.shortDescription = summery; this.group = group; this.loader = cmd.loader; this.private = cmd.private; this.migration = cmd.migration; this.internal = cmd.internal; this.commands = (cmd.commands || []).map(sub => new LegacyCommandAdapter(sub, cliExtension)); } action(params, options) { var _this = this; return (0, _bluebird().coroutine)(function* () { const res = yield _this.cmd.action(params, options, _this._packageManagerArgs); let data = res; let code = 0; if (res && res.__code !== undefined) { data = res.data; code = res.__code; } const report = _this.cmd.report(data, params, options); return { code, report }; })(); } report(params, options) { var _this2 = this; return (0, _bluebird().coroutine)(function* () { const actionResult = yield _this2.action(params, options); return { data: actionResult.report, code: actionResult.code }; })(); } json(params, options) { var _this3 = this; return (0, _bluebird().coroutine)(function* () { const actionResult = yield _this3.action(params, options); return { data: JSON.parse(actionResult.report), code: actionResult.code }; })(); } } // TODO: remove all help and move information to commands exports.LegacyCommandAdapter = LegacyCommandAdapter; function findLegacyDetails(name, p) { let group = ''; let summery = ''; for (let i = 0; i < _allHelp().default.length; i += 1) { const index = _allHelp().default[i].commands.findIndex(command => command.name === name); // eslint-disable-next-line no-bitwise if (~index) { group = _allHelp().default[i].group; summery = _allHelp().default[i].commands[index].description; !p.groups[group] && p.registerGroup(group, _allHelp().default[i].title); } } return { group, summery }; }