@teambit/workspace 0.0.733 → 0.0.736

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ import { Command } from '@teambit/cli';
2
+ import { Workspace } from '../workspace';
3
+ export declare class ScopeSetCmd implements Command {
4
+ private workspace;
5
+ name: string;
6
+ description: string;
7
+ options: never[];
8
+ group: string;
9
+ extendedDescription: string;
10
+ constructor(workspace: Workspace);
11
+ report([pattern, scopeName]: [string, string]): Promise<string>;
12
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ require("core-js/modules/es.array.iterator.js");
6
+
7
+ require("core-js/modules/es.promise.js");
8
+
9
+ Object.defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+ exports.ScopeSetCmd = void 0;
13
+
14
+ function _defineProperty2() {
15
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
+
17
+ _defineProperty2 = function () {
18
+ return data;
19
+ };
20
+
21
+ return data;
22
+ }
23
+
24
+ function _constants() {
25
+ const data = require("@teambit/legacy/dist/constants");
26
+
27
+ _constants = function () {
28
+ return data;
29
+ };
30
+
31
+ return data;
32
+ }
33
+
34
+ function _chalk() {
35
+ const data = _interopRequireDefault(require("chalk"));
36
+
37
+ _chalk = function () {
38
+ return data;
39
+ };
40
+
41
+ return data;
42
+ }
43
+
44
+ class ScopeSetCmd {
45
+ constructor(workspace) {
46
+ this.workspace = workspace;
47
+ (0, _defineProperty2().default)(this, "name", 'set <pattern> <scope-name>');
48
+ (0, _defineProperty2().default)(this, "description", 'set a scope name for component(s)');
49
+ (0, _defineProperty2().default)(this, "options", []);
50
+ (0, _defineProperty2().default)(this, "group", 'development');
51
+ (0, _defineProperty2().default)(this, "extendedDescription", `${(0, _constants().PATTERN_HELP)('scope set')}`);
52
+ }
53
+
54
+ async report([pattern, scopeName]) {
55
+ const componentsIds = await this.workspace.idsByPattern(pattern);
56
+ const changedIds = await this.workspace.setDefaultScopeToComponents(componentsIds, scopeName);
57
+ return _chalk().default.green(`successfully set ${_chalk().default.bold(scopeName)} as the default-scope for the following component(s):
58
+ ${_chalk().default.reset(changedIds.map(id => id.toString()).join('\n'))}`);
59
+ }
60
+
61
+ }
62
+
63
+ exports.ScopeSetCmd = ScopeSetCmd;
64
+
65
+ //# sourceMappingURL=scope-set.cmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["scope-set.cmd.ts"],"names":["ScopeSetCmd","constructor","workspace","report","pattern","scopeName","componentsIds","idsByPattern","changedIds","setDefaultScopeToComponents","chalk","green","bold","reset","map","id","toString","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,WAAN,CAAqC;AAO1CC,EAAAA,WAAW,CAASC,SAAT,EAA+B;AAAA,SAAtBA,SAAsB,GAAtBA,SAAsB;AAAA,kDANnC,4BAMmC;AAAA,yDAL5B,mCAK4B;AAAA,qDAJhC,EAIgC;AAAA,mDAHlC,aAGkC;AAAA,iEAFnB,GAAE,+BAAa,WAAb,CAA0B,EAET;AAAE;;AAEhC,QAANC,MAAM,CAAC,CAACC,OAAD,EAAUC,SAAV,CAAD,EAAyC;AACnD,UAAMC,aAAa,GAAG,MAAM,KAAKJ,SAAL,CAAeK,YAAf,CAA4BH,OAA5B,CAA5B;AACA,UAAMI,UAAU,GAAG,MAAM,KAAKN,SAAL,CAAeO,2BAAf,CAA2CH,aAA3C,EAA0DD,SAA1D,CAAzB;AACA,WAAOK,iBAAMC,KAAN,CAAa,oBAAmBD,iBAAME,IAAN,CAAWP,SAAX,CAAsB;AACjE,EAAEK,iBAAMG,KAAN,CAAYL,UAAU,CAACM,GAAX,CAAgBC,EAAD,IAAQA,EAAE,CAACC,QAAH,EAAvB,EAAsCC,IAAtC,CAA2C,IAA3C,CAAZ,CAA8D,EADrD,CAAP;AAED;;AAdyC","sourcesContent":["import { Command } from '@teambit/cli';\nimport { PATTERN_HELP } from '@teambit/legacy/dist/constants';\nimport chalk from 'chalk';\nimport { Workspace } from '../workspace';\n\nexport class ScopeSetCmd implements Command {\n name = 'set <pattern> <scope-name>';\n description = 'set a scope name for component(s)';\n options = [];\n group = 'development';\n extendedDescription = `${PATTERN_HELP('scope set')}`;\n\n constructor(private workspace: Workspace) {}\n\n async report([pattern, scopeName]: [string, string]) {\n const componentsIds = await this.workspace.idsByPattern(pattern);\n const changedIds = await this.workspace.setDefaultScopeToComponents(componentsIds, scopeName);\n return chalk.green(`successfully set ${chalk.bold(scopeName)} as the default-scope for the following component(s):\n${chalk.reset(changedIds.map((id) => id.toString()).join('\\n'))}`);\n }\n}\n"]}
@@ -376,6 +376,11 @@ export declare class Workspace implements ComponentFactory {
376
376
  isModified(component: Component): Promise<boolean>;
377
377
  private filterEnvsFromExtensionsIfNeeded;
378
378
  triggerOnPreWatch(componentIds: ComponentID[], watchOpts: WatchOptions): Promise<void>;
379
+ /**
380
+ * filter the given component-ids and set default-scope only to the new ones.
381
+ * returns the affected components.
382
+ */
383
+ setDefaultScopeToComponents(componentIds: ComponentID[], scopeName: string): Promise<ComponentID[]>;
379
384
  addSpecificComponentConfig(id: ComponentID, aspectId: string, config?: Record<string, any>): Promise<void>;
380
385
  removeSpecificComponentConfig(id: ComponentID, aspectId: string, markWithMinusIfNotExist: boolean): Promise<void>;
381
386
  getAspectIdFromConfig(componentId: ComponentID, aspectIdStr: string, ignoreAspectVersion?: boolean): Promise<string | undefined>;
package/dist/workspace.js CHANGED
@@ -1588,6 +1588,28 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1588
1588
  await func(components, watchOpts);
1589
1589
  });
1590
1590
  }
1591
+ /**
1592
+ * filter the given component-ids and set default-scope only to the new ones.
1593
+ * returns the affected components.
1594
+ */
1595
+
1596
+
1597
+ async setDefaultScopeToComponents(componentIds, scopeName) {
1598
+ if (!(0, _legacyBitId().isValidScopeName)(scopeName)) {
1599
+ throw new (_legacyBitId().InvalidScopeName)(scopeName);
1600
+ }
1601
+
1602
+ const newComponentIds = componentIds.filter(id => !id.hasVersion());
1603
+
1604
+ if (!newComponentIds.length) {
1605
+ const compIdsStr = componentIds.map(compId => compId.toString()).join(', ');
1606
+ throw new (_bitError().BitError)(`unable to set default-scope for the following components, as they are not new:\n${compIdsStr}`);
1607
+ }
1608
+
1609
+ newComponentIds.map(comp => this.bitMap.setDefaultScope(comp, scopeName));
1610
+ await this.bitMap.write();
1611
+ return newComponentIds;
1612
+ }
1591
1613
 
1592
1614
  async addSpecificComponentConfig(id, aspectId, config = {}) {
1593
1615
  const componentConfigFile = await this.componentConfigFile(id);