UNPKG

@teambit/lanes

Version:
137 lines (135 loc) • 6.44 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 _componentModules() { const data = require("@teambit/component.modules.merge-helper"); _componentModules = function () { return data; }; return data; } function _cli() { const data = require("@teambit/cli"); _cli = 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', 'DEPRECATED. this is currently the default behavior'], ['', 'skip-fetch', "don't fetch the latest from the remote; switch to the lane/main state already in the local scope"], ['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, skipFetch = false, alias, autoMergeResolve, forceOurs, forceTheirs, getAll = false, workspaceOnly = false, skipDependencyInstallation = false, pattern, verbose, json = false, branch = false }) { const switchResult = await this.lanes.switchLanes(lane, { skipFetch, alias, merge: autoMergeResolve, forceOurs, forceTheirs, workspaceOnly, pattern, skipDependencyInstallation, branch }); const { components, failedComponents, installationError, compilationError, gitBranchWarning } = switchResult; if (getAll) { this.lanes.logger.consoleWarning('the --get-all flag is deprecated and currently the default behavior'); } if (head) { this.lanes.logger.consoleWarning('the --head flag is deprecated and currently the default behavior'); } if (json) { return JSON.stringify({ components, failedComponents }, null, 4); } const skippedComponents = failedComponents ?? []; const hasSkippedComponents = skippedComponents.length > 0 && !verbose; const getFailureOutputMinimal = () => { if (!hasSkippedComponents) return ''; return (0, _cli().formatDetailsHint)(`full list of ${skippedComponents.length} skipped component(s)`); }; const getFailureOutputDetailed = () => { if (!skippedComponents.length) return ''; const items = skippedComponents.map(failedComponent => (0, _cli().formatItem)(`${_chalk().default.bold(failedComponent.id.toString())} - ${failedComponent.unchangedMessage}`)); return (0, _cli().formatSection)('switch skipped', '', items); }; const getSuccessfulOutput = () => { const laneSwitched = (0, _cli().formatSuccessSummary)(`successfully set "${_chalk().default.bold(lane)}" as the active lane`); if (!components || !components.length) return `No components have been changed.\n${laneSwitched}`; const target = skipFetch ? `local head of lane ${lane}` : `head of lane ${lane}`; const title = `successfully switched ${components.length} components to the ${target}`; return [(0, _cli().formatSuccessSummary)(title), (0, _componentModules().applyVersionReport)(components, true, false), laneSwitched].filter(Boolean).join('\n'); }; const getGitBranchWarningOutput = () => { return gitBranchWarning ? _chalk().default.yellow(`Warning: ${gitBranchWarning}`) : ''; }; const buildOutput = failureOutput => (0, _cli().joinSections)([failureOutput, getSuccessfulOutput(), getGitBranchWarningOutput(), (0, _componentModules().installationErrorOutput)(installationError), (0, _componentModules().compilationErrorOutput)(compilationError)]); if (!hasSkippedComponents) { return buildOutput(getFailureOutputDetailed()); } const data = buildOutput(getFailureOutputMinimal()); const details = buildOutput(getFailureOutputDetailed()); return { data, code: 0, details }; } } exports.SwitchCmd = SwitchCmd; //# sourceMappingURL=switch.cmd.js.map