UNPKG

@teambit/lanes

Version:
125 lines (123 loc) 5.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SwitchCmd = void 0; function _chalk() { const data = _interopRequireDefault(require("chalk")); _chalk = function () { return data; }; return data; } function _lodash() { const data = require("lodash"); _lodash = function () { return data; }; return data; } function _componentModules() { const data = require("@teambit/component.modules.merge-helper"); _componentModules = function () { return data; }; return data; } function _legacy() { const data = require("@teambit/legacy.constants"); _legacy = function () { return data; }; return data; } function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } class SwitchCmd { constructor(lanes) { this.lanes = lanes; _defineProperty(this, "name", 'switch <lane>'); _defineProperty(this, "description", `switch to the specified lane`); _defineProperty(this, "extendedDescription", ``); _defineProperty(this, "private", true); _defineProperty(this, "group", 'collaborate'); _defineProperty(this, "alias", ''); _defineProperty(this, "arguments", [{ name: 'lane', description: 'lane-name or lane-id (if lane is not local) to switch to' }]); _defineProperty(this, "options", [['h', 'head', 'switch to the head of the lane/main (fetches the latest changes from the remote)'], ['r', 'auto-merge-resolve <merge-strategy>', 'merge local changes with the checked out version. strategy should be "theirs", "ours" or "manual"'], ['', 'force-ours', 'do not merge, preserve local files as is'], ['', 'force-theirs', 'do not merge, just overwrite with incoming files'], ['a', 'get-all', 'DEPRECATED. this is currently the default behavior'], ['', 'workspace-only', 'checkout only the components in the workspace to the selected lane'], ['x', 'skip-dependency-installation', 'do not install dependencies of the imported components'], ['p', 'pattern <component-pattern>', `switch only the lane components matching the specified component-pattern. only works when the workspace is empty\n ${_legacy().COMPONENT_PATTERN_HELP}`], ['n', 'alias <string>', "relevant when the specified lane is a remote lane. create a local alias for the lane (doesnt affect the lane's name on the remote"], ['', 'verbose', 'display detailed information about components that legitimately were not switched'], ['j', 'json', 'return the output as JSON'], ['', 'branch', 'create and checkout a new git branch named after the lane']]); _defineProperty(this, "loader", true); } async report([lane], { head, alias, autoMergeResolve, forceOurs, forceTheirs, getAll = false, workspaceOnly = false, skipDependencyInstallation = false, pattern, verbose, json = false, branch = false }) { const switchResult = await this.lanes.switchLanes(lane, { head, alias, merge: autoMergeResolve, forceOurs, forceTheirs, workspaceOnly, pattern, skipDependencyInstallation, branch }); const { components, failedComponents, installationError, compilationError, gitBranchWarning } = switchResult; if (getAll) { this.lanes.logger.warn('the --get-all flag is deprecated and currently the default behavior'); } if (json) { return JSON.stringify({ components, failedComponents }, null, 4); } const getFailureOutput = () => { if (!failedComponents || !failedComponents.length) return ''; const title = '\nswitch skipped for the following component(s)'; const body = (0, _lodash().compact)(failedComponents.map(failedComponent => { // all failures here are "unchangedLegitimately". otherwise, it would have been thrown as an error if (!verbose) return null; return `${_chalk().default.bold(failedComponent.id.toString())} - ${_chalk().default.white(failedComponent.unchangedMessage)}`; })).join('\n'); if (!body) { return `${_chalk().default.bold(`\nswitch skipped legitimately for ${failedComponents.length} component(s)`)} (use --verbose to list them next time)`; } return `${_chalk().default.underline(title)}\n${body}`; }; const getSuccessfulOutput = () => { const laneSwitched = _chalk().default.green(`\nsuccessfully set "${_chalk().default.bold(lane)}" as the active lane`); if (!components || !components.length) return `No components have been changed.${laneSwitched}`; const title = `successfully switched ${components.length} components to the head of lane ${lane}\n`; return _chalk().default.bold(title) + (0, _componentModules().applyVersionReport)(components, true, false) + laneSwitched; }; const getGitBranchWarningOutput = () => { return gitBranchWarning ? _chalk().default.yellow(`Warning: ${gitBranchWarning}`) : null; }; return (0, _lodash().compact)([getFailureOutput(), getSuccessfulOutput(), getGitBranchWarningOutput(), (0, _componentModules().installationErrorOutput)(installationError), (0, _componentModules().compilationErrorOutput)(compilationError)]).join('\n\n'); } } exports.SwitchCmd = SwitchCmd; //# sourceMappingURL=switch.cmd.js.map