@teambit/export
Version:
174 lines (172 loc) • 8.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ExportCmd = void 0;
function _open() {
const data = _interopRequireDefault(require("open"));
_open = function () {
return data;
};
return data;
}
function _eject() {
const data = require("@teambit/eject");
_eject = function () {
return data;
};
return data;
}
function _legacy() {
const data = require("@teambit/legacy.constants");
_legacy = function () {
return data;
};
return data;
}
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 _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 ExportCmd {
constructor(exportMain) {
this.exportMain = exportMain;
_defineProperty(this, "name", 'export [component-patterns...]');
_defineProperty(this, "description", 'export components from the workspace to remote scopes');
_defineProperty(this, "arguments", [{
name: 'component-patterns...',
description: `(not recommended) ${_legacy().COMPONENT_PATTERN_HELP}`
}]);
_defineProperty(this, "extendedDescription", `bit export => export all staged snaps/tags of components to their remote scope. if checked out to a lane, export the lane as well
\`bit export [pattern...]\` => export components included by the pattern to their remote scope (we recommend not using a pattern in
most scenarios so that all changes are exported simultaneously)
${(0, _legacy().WILDCARD_HELP)('export')}`);
_defineProperty(this, "alias", 'e');
_defineProperty(this, "helpUrl", 'reference/components/exporting-components');
_defineProperty(this, "options", [['e', 'eject', 'after export, remove the components from the workspace and install them as packages'], ['a', 'all', 'export all components, including non-staged (useful when components in the remote scope are corrupted or missing)'], ['', 'all-versions', 'export not only staged versions but all of them (useful when versions in the remote scope are corrupted or missing)'], ['', 'origin-directly', 'avoid export to the central hub, instead, export directly to the original scopes. not recommended!'], ['', 'resume <string>', 'in case the previous export failed and suggested to resume with an export-id, enter the id'], ['', 'head-only', 'in case previous export failed and locally it shows exported and only one snap/tag was created, try using this flag'], ['', 'ignore-missing-artifacts', "don't throw an error when artifact files are missing. not recommended, unless you're sure the artifacts are in the remote"], ['', 'fork-lane-new-scope', 'allow exporting a forked lane into a different scope than the original scope'], ['', 'open-browser', 'open a browser once the export is completed in the cloud job url'], ['', 'verbose', 'per exported component, show the versions being exported'], ['j', 'json', 'show output in json format']]);
_defineProperty(this, "loader", true);
_defineProperty(this, "group", 'collaborate');
_defineProperty(this, "remoteOp", true);
}
async report([ids = []], {
eject = false,
all = false,
allVersions = false,
originDirectly = false,
ignoreMissingArtifacts = false,
resume,
headOnly,
forkLaneNewScope = false,
openBrowser = false,
verbose = false
}) {
const {
componentsIds,
newIdsOnRemote,
nonExistOnBitMap,
removedIds,
missingScope,
exportedLanes,
ejectResults,
rippleJobUrls
} = await this.exportMain.export({
ids,
eject,
includeNonStaged: all || allVersions,
allVersions: allVersions || all,
originDirectly,
resumeExportId: resume,
headOnly,
ignoreMissingArtifacts,
forkLaneNewScope
});
if ((0, _lodash().isEmpty)(componentsIds) && (0, _lodash().isEmpty)(nonExistOnBitMap) && (0, _lodash().isEmpty)(missingScope) && !exportedLanes.length) {
return _chalk().default.yellow('nothing to export');
}
const exportedLane = exportedLanes[0]?.id();
const getExportedIds = () => {
if (!verbose) return componentsIds.join('\n');
return componentsIds.map(id => {
const versions = newIdsOnRemote.filter(newId => newId.isEqualWithoutVersion(id)).map(newId => newId.version);
return `${id.toString()} - ${versions.join(', ') || 'n/a'}`;
}).join('\n');
};
const exportOutput = () => {
if ((0, _lodash().isEmpty)(componentsIds)) return exportedLane ? `exported the lane ${_chalk().default.bold(exportedLane)}` : '';
const lanesOutput = exportedLanes.length ? ` the lane ${_chalk().default.bold(exportedLanes[0].id())} and` : '';
return _chalk().default.green(`exported${lanesOutput} the following ${componentsIds.length} component(s):\n${_chalk().default.bold(getExportedIds())}`);
};
const nonExistOnBitMapOutput = () => {
// if includeDependencies is true, the nonExistOnBitMap might be the dependencies
if ((0, _lodash().isEmpty)(nonExistOnBitMap)) return '';
const idsStr = nonExistOnBitMap.map(id => id.toString()).join(', ');
return _chalk().default.yellow(`${idsStr}\nexported successfully. bit did not update the workspace as the component files are not tracked. this might happen when a component was tracked in a different git branch. to fix it check if they where tracked in a different git branch, checkout to that branch and resync by running 'bit import'. or stay on your branch and track the components again using 'bit add'.\n`);
};
const removedOutput = () => {
if (!removedIds.length) return '';
const remoteLaneStr = exportedLanes.length ? ' lane' : '';
const title = _chalk().default.bold(`\n\nthe following component(s) have been marked as removed on the remote${remoteLaneStr}\n`);
const idsStr = removedIds.join('\n');
return title + idsStr;
};
const missingScopeOutput = () => {
if ((0, _lodash().isEmpty)(missingScope)) return '';
const idsStr = missingScope.map(id => id.toString()).join(', ');
return _chalk().default.yellow(`the following component(s) were not exported as no remote scope is configured for them: ${_chalk().default.bold(idsStr)}.\nplease specify <remote> to export them, run 'bit scope set <scope> <component>, or set a "defaultScope" in your workspace config\n\n`);
};
const ejectOutput = () => {
if (!ejectResults) return '';
const output = (0, _eject().ejectTemplate)(ejectResults);
return `\n${output}`;
};
const rippleJobsOutput = () => {
if (!rippleJobUrls.length) return '';
const shouldOpenBrowser = openBrowser && !process.env.CI;
const prefix = shouldOpenBrowser ? 'Your browser has been opened to the following link' : 'Visit the link below';
const msg = `\n\n${prefix} to track the progress of building the components in the cloud\n`;
if (shouldOpenBrowser) {
(0, _open().default)(rippleJobUrls[0]).catch(() => {
/** it's ok, the user is instructed to open the browser manually */
});
}
const urlsColored = rippleJobUrls.map(url => _chalk().default.bold.underline(url));
return msg + urlsColored.join('\n');
};
return nonExistOnBitMapOutput() + missingScopeOutput() + exportOutput() + ejectOutput() + removedOutput() + rippleJobsOutput();
}
async json([ids = []], {
eject = false,
all = false,
allVersions = false,
originDirectly = false,
ignoreMissingArtifacts = false,
resume
}) {
const results = await this.exportMain.export({
ids,
eject,
includeNonStaged: all || allVersions,
allVersions: allVersions || all,
originDirectly,
resumeExportId: resume,
ignoreMissingArtifacts
});
return results;
}
}
exports.ExportCmd = ExportCmd;
//# sourceMappingURL=export-cmd.js.map