@teambit/lanes
Version:
786 lines (782 loc) • 36.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LaneShowCmd = exports.LaneRevertCmd = exports.LaneRenameCmd = exports.LaneRemoveReadmeCmd = exports.LaneRemoveCompCmd = exports.LaneRemoveCmd = exports.LaneListCmd = exports.LaneImportCmd = exports.LaneHistoryCmd = exports.LaneFetchCmd = exports.LaneEjectCmd = exports.LaneCurrentCmd = exports.LaneCreateCmd = exports.LaneCmd = exports.LaneCheckoutCmd = exports.LaneChangeScopeCmd = exports.LaneAliasCmd = exports.CatLaneHistoryCmd = void 0;
function _chalk() {
const data = _interopRequireDefault(require("chalk"));
_chalk = function () {
return data;
};
return data;
}
function _laneId() {
const data = require("@teambit/lane-id");
_laneId = function () {
return data;
};
return data;
}
function _checkout() {
const data = require("@teambit/checkout");
_checkout = function () {
return data;
};
return data;
}
function _workspace() {
const data = require("@teambit/workspace");
_workspace = 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.scope");
_legacy = function () {
return data;
};
return data;
}
function _bitError() {
const data = require("@teambit/bit-error");
_bitError = function () {
return data;
};
return data;
}
function _yesno() {
const data = _interopRequireDefault(require("yesno"));
_yesno = function () {
return data;
};
return data;
}
function _legacy2() {
const data = require("@teambit/legacy.constants");
_legacy2 = function () {
return data;
};
return data;
}
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return 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); } // eslint-disable-next-line max-classes-per-file
class LaneListCmd {
constructor(lanes, workspace, scope) {
this.lanes = lanes;
this.workspace = workspace;
this.scope = scope;
_defineProperty(this, "name", 'list');
_defineProperty(this, "description", `list local or remote lanes`);
_defineProperty(this, "alias", '');
_defineProperty(this, "options", [['d', 'details', 'show more details on the state of each component in each lane'], ['j', 'json', "show lanes' details in a json format"], ['r', 'remote <remote-scope-name>', 'show all remote lanes from the specified scope'], ['', 'merged', 'list only merged lanes'], ['', 'not-merged', "list only lanes that haven't been merged"]]);
_defineProperty(this, "loader", true);
_defineProperty(this, "remoteOp", true);
_defineProperty(this, "skipWorkspace", true);
}
async report(args, laneOptions) {
const {
details,
remote,
merged,
notMerged
} = laneOptions;
const laneIdStr = (laneId, alias) => {
if (laneId.isDefault()) return laneId.name;
if (alias) return `${laneId.toString()} (${alias})`;
return laneId.toString();
};
const lanes = await this.lanes.getLanes({
remote,
merged,
notMerged,
showDefaultLane: true
});
if (merged) {
const mergedLanes = lanes.filter(l => l.isMerged);
if (!mergedLanes.length) return (0, _cli().formatHint)('none of the lanes is merged');
const items = mergedLanes.map(m => (0, _cli().formatItem)(m.name));
return (0, _cli().formatSection)('merged lanes', '', items);
}
if (notMerged) {
const unmergedLanes = lanes.filter(l => !l.isMerged);
if (!unmergedLanes.length) return (0, _cli().formatHint)('all lanes are merged');
const items = unmergedLanes.map(m => (0, _cli().formatItem)(m.name));
return (0, _cli().formatSection)('unmerged lanes', '', items);
}
const currentLane = this.lanes.getCurrentLaneId() || this.lanes.getDefaultLaneId();
const laneDataOfCurrentLane = currentLane ? lanes.find(l => currentLane.isEqual(l.id)) : undefined;
const currentAlias = laneDataOfCurrentLane ? laneDataOfCurrentLane.alias : undefined;
const currentLaneReadmeComponentStr = outputReadmeComponent(laneDataOfCurrentLane?.readmeComponent);
const getCurrentLaneOutput = () => {
if (remote) return '';
const currentLaneLabel = `current lane - ${_chalk().default.green(laneIdStr(currentLane, currentAlias))}${currentLaneReadmeComponentStr}`;
if (details && laneDataOfCurrentLane) {
return `${currentLaneLabel}\n${outputComponents(laneDataOfCurrentLane.components)}`;
}
return currentLaneLabel;
};
const getAvailableLanesOutput = () => {
const otherLanes = lanes.filter(l => !currentLane.isEqual(l.id));
if (!otherLanes.length) return '';
if (details) {
const items = otherLanes.map(laneData => {
const readmeComponentStr = outputReadmeComponent(laneData.readmeComponent);
const laneTitle = `> ${_chalk().default.bold(laneIdStr(laneData.id, laneData.alias))}`;
const components = outputComponents(laneData.components);
return `${laneTitle}${readmeComponentStr}\n${components}`;
});
return items.join('\n\n');
}
const items = otherLanes.map(laneData => {
const readmeComponentStr = outputReadmeComponent(laneData.readmeComponent);
return (0, _cli().formatItem)(`${_chalk().default.green(laneIdStr(laneData.id, laneData.alias))} (${laneData.components.length} components)${readmeComponentStr}`);
});
return (0, _cli().formatSection)('available lanes', '', items);
};
const getFooter = () => {
const hints = [];
if (details) {
hints.push('use --merged and --not-merged to see which of the lanes is fully merged');
} else {
hints.push("use 'bit lane list --details' or 'bit lane show <lane-name>' for more info");
}
if (!remote && this.workspace) {
hints.push("switch lanes using 'bit switch <name>'. create lanes using 'bit lane create <name>'");
}
return (0, _cli().formatHint)(hints.join('\n'));
};
return (0, _cli().joinSections)([getCurrentLaneOutput(), getAvailableLanesOutput(), getFooter()]);
}
async json(args, laneOptions) {
const {
remote,
merged = false,
notMerged = false
} = laneOptions;
const lanesData = await this.lanes.getLanes({
remote,
showDefaultLane: true,
merged,
notMerged
});
const lanes = lanesData.map(_legacy().serializeLaneData);
const currentLane = this.lanes.getCurrentLaneNameOrAlias();
return {
lanes,
currentLane
};
}
}
exports.LaneListCmd = LaneListCmd;
class LaneCurrentCmd {
constructor(lanes) {
this.lanes = lanes;
_defineProperty(this, "name", 'current');
_defineProperty(this, "description", 'display the name of the current lane');
_defineProperty(this, "alias", '');
_defineProperty(this, "options", [['j', 'json', 'output in json format']]);
_defineProperty(this, "loader", false);
_defineProperty(this, "skipWorkspace", false);
}
async report() {
const currentLaneId = this.lanes.getCurrentLaneId();
if (!currentLaneId || currentLaneId.isDefault()) {
return _laneId().DEFAULT_LANE;
}
const alias = this.lanes.getCurrentLaneNameOrAlias();
if (alias && alias !== currentLaneId.name) {
return `${currentLaneId.toString()} (${alias})`;
}
return currentLaneId.toString();
}
async json() {
const currentLaneId = this.lanes.getCurrentLaneId();
if (!currentLaneId || currentLaneId.isDefault()) {
return {
name: _laneId().DEFAULT_LANE,
scope: null,
id: _laneId().DEFAULT_LANE,
isDefault: true,
alias: null
};
}
const alias = this.lanes.getCurrentLaneNameOrAlias();
return {
name: currentLaneId.name,
scope: currentLaneId.scope,
id: currentLaneId.toString(),
isDefault: false,
alias: alias !== currentLaneId.name ? alias : null
};
}
}
exports.LaneCurrentCmd = LaneCurrentCmd;
class LaneShowCmd {
constructor(lanes, workspace, scope) {
this.lanes = lanes;
this.workspace = workspace;
this.scope = scope;
_defineProperty(this, "name", 'show [lane-name]');
_defineProperty(this, "description", `show lane details. if no lane specified, show the current lane`);
_defineProperty(this, "alias", '');
_defineProperty(this, "options", [['j', 'json', 'show the lane details in json format'], ['r', 'remote', 'show details of the remote head of the provided lane']]);
_defineProperty(this, "loader", true);
_defineProperty(this, "remoteOp", true);
_defineProperty(this, "skipWorkspace", true);
}
async report([name], laneOptions) {
const lanes = await this.geLanesData([name], laneOptions);
const onlyLane = lanes[0];
const laneId = onlyLane.id;
const laneIdStr = laneId.isDefault() ? _laneId().DEFAULT_LANE : laneId.toString();
const title = (0, _cli().formatTitle)(laneIdStr);
const author = onlyLane.log ? `author: ${onlyLane.log?.username || 'N/A'} <${onlyLane.log?.email || 'N/A'}>` : '';
const date = onlyLane.log?.date ? `created: ${new Date(parseInt(onlyLane.log.date)).toLocaleString()}` : '';
const link = laneId.isDefault() ? '' : `link: https://${_legacy2().DEFAULT_CLOUD_DOMAIN}/${laneId.scope.replace('.', '/')}/~lane/${laneId.name}`;
const meta = [author, date, link].filter(Boolean).join('\n');
return (0, _cli().joinSections)([title, meta, outputComponents(onlyLane.components)]);
}
async geLanesData([name], laneOptions) {
const {
remote
} = laneOptions;
if (!name && remote) {
throw new Error('remote flag is not supported without lane name');
}
if (!name) {
name = this.lanes.getCurrentLaneName() || _laneId().DEFAULT_LANE;
}
const laneId = await this.lanes.parseLaneId(name);
const lanes = await this.lanes.getLanes({
name: laneId.name,
remote: remote ? laneId.scope : undefined
});
return lanes;
}
async json([name], laneOptions) {
const lanes = await this.geLanesData([name], laneOptions);
return (0, _legacy().serializeLaneData)(lanes[0]);
}
}
exports.LaneShowCmd = LaneShowCmd;
class LaneCreateCmd {
constructor(lanes) {
this.lanes = lanes;
_defineProperty(this, "name", 'create <lane-name>');
_defineProperty(this, "arguments", [{
name: 'lane-name',
description: 'the name for the new lane'
}]);
_defineProperty(this, "description", `creates a new lane and switches to it`);
_defineProperty(this, "extendedDescription", `a lane created from main (default-lane) is empty until components are snapped.
a lane created from another lane contains all the components of the original lane.`);
_defineProperty(this, "alias", '');
_defineProperty(this, "options", [['s', 'scope <scope-name>', 'remote scope to which this lane will be exported, default to the workspace.json\'s defaultScope (can be changed up to first export of the lane with "bit lane change-scope")'], ['', 'remote-scope <scope-name>', 'DEPRECATED. use --scope'], ['', 'alias <name>', 'a local alias to refer to this lane, defaults to the `<lane-name>` (can be added later with "bit lane alias")'], ['', 'fork-lane-new-scope', 'create the new lane in a different scope than its parent lane (if created from another lane)']]);
_defineProperty(this, "loader", true);
}
async report([name], createLaneOptions) {
if (!this.lanes.workspace) throw new (_workspace().OutsideWorkspaceError)();
const currentLane = await this.lanes.getCurrentLane();
if (createLaneOptions.remoteScope) createLaneOptions.scope = createLaneOptions.remoteScope;
const result = await this.lanes.createLane(name, createLaneOptions);
const remoteScopeOrDefaultScope = createLaneOptions.scope ? `the remote scope ${_chalk().default.bold(createLaneOptions.scope)}` : `the default-scope ${_chalk().default.bold(result.laneId.scope)}. you can change the lane's scope, before it is exported, with the "bit lane change-scope" command`;
const summary = (0, _cli().formatSuccessSummary)(`successfully created and checked out to lane ${_chalk().default.bold(result.alias || result.laneId.name)}`);
const note = currentLane ? (0, _cli().formatHint)(`note - your new lane will be based on lane ${currentLane.name}`) : '';
const scopeInfo = (0, _cli().formatHint)(`this lane will be exported to ${remoteScopeOrDefaultScope}`);
return (0, _cli().joinSections)([summary, note, scopeInfo]);
}
}
exports.LaneCreateCmd = LaneCreateCmd;
class LaneAliasCmd {
constructor(lanes) {
this.lanes = lanes;
_defineProperty(this, "name", 'alias <lane-name> <alias>');
_defineProperty(this, "description", 'adds an alias to a lane');
_defineProperty(this, "extendedDescription", `an alias is a name that can be used locally to refer to a lane. it is saved locally and never reaches the remote.
it is useful e.g. when having multiple lanes with the same name, but with different remote scopes.`);
_defineProperty(this, "alias", '');
_defineProperty(this, "options", []);
_defineProperty(this, "loader", true);
}
async report([laneName, alias]) {
const {
laneId
} = await this.lanes.aliasLane(laneName, alias);
return `successfully added the alias ${_chalk().default.bold(alias)} for lane ${_chalk().default.bold(laneId.toString())}`;
}
}
exports.LaneAliasCmd = LaneAliasCmd;
class CatLaneHistoryCmd {
constructor(lanes) {
this.lanes = lanes;
_defineProperty(this, "name", 'cat-lane-history <lane-name>');
_defineProperty(this, "description", 'cat lane-history object by lane-name');
_defineProperty(this, "private", true);
_defineProperty(this, "alias", 'clh');
_defineProperty(this, "options", []);
_defineProperty(this, "loader", true);
_defineProperty(this, "group", 'advanced');
}
async report([laneName]) {
const laneId = await this.lanes.parseLaneId(laneName);
const laneHistory = await this.lanes.getLaneHistory(laneId);
return JSON.stringify(laneHistory.toObject(), null, 2);
}
}
exports.CatLaneHistoryCmd = CatLaneHistoryCmd;
class LaneCheckoutCmd {
constructor(lanes) {
this.lanes = lanes;
_defineProperty(this, "name", 'checkout <history-id>');
_defineProperty(this, "description", 'checkout to a previous history of the current lane. see also "bit lane revert"');
_defineProperty(this, "arguments", [{
name: 'history-id',
description: 'the history-id to checkout to. run "bit lane history" to list the ids'
}]);
_defineProperty(this, "alias", '');
_defineProperty(this, "options", [['x', 'skip-dependency-installation', 'do not install dependencies of the checked out components']]);
_defineProperty(this, "loader", true);
}
async report([historyId], opts) {
const result = await this.lanes.checkoutHistory(historyId, opts);
return (0, _checkout().checkoutOutput)(result, {}, `successfully checked out according to history-id: ${historyId}`);
}
}
exports.LaneCheckoutCmd = LaneCheckoutCmd;
class LaneRevertCmd {
constructor(lanes) {
this.lanes = lanes;
_defineProperty(this, "name", 'revert <history-id>');
_defineProperty(this, "description", 'revert to a previous history of the current lane. see also "bit lane checkout"');
_defineProperty(this, "extendedDescription", `revert is similar to "lane checkout", but it keeps the versions and only change the files.
choose one or the other based on your needs.
if you want to continue working on this lane and needs the changes from the history to be the head, then use "lane revert".
if you want to fork the lane from a certain point in history, use "lane checkout" and create a new lane from it.`);
_defineProperty(this, "arguments", [{
name: 'history-id',
description: 'the history-id to checkout to. run "bit lane history" to list the ids'
}]);
_defineProperty(this, "alias", '');
_defineProperty(this, "options", [['x', 'skip-dependency-installation', 'do not install dependencies of the checked out components'], ['', 'restore-deleted-components', 'restore components that were deleted after this history point'], ['j', 'json', 'return the revert result in json format']]);
_defineProperty(this, "loader", true);
}
async report([historyId], opts) {
const result = await this.lanes.revertHistory(historyId, opts);
return (0, _checkout().checkoutOutput)(result, {}, `successfully reverted according to history-id: ${historyId}`);
}
async json([historyId], opts) {
const result = await this.lanes.revertHistory(historyId, opts);
return {
components: result.components?.map(component => ({
id: component.id.toString(),
filesStatus: Object.entries(component.filesStatus || {}).reduce((acc, [filePath, status]) => {
acc[filePath] = status;
return acc;
}, {})
})),
removedComponents: result.removedComponents?.map(id => id.toString()),
addedComponents: result.addedComponents?.map(id => id.toString()),
newComponents: result.newComponents?.map(id => id.toString()),
failedComponents: result.failedComponents?.map(component => ({
id: component.id.toString(),
unchangedMessage: component.unchangedMessage,
unchangedLegitimately: component.unchangedLegitimately
})),
leftUnresolvedConflicts: result.leftUnresolvedConflicts,
newFromLane: result.newFromLane,
newFromLaneAdded: result.newFromLaneAdded,
version: result.version,
resolvedComponents: result.resolvedComponents?.map(component => component.id.toString()),
abortedComponents: result.abortedComponents?.map(component => ({
id: component.id.toString(),
filesStatus: Object.entries(component.filesStatus || {}).reduce((acc, [filePath, status]) => {
acc[filePath] = status;
return acc;
}, {})
})),
installationError: result.installationError?.message,
compilationError: result.compilationError?.message,
mergeSnapError: result.mergeSnapError?.message,
mergeSnapResults: result.mergeSnapResults ? {
snappedComponents: result.mergeSnapResults.snappedComponents?.map(component => component.id.toString()),
removedComponents: result.mergeSnapResults.removedComponents?.toStringArray(),
exportedIds: result.mergeSnapResults.exportedIds?.map(id => id.toString())
} : null,
workspaceConfigUpdateResult: result.workspaceConfigUpdateResult ? {
logs: result.workspaceConfigUpdateResult.logs
} : undefined,
historyId
};
}
}
exports.LaneRevertCmd = LaneRevertCmd;
class LaneHistoryCmd {
constructor(lanes) {
this.lanes = lanes;
_defineProperty(this, "name", 'history [lane-name]');
_defineProperty(this, "description", 'show lane history, default to the current lane');
_defineProperty(this, "extendedDescription", `list from the oldest to the newest history items`);
_defineProperty(this, "alias", '');
_defineProperty(this, "options", [['', 'id <string>', 'show a specific history item'], ['j', 'json', 'return the lane history in json format']]);
_defineProperty(this, "loader", true);
}
async getHistoryData(laneName, id) {
const laneId = laneName ? await this.lanes.parseLaneId(laneName) : this.lanes.getCurrentLaneId();
if (!laneId || laneId.isDefault()) throw new (_bitError().BitError)(`unable to show history of the default lane (main)`);
await this.lanes.importLaneHistory(laneId);
const laneHistory = await this.lanes.getLaneHistory(laneId);
const history = laneHistory.getHistory();
if (id) {
const historyItem = history[id];
if (!historyItem) throw new Error(`history id ${id} was not found`);
return {
historyItem,
id,
history,
singleItem: true
};
}
return {
history,
sortedIds: laneHistory.getHistoryIds(),
singleItem: false
};
}
getDateString(date) {
return new Date(parseInt(date)).toLocaleString();
}
async report([laneName], {
id
}) {
const data = await this.getHistoryData(laneName, id);
if (data.singleItem) {
const {
historyItem
} = data;
const date = this.getDateString(historyItem.log.date);
const message = historyItem.log.message;
const updateDependentsBlock = historyItem.updateDependents?.length ? `\n\nupdateDependents:\n${historyItem.updateDependents.join('\n')}` : '';
return `${id} ${date} ${historyItem.log.username} ${message}\n\n${historyItem.components.join('\n')}${updateDependentsBlock}`;
}
const {
history,
sortedIds
} = data;
const items = sortedIds.map(uuid => {
const item = history[uuid];
const date = this.getDateString(item.log.date);
const message = item.log.message;
return `${uuid} ${date} ${item.log.username} ${message}`;
});
return items.join('\n');
}
async json([laneName], {
id
}) {
const data = await this.getHistoryData(laneName, id);
if (data.singleItem) {
const {
historyItem,
id: historyId
} = data;
return _objectSpread({
id: historyId,
date: historyItem.log.date,
username: historyItem.log.username,
message: historyItem.log.message,
components: historyItem.components
}, historyItem.updateDependents?.length && {
updateDependents: historyItem.updateDependents
});
}
const {
history,
sortedIds
} = data;
return sortedIds.map(uuid => {
const item = history[uuid];
return _objectSpread({
id: uuid,
date: item.log.date,
username: item.log.username,
message: item.log.message,
components: item.components
}, item.updateDependents?.length && {
updateDependents: item.updateDependents
});
});
}
}
exports.LaneHistoryCmd = LaneHistoryCmd;
class LaneEjectCmd {
constructor(lanes) {
this.lanes = lanes;
_defineProperty(this, "name", 'eject <component-pattern>');
_defineProperty(this, "description", `delete a component from the lane and install it as a package from main`);
_defineProperty(this, "extendedDescription", `NOTE: unlike "bit eject" on main, this command doesn't only remove the component from the
workspace, but also mark it as deleted from the lane, so it won't be merged later on.`);
_defineProperty(this, "alias", '');
_defineProperty(this, "arguments", [{
name: 'component-pattern',
description: _legacy2().COMPONENT_PATTERN_HELP
}]);
_defineProperty(this, "options", []);
_defineProperty(this, "loader", true);
}
async report([pattern]) {
const results = await this.lanes.eject(pattern);
const title = _chalk().default.green('successfully ejected the following components');
const body = results.map(r => r.toString()).join('\n');
return `${title}\n${body}`;
}
}
exports.LaneEjectCmd = LaneEjectCmd;
class LaneChangeScopeCmd {
constructor(lanes) {
this.lanes = lanes;
_defineProperty(this, "name", 'change-scope <remote-scope-name>');
_defineProperty(this, "description", `changes the remote scope of a lane`);
_defineProperty(this, "extendedDescription", 'NOTE: available only before the lane is exported to the remote');
_defineProperty(this, "alias", '');
_defineProperty(this, "options", [['l', 'lane-name <lane-name>', 'the name of the lane to change its remote scope. if not specified, the current lane is used']]);
_defineProperty(this, "loader", true);
}
async report([remoteScope], {
laneName
}) {
const {
remoteScopeBefore,
localName
} = await this.lanes.changeScope(remoteScope, laneName);
return `the remote-scope of ${_chalk().default.bold(localName)} has been changed from ${_chalk().default.bold(remoteScopeBefore)} to ${_chalk().default.bold(remoteScope)}`;
}
}
exports.LaneChangeScopeCmd = LaneChangeScopeCmd;
class LaneRenameCmd {
constructor(lanes) {
this.lanes = lanes;
_defineProperty(this, "name", 'rename <new-name>');
_defineProperty(this, "description", `change the lane-name locally`);
_defineProperty(this, "extendedDescription", 'the remote will be updated after the next "bit export" command');
_defineProperty(this, "alias", '');
_defineProperty(this, "options", [['l', 'lane-name <lane-name>', 'the name of the lane to rename. if not specified, the current lane is used']]);
_defineProperty(this, "loader", true);
}
async report([newName], {
laneName
}) {
const {
currentName
} = await this.lanes.rename(newName, laneName);
return `the lane ${_chalk().default.bold(currentName)}'s name has been changed to ${_chalk().default.bold(newName)}.`;
}
}
exports.LaneRenameCmd = LaneRenameCmd;
class LaneRemoveCmd {
constructor(lanes) {
this.lanes = lanes;
_defineProperty(this, "name", 'remove <lanes...>');
_defineProperty(this, "arguments", [{
name: 'lanes...',
description: 'A list of lane names, separated by spaces'
}]);
_defineProperty(this, "description", `remove or delete lanes`);
_defineProperty(this, "group", 'collaborate');
_defineProperty(this, "alias", '');
_defineProperty(this, "options", [['r', 'remote', 'delete a remote lane. use remote/lane-id syntax e.g. bit lane remove owner.org/my-lane --remote. Delete is immediate, no export required'], ['f', 'force', 'removes/deletes the lane even when the lane is not yet merged to main'], ['s', 'silent', 'skip confirmation']]);
_defineProperty(this, "loader", true);
}
async report([names], {
remote = false,
force = false,
silent = false
}) {
if (!silent) {
this.lanes.logger.clearStatusLine(); // stop the logger to avoid polluting the prompt
const shouldProceed = await (0, _yesno().default)({
question: 'Are you sure you would like to proceed with this operation? [yes(y)/no(n)]'
});
if (!shouldProceed) {
throw new (_bitError().BitError)('the operation has been cancelled');
}
}
const laneResults = await this.lanes.removeLanes(names, {
remote,
force
});
return _chalk().default.green(`successfully removed the following lane(s): ${_chalk().default.bold(laneResults.join(', '))}`);
}
}
exports.LaneRemoveCmd = LaneRemoveCmd;
class LaneRemoveCompCmd {
constructor(workspace, lanes) {
this.workspace = workspace;
this.lanes = lanes;
_defineProperty(this, "name", 'remove-comp <component-pattern>');
_defineProperty(this, "arguments", [{
name: 'component-pattern',
description: _legacy2().COMPONENT_PATTERN_HELP
}]);
_defineProperty(this, "description", `DEPRECATED. remove components when on a lane`);
_defineProperty(this, "group", 'collaborate');
_defineProperty(this, "alias", 'rc');
_defineProperty(this, "options", [['', 'workspace-only', 'do not mark the components as removed from the lane. instead, remove them from the workspace only'], ['', 'update-main', 'EXPERIMENTAL. remove, i.e. delete, component/s on the main lane after merging this lane into main']]);
_defineProperty(this, "loader", true);
}
async report() {
throw new (_bitError().BitError)(`bit lane remove-comp has been removed. please use "bit remove" or "bit delete" instead`);
}
}
exports.LaneRemoveCompCmd = LaneRemoveCompCmd;
class LaneImportCmd {
constructor(switchCmd, lanes) {
this.switchCmd = switchCmd;
this.lanes = lanes;
_defineProperty(this, "name", 'import <lane>');
_defineProperty(this, "description", `import a remote lane to your workspace`);
_defineProperty(this, "extendedDescription", `when on the default lane, the workspace is switched to the imported lane.
when already on the same lane, only the latest objects are fetched from the remote — run "bit checkout head" to update the workspace.
when on a different lane, the lane is fetched locally without switching to avoid disrupting your work — run \`bit switch <lane>\` to switch.`);
_defineProperty(this, "arguments", [{
name: 'lane',
description: 'the remote lane name'
}]);
_defineProperty(this, "alias", '');
_defineProperty(this, "options", [['x', 'skip-dependency-installation', 'do not install dependencies of the imported components'], ['p', 'pattern <component-pattern>', 'import only components from the lane that fit the specified component-pattern to the workspace. works only when the workspace is empty'], ['', 'branch', 'create and checkout a new git branch named after the lane'], ['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']]);
_defineProperty(this, "loader", true);
}
async report([lane], {
skipDependencyInstallation = false,
pattern,
branch = false,
autoMergeResolve,
forceOurs = false,
forceTheirs = false
}) {
if (forceOurs && forceTheirs) {
throw new (_bitError().BitError)('please use either --force-ours or --force-theirs, not both');
}
const currentLaneId = this.lanes.getCurrentLaneId();
// when on the default lane (or outside a workspace), keep the original behavior: switch to the imported lane.
if (!currentLaneId || currentLaneId.isDefault()) {
return this.switchCmd.report([lane], {
skipDependencyInstallation,
pattern,
branch,
autoMergeResolve,
forceOurs,
forceTheirs
});
}
// already on a (non-default) lane: do not auto-switch, only fetch the lane locally.
const targetLaneId = await this.lanes.parseLaneId(lane);
await this.lanes.fetchLaneWithItsComponents(targetLaneId);
if (currentLaneId.isEqual(targetLaneId)) {
return (0, _cli().joinSections)([(0, _cli().formatSuccessSummary)(`you are already on lane "${_chalk().default.bold(targetLaneId.toString())}". the lane has been fetched from the remote, but your workspace files were ${_chalk().default.bold('not')} updated.`), `${_chalk().default.yellow('to update your workspace files to the latest')}, run "${_chalk().default.bold('bit checkout head')}".`]);
}
return (0, _cli().joinSections)([(0, _cli().formatSuccessSummary)(`imported lane "${_chalk().default.bold(targetLaneId.toString())}" locally`), (0, _cli().formatHint)(`you are still on lane "${currentLaneId.toString()}". to switch to the imported lane, run "bit switch ${targetLaneId.toString()}"`)]);
}
}
exports.LaneImportCmd = LaneImportCmd;
class LaneFetchCmd {
constructor(fetchCmd, lanes) {
this.fetchCmd = fetchCmd;
this.lanes = lanes;
_defineProperty(this, "name", 'fetch [lane-id]');
_defineProperty(this, "description", `fetch component objects from lanes. if no lane-id is provided, it fetches from the current lane`);
_defineProperty(this, "extendedDescription", `note, it does not save the remote lanes objects locally, only the refs`);
_defineProperty(this, "alias", '');
_defineProperty(this, "options", [['a', 'all', 'fetch all remote lanes']]);
_defineProperty(this, "loader", true);
}
async report([laneId], {
all
}) {
if (all) return this.fetchCmd.report([[]], {
lanes: true
});
const getLaneIdStr = () => {
if (laneId) return laneId;
const currentLane = this.lanes.getCurrentLaneId();
if (!currentLane || currentLane.isDefault()) throw new (_bitError().BitError)('you are not checked out to any lane. please specify a lane-id to fetch or use --all flag');
return currentLane.toString();
};
const lane = getLaneIdStr();
return this.fetchCmd.report([[lane]], {
lanes: true
});
}
}
exports.LaneFetchCmd = LaneFetchCmd;
class LaneCmd {
constructor(lanes, workspace, scope) {
this.lanes = lanes;
this.workspace = workspace;
this.scope = scope;
_defineProperty(this, "name", 'lane [sub-command]');
_defineProperty(this, "description", 'manage lanes for parallel development');
_defineProperty(this, "extendedDescription", `lanes allow isolated development of features without affecting main branch components.
create, switch between, and merge lanes to coordinate parallel work across teams.
without a sub-command, lists all available lanes.`);
_defineProperty(this, "alias", 'l');
_defineProperty(this, "options", [['d', 'details', 'show more details on the state of each component in each lane'], ['j', 'json', 'show lanes details in json format'], ['r', 'remote <remote-scope-name>', 'show all remote lanes from the specified scope'], ['', 'merged', 'list only merged lanes'], ['', 'not-merged', "list only lanes that haven't been merged"]]);
_defineProperty(this, "loader", true);
_defineProperty(this, "group", 'collaborate');
_defineProperty(this, "remoteOp", true);
_defineProperty(this, "skipWorkspace", true);
_defineProperty(this, "helpUrl", 'reference/components/lanes');
_defineProperty(this, "commands", []);
}
async report([name], laneOptions) {
return new LaneListCmd(this.lanes, this.workspace, this.scope).report([name], laneOptions);
}
}
/**
* @deprecated - only use it to revert the add-readme command changes
*/
exports.LaneCmd = LaneCmd;
class LaneRemoveReadmeCmd {
constructor(lanes) {
this.lanes = lanes;
_defineProperty(this, "name", 'remove-readme [laneName]');
_defineProperty(this, "description", 'DEPRECATED (only use it if you have used add-readme and want to undo it). remove lane readme component');
_defineProperty(this, "options", []);
_defineProperty(this, "loader", true);
_defineProperty(this, "skipWorkspace", false);
}
async report([laneName]) {
const {
result,
message
} = await this.lanes.removeLaneReadme(laneName);
if (result) {
return _chalk().default.green(`the readme component has been successfully removed from the lane ${laneName || this.lanes.getCurrentLaneName()}`);
}
return _chalk().default.red(`${message}\n`);
}
}
exports.LaneRemoveReadmeCmd = LaneRemoveReadmeCmd;
function outputComponents(components) {
const items = components.map(c => (0, _cli().formatItem)(`${c.id.toString()} - ${c.head}`));
return (0, _cli().formatSection)('components', '', items);
}
function outputReadmeComponent(component) {
if (!component) return '';
const head = component.head || '(unsnapped)';
const hint = component.head ? '' : ` - use "bit snap ${component.id.fullName}" to snap before exporting`;
const prefix = component.head ? ' ' : ` ${_cli().warnSymbol} `;
return `${prefix}readme: ${component.id} - ${head}${hint}`;
}
//# sourceMappingURL=lane.cmd.js.map