UNPKG

@teambit/workspace

Version:
76 lines (73 loc) 3.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PatternCommand = void 0; function _chalk() { const data = _interopRequireDefault(require("chalk")); _chalk = function () { return data; }; return data; } function _filter() { const data = require("./filter"); _filter = 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 PatternCommand { constructor(workspace) { this.workspace = workspace; _defineProperty(this, "name", 'pattern <pattern>'); _defineProperty(this, "alias", ''); _defineProperty(this, "description", 'list the component ids matching the given pattern'); _defineProperty(this, "extendedDescription", `this command helps validating a pattern before using it in other commands. NOTE: always wrap the pattern with quotes to avoid collision with shell commands. depending on your shell, it might be single or double quotes. a pattern can be a simple component-id or component-name. e.g. 'ui/button'. a pattern can be used with wildcards for multiple component ids, e.g. 'org.scope/utils/**' or '**/utils/**' to capture all org/scopes. to enter multiple patterns, separate them by a comma, e.g. 'ui/*, lib/*' to exclude, use '!'. e.g. 'ui/**, !ui/button' the matching algorithm is from multimatch (@see https://github.com/sindresorhus/multimatch). to filter by a state or attribute, prefix the pattern with "$". e.g. '$deprecated', '$modified'. list of supported states: [${_filter().statesFilter.join(', ')}]. to filter by multi-params state/attribute, separate the params with ":", e.g. '$env:teambit.react/react'. list of supported multi-params states: [env]. to match a state and another criteria, use " AND " keyword. e.g. '$modified AND teambit.workspace/** AND $env:teambit.react/react'. `); _defineProperty(this, "examples", [{ cmd: "bit pattern '**'", description: 'matches all components' }, { cmd: "bit pattern '*/ui/*'", description: 'matches components with any scope-name and the "ui" namespace. e.g. "ui/button" but not "ui/elements/button"' }, { cmd: "bit pattern '*/ui/**'", description: 'matches components whose namespace starts with "ui/" e.g. "ui/button", "ui/elements/button"' }, { cmd: "bit pattern 'bar, foo'", description: 'matches two components: bar and foo' }, { cmd: "bit pattern 'my-scope.org/**'", description: 'matches all components of the scope "my-scope.org"' }]); _defineProperty(this, "group", 'info-analysis'); _defineProperty(this, "private", false); _defineProperty(this, "options", [['j', 'json', 'return the output as JSON']]); } async report([pattern]) { const ids = await this.json([pattern]); const title = _chalk().default.green(`found ${_chalk().default.bold(ids.length.toString())} components matching the pattern`); return `${title}\n${ids.join('\n')}`; } async json([pattern]) { return this.workspace.idsByPattern(pattern, false); } } exports.PatternCommand = PatternCommand; //# sourceMappingURL=pattern.cmd.js.map