UNPKG

@teambit/workspace

Version:
101 lines (99 loc) 4.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LocalOnlyUnsetCmd = exports.LocalOnlySetCmd = exports.LocalOnlyListCmd = exports.LocalOnlyCmd = void 0; function _chalk() { const data = _interopRequireDefault(require("chalk")); _chalk = 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); } /* eslint max-classes-per-file: 0 */ class LocalOnlySetCmd { constructor(workspace) { this.workspace = workspace; _defineProperty(this, "name", 'set <component-pattern>'); _defineProperty(this, "description", 'set a component as local-only'); _defineProperty(this, "arguments", [{ name: 'component-pattern', description: _legacy().COMPONENT_PATTERN_HELP }]); _defineProperty(this, "alias", ''); _defineProperty(this, "options", []); } async report([pattern]) { const ids = await this.workspace.idsByPattern(pattern); await this.workspace.setLocalOnly(ids); const title = _chalk().default.bold(`successfully set the following components as local-only`); return `${title}:\n${ids.map(id => id.toString()).join('\n')}`; } } exports.LocalOnlySetCmd = LocalOnlySetCmd; class LocalOnlyUnsetCmd { constructor(workspace) { this.workspace = workspace; _defineProperty(this, "name", 'unset <component-pattern>'); _defineProperty(this, "description", 'remove a component from local-only'); _defineProperty(this, "arguments", [{ name: 'component-pattern', description: _legacy().COMPONENT_PATTERN_HELP }]); _defineProperty(this, "alias", ''); _defineProperty(this, "options", []); } async report([pattern]) { const ids = await this.workspace.idsByPattern(pattern); const successfullyUnset = await this.workspace.unsetLocalOnly(ids); if (successfullyUnset.length === 0) { return _chalk().default.yellow('no local-only components were found'); } const title = _chalk().default.bold(`successfully unset the following component(s)`); return `${title}:\n${successfullyUnset.map(id => id.toString()).join('\n')}`; } } exports.LocalOnlyUnsetCmd = LocalOnlyUnsetCmd; class LocalOnlyListCmd { constructor(workspace) { this.workspace = workspace; _defineProperty(this, "name", 'list'); _defineProperty(this, "description", 'list all local-only components'); _defineProperty(this, "alias", ''); _defineProperty(this, "options", []); } async report() { const ids = this.workspace.listLocalOnly(); if (ids.length === 0) { return _chalk().default.yellow('no local-only components were found'); } const title = _chalk().default.bold(`the following component(s) are local-only`); return `${title}:\n${ids.map(id => id.toString()).join('\n')}`; } } exports.LocalOnlyListCmd = LocalOnlyListCmd; class LocalOnlyCmd { constructor() { _defineProperty(this, "name", 'local-only <sub-command>'); _defineProperty(this, "description", 'manage local-only components, which reside only in the workspace and are not snapped/tagged'); _defineProperty(this, "group", 'component-config'); _defineProperty(this, "alias", ''); _defineProperty(this, "commands", []); _defineProperty(this, "options", []); } async report([unrecognizedSubcommand]) { return _chalk().default.red(`"${unrecognizedSubcommand}" is not a subcommand of "local-only", please run "bit local-only --help" to list the subcommands`); } } exports.LocalOnlyCmd = LocalOnlyCmd; //# sourceMappingURL=local-only-cmd.js.map