@teambit/workspace 0.0.734 → 0.0.737
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.
- package/dist/scope-subcommands/scope-set.cmd.d.ts +12 -0
- package/dist/scope-subcommands/scope-set.cmd.js +74 -0
- package/dist/scope-subcommands/scope-set.cmd.js.map +1 -0
- package/dist/workspace.d.ts +6 -0
- package/dist/workspace.js +53 -2
- package/dist/workspace.js.map +1 -1
- package/dist/workspace.provider.js +14 -1
- package/dist/workspace.provider.js.map +1 -1
- package/package-tar/teambit-workspace-0.0.737.tgz +0 -0
- package/package.json +31 -31
- package/{preview-1652785756723.js → preview-1652930732694.js} +2 -2
- package/scope-subcommands/scope-set.cmd.ts +31 -0
- package/tsconfig.json +1 -1
- package/package-tar/teambit-workspace-0.0.734.tgz +0 -0
|
@@ -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([scopeName, pattern]: [string, string]): Promise<string>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 <scope-name> [pattern]');
|
|
48
|
+
(0, _defineProperty2().default)(this, "description", 'set the default-scope');
|
|
49
|
+
(0, _defineProperty2().default)(this, "options", []);
|
|
50
|
+
(0, _defineProperty2().default)(this, "group", 'development');
|
|
51
|
+
(0, _defineProperty2().default)(this, "extendedDescription", `set a new scope in the workspace.jsonc.
|
|
52
|
+
if "pattern" is provided, the default-scope will be set to the new components matching the criteria.
|
|
53
|
+
|
|
54
|
+
${(0, _constants().PATTERN_HELP)('scope set scope-name')}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async report([scopeName, pattern]) {
|
|
58
|
+
if (pattern) {
|
|
59
|
+
const componentsIds = await this.workspace.idsByPattern(pattern);
|
|
60
|
+
const changedIds = await this.workspace.setDefaultScopeToComponents(componentsIds, scopeName);
|
|
61
|
+
return _chalk().default.green(`successfully set ${_chalk().default.bold(scopeName)} as the default-scope for the following component(s):
|
|
62
|
+
${_chalk().default.reset(changedIds.map(id => id.toString()).join('\n'))}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const oldScope = this.workspace.defaultScope;
|
|
66
|
+
await this.workspace.setDefaultScope(scopeName);
|
|
67
|
+
return _chalk().default.green(`successfully set the default-scope to ${_chalk().default.bold(scopeName)}. (previous scope was "${oldScope}")`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
exports.ScopeSetCmd = ScopeSetCmd;
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=scope-set.cmd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["scope-set.cmd.ts"],"names":["ScopeSetCmd","constructor","workspace","report","scopeName","pattern","componentsIds","idsByPattern","changedIds","setDefaultScopeToComponents","chalk","green","bold","reset","map","id","toString","join","oldScope","defaultScope","setDefaultScope"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,WAAN,CAAqC;AAU1CC,EAAAA,WAAW,CAASC,SAAT,EAA+B;AAAA,SAAtBA,SAAsB,GAAtBA,SAAsB;AAAA,kDATnC,4BASmC;AAAA,yDAR5B,uBAQ4B;AAAA,qDAPhC,EAOgC;AAAA,mDANlC,aAMkC;AAAA,iEALnB;AACzB;AACA;AACA,EAAE,+BAAa,sBAAb,CAAqC,EAEK;AAAE;;AAEhC,QAANC,MAAM,CAAC,CAACC,SAAD,EAAYC,OAAZ,CAAD,EAAyC;AACnD,QAAIA,OAAJ,EAAa;AACX,YAAMC,aAAa,GAAG,MAAM,KAAKJ,SAAL,CAAeK,YAAf,CAA4BF,OAA5B,CAA5B;AACA,YAAMG,UAAU,GAAG,MAAM,KAAKN,SAAL,CAAeO,2BAAf,CAA2CH,aAA3C,EAA0DF,SAA1D,CAAzB;AACA,aAAOM,iBAAMC,KAAN,CAAa,oBAAmBD,iBAAME,IAAN,CAAWR,SAAX,CAAsB;AACnE,IAAIM,iBAAMG,KAAN,CAAYL,UAAU,CAACM,GAAX,CAAgBC,EAAD,IAAQA,EAAE,CAACC,QAAH,EAAvB,EAAsCC,IAAtC,CAA2C,IAA3C,CAAZ,CAA8D,EADrD,CAAP;AAED;;AACD,UAAMC,QAAQ,GAAG,KAAKhB,SAAL,CAAeiB,YAAhC;AACA,UAAM,KAAKjB,SAAL,CAAekB,eAAf,CAA+BhB,SAA/B,CAAN;AACA,WAAOM,iBAAMC,KAAN,CACJ,yCAAwCD,iBAAME,IAAN,CAAWR,SAAX,CAAsB,0BAAyBc,QAAS,IAD5F,CAAP;AAGD;;AAxByC","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 <scope-name> [pattern]';\n description = 'set the default-scope';\n options = [];\n group = 'development';\n extendedDescription = `set a new scope in the workspace.jsonc.\nif \"pattern\" is provided, the default-scope will be set to the new components matching the criteria.\n\n${PATTERN_HELP('scope set scope-name')}`;\n\n constructor(private workspace: Workspace) {}\n\n async report([scopeName, pattern]: [string, string]) {\n if (pattern) {\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 const oldScope = this.workspace.defaultScope;\n await this.workspace.setDefaultScope(scopeName);\n return chalk.green(\n `successfully set the default-scope to ${chalk.bold(scopeName)}. (previous scope was \"${oldScope}\")`\n );\n }\n}\n"]}
|
package/dist/workspace.d.ts
CHANGED
|
@@ -376,6 +376,12 @@ 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[]>;
|
|
384
|
+
setDefaultScope(scopeName: string): Promise<void>;
|
|
379
385
|
addSpecificComponentConfig(id: ComponentID, aspectId: string, config?: Record<string, any>): Promise<void>;
|
|
380
386
|
removeSpecificComponentConfig(id: ComponentID, aspectId: string, markWithMinusIfNotExist: boolean): Promise<void>;
|
|
381
387
|
getAspectIdFromConfig(componentId: ComponentID, aspectIdStr: string, ignoreAspectVersion?: boolean): Promise<string | undefined>;
|
package/dist/workspace.js
CHANGED
|
@@ -501,6 +501,16 @@ function _bitMap() {
|
|
|
501
501
|
return data;
|
|
502
502
|
}
|
|
503
503
|
|
|
504
|
+
function _workspace() {
|
|
505
|
+
const data = require("./workspace.aspect");
|
|
506
|
+
|
|
507
|
+
_workspace = function () {
|
|
508
|
+
return data;
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
return data;
|
|
512
|
+
}
|
|
513
|
+
|
|
504
514
|
/* eslint-disable max-lines */
|
|
505
515
|
const AspectSpecificField = '__specific';
|
|
506
516
|
exports.AspectSpecificField = AspectSpecificField;
|
|
@@ -1588,6 +1598,47 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
|
|
|
1588
1598
|
await func(components, watchOpts);
|
|
1589
1599
|
});
|
|
1590
1600
|
}
|
|
1601
|
+
/**
|
|
1602
|
+
* filter the given component-ids and set default-scope only to the new ones.
|
|
1603
|
+
* returns the affected components.
|
|
1604
|
+
*/
|
|
1605
|
+
|
|
1606
|
+
|
|
1607
|
+
async setDefaultScopeToComponents(componentIds, scopeName) {
|
|
1608
|
+
if (!(0, _legacyBitId().isValidScopeName)(scopeName)) {
|
|
1609
|
+
throw new (_legacyBitId().InvalidScopeName)(scopeName);
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
const newComponentIds = componentIds.filter(id => !id.hasVersion());
|
|
1613
|
+
|
|
1614
|
+
if (!newComponentIds.length) {
|
|
1615
|
+
const compIdsStr = componentIds.map(compId => compId.toString()).join(', ');
|
|
1616
|
+
throw new (_bitError().BitError)(`unable to set default-scope for the following components, as they are not new:\n${compIdsStr}`);
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
newComponentIds.map(comp => this.bitMap.setDefaultScope(comp, scopeName));
|
|
1620
|
+
await this.bitMap.write();
|
|
1621
|
+
return newComponentIds;
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
async setDefaultScope(scopeName) {
|
|
1625
|
+
var _config$workspaceConf, _config$workspaceConf2;
|
|
1626
|
+
|
|
1627
|
+
if (this.defaultScope === scopeName) {
|
|
1628
|
+
throw new Error(`the default-scope is already set as "${scopeName}", nothing to change`);
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
const config = this.harmony.get('teambit.harmony/config');
|
|
1632
|
+
(_config$workspaceConf = config.workspaceConfig) === null || _config$workspaceConf === void 0 ? void 0 : _config$workspaceConf.setExtension(_workspace().WorkspaceAspect.id, {
|
|
1633
|
+
defaultScope: scopeName
|
|
1634
|
+
}, {
|
|
1635
|
+
mergeIntoExisting: true,
|
|
1636
|
+
ignoreVersion: true
|
|
1637
|
+
});
|
|
1638
|
+
await ((_config$workspaceConf2 = config.workspaceConfig) === null || _config$workspaceConf2 === void 0 ? void 0 : _config$workspaceConf2.write({
|
|
1639
|
+
dir: _path().default.dirname(config.workspaceConfig.path)
|
|
1640
|
+
}));
|
|
1641
|
+
}
|
|
1591
1642
|
|
|
1592
1643
|
async addSpecificComponentConfig(id, aspectId, config = {}) {
|
|
1593
1644
|
const componentConfigFile = await this.componentConfigFile(id);
|
|
@@ -2285,10 +2336,10 @@ needed-for: ${(neededFor === null || neededFor === void 0 ? void 0 : neededFor.t
|
|
|
2285
2336
|
return await this.importAndGetMany(componentIds);
|
|
2286
2337
|
} catch (err) {
|
|
2287
2338
|
if (err instanceof _exceptions2().ComponentNotFound) {
|
|
2288
|
-
var _config$
|
|
2339
|
+
var _config$workspaceConf3;
|
|
2289
2340
|
|
|
2290
2341
|
const config = this.harmony.get('teambit.harmony/config');
|
|
2291
|
-
const configStr = JSON.stringify(((_config$
|
|
2342
|
+
const configStr = JSON.stringify(((_config$workspaceConf3 = config.workspaceConfig) === null || _config$workspaceConf3 === void 0 ? void 0 : _config$workspaceConf3.raw) || {});
|
|
2292
2343
|
|
|
2293
2344
|
if (configStr.includes(err.id)) {
|
|
2294
2345
|
throw new (_bitError().BitError)(`error: a component "${err.id}" was not found
|