@teambit/compositions 0.0.522 → 0.0.526

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/composition.ts CHANGED
@@ -3,6 +3,7 @@ import { humanizeCompositionId } from '@teambit/compositions.model.composition-i
3
3
  export type CompositionProps = {
4
4
  identifier: string;
5
5
  filepath?: string;
6
+ displayName?: string;
6
7
  };
7
8
 
8
9
  export class Composition {
@@ -15,23 +16,29 @@ export class Composition {
15
16
  /**
16
17
  * file path in which the composition is contained.
17
18
  */
18
- readonly filepath?: string
19
+ readonly filepath?: string,
20
+
21
+ /**
22
+ * set explicit display name
23
+ */
24
+ private _displayName?: string
19
25
  ) {}
20
26
 
21
27
  get displayName() {
22
- return humanizeCompositionId(this.identifier);
28
+ return this._displayName || humanizeCompositionId(this.identifier);
23
29
  }
24
30
 
25
31
  toObject() {
26
32
  return {
27
33
  identifier: this.identifier,
28
34
  filepath: this.filepath,
35
+ displayName: this._displayName,
29
36
  };
30
37
  }
31
38
 
32
39
  static fromArray(compositions: CompositionProps[]): Composition[] {
33
40
  return compositions.map((composition) => {
34
- return new Composition(composition.identifier, composition.filepath);
41
+ return new Composition(composition.identifier, composition.filepath, composition.displayName);
35
42
  });
36
43
  }
37
44
  }
@@ -18,6 +18,7 @@ export function compositionsSchema(compositions: CompositionsMain): Schema {
18
18
  type Composition {
19
19
  filepath: String
20
20
  identifier: String
21
+ displayName: String
21
22
  }
22
23
  `,
23
24
  resolvers: {
@@ -118,7 +118,13 @@ export class CompositionsMain {
118
118
 
119
119
  const module = this.schema.parseModule(join(this.workspace.componentDir(component.id), file.relative));
120
120
  return module.exports.map((exportModel) => {
121
- return new Composition(exportModel.identifier, file.relative);
121
+ const displayName = exportModel.staticProperties?.get('compositionName');
122
+
123
+ return new Composition(
124
+ exportModel.identifier,
125
+ file.relative,
126
+ typeof displayName === 'string' ? displayName : undefined
127
+ );
122
128
  });
123
129
  }
124
130
 
@@ -1,15 +1,18 @@
1
1
  export declare type CompositionProps = {
2
2
  identifier: string;
3
3
  filepath?: string;
4
+ displayName?: string;
4
5
  };
5
6
  export declare class Composition {
6
7
  readonly identifier: string;
7
8
  readonly filepath?: string | undefined;
8
- constructor(identifier: string, filepath?: string | undefined);
9
+ private _displayName?;
10
+ constructor(identifier: string, filepath?: string | undefined, _displayName?: string | undefined);
9
11
  get displayName(): string;
10
12
  toObject(): {
11
13
  identifier: string;
12
14
  filepath: string | undefined;
15
+ displayName: string | undefined;
13
16
  };
14
17
  static fromArray(compositions: CompositionProps[]): Composition[];
15
18
  }
@@ -24,25 +24,31 @@ class Composition {
24
24
  /**
25
25
  * file path in which the composition is contained.
26
26
  */
27
- filepath) {
27
+ filepath,
28
+ /**
29
+ * set explicit display name
30
+ */
31
+ _displayName) {
28
32
  this.identifier = identifier;
29
33
  this.filepath = filepath;
34
+ this._displayName = _displayName;
30
35
  }
31
36
 
32
37
  get displayName() {
33
- return (0, _compositionsModel().humanizeCompositionId)(this.identifier);
38
+ return this._displayName || (0, _compositionsModel().humanizeCompositionId)(this.identifier);
34
39
  }
35
40
 
36
41
  toObject() {
37
42
  return {
38
43
  identifier: this.identifier,
39
- filepath: this.filepath
44
+ filepath: this.filepath,
45
+ displayName: this._displayName
40
46
  };
41
47
  }
42
48
 
43
49
  static fromArray(compositions) {
44
50
  return compositions.map(composition => {
45
- return new Composition(composition.identifier, composition.filepath);
51
+ return new Composition(composition.identifier, composition.filepath, composition.displayName);
46
52
  });
47
53
  }
48
54
 
@@ -1 +1 @@
1
- {"version":3,"sources":["composition.ts"],"names":["Composition","constructor","identifier","filepath","displayName","toObject","fromArray","compositions","map","composition"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAOO,MAAMA,WAAN,CAAkB;AACvBC,EAAAA,WAAW;AACT;AACJ;AACA;AACaC,EAAAA,UAJA;AAMT;AACJ;AACA;AACaC,EAAAA,QATA,EAUT;AAAA,SANSD,UAMT,GANSA,UAMT;AAAA,SADSC,QACT,GADSA,QACT;AAAE;;AAEW,MAAXC,WAAW,GAAG;AAChB,WAAO,gDAAsB,KAAKF,UAA3B,CAAP;AACD;;AAEDG,EAAAA,QAAQ,GAAG;AACT,WAAO;AACLH,MAAAA,UAAU,EAAE,KAAKA,UADZ;AAELC,MAAAA,QAAQ,EAAE,KAAKA;AAFV,KAAP;AAID;;AAEe,SAATG,SAAS,CAACC,YAAD,EAAkD;AAChE,WAAOA,YAAY,CAACC,GAAb,CAAkBC,WAAD,IAAiB;AACvC,aAAO,IAAIT,WAAJ,CAAgBS,WAAW,CAACP,UAA5B,EAAwCO,WAAW,CAACN,QAApD,CAAP;AACD,KAFM,CAAP;AAGD;;AA5BsB","sourcesContent":["import { humanizeCompositionId } from '@teambit/compositions.model.composition-id';\n\nexport type CompositionProps = {\n identifier: string;\n filepath?: string;\n};\n\nexport class Composition {\n constructor(\n /**\n * identifier of the composition\n */\n readonly identifier: string,\n\n /**\n * file path in which the composition is contained.\n */\n readonly filepath?: string\n ) {}\n\n get displayName() {\n return humanizeCompositionId(this.identifier);\n }\n\n toObject() {\n return {\n identifier: this.identifier,\n filepath: this.filepath,\n };\n }\n\n static fromArray(compositions: CompositionProps[]): Composition[] {\n return compositions.map((composition) => {\n return new Composition(composition.identifier, composition.filepath);\n });\n }\n}\n"]}
1
+ {"version":3,"sources":["composition.ts"],"names":["Composition","constructor","identifier","filepath","_displayName","displayName","toObject","fromArray","compositions","map","composition"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAQO,MAAMA,WAAN,CAAkB;AACvBC,EAAAA,WAAW;AACT;AACJ;AACA;AACaC,EAAAA,UAJA;AAMT;AACJ;AACA;AACaC,EAAAA,QATA;AAWT;AACJ;AACA;AACYC,EAAAA,YAdC,EAeT;AAAA,SAXSF,UAWT,GAXSA,UAWT;AAAA,SANSC,QAMT,GANSA,QAMT;AAAA,SADQC,YACR,GADQA,YACR;AAAE;;AAEW,MAAXC,WAAW,GAAG;AAChB,WAAO,KAAKD,YAAL,IAAqB,gDAAsB,KAAKF,UAA3B,CAA5B;AACD;;AAEDI,EAAAA,QAAQ,GAAG;AACT,WAAO;AACLJ,MAAAA,UAAU,EAAE,KAAKA,UADZ;AAELC,MAAAA,QAAQ,EAAE,KAAKA,QAFV;AAGLE,MAAAA,WAAW,EAAE,KAAKD;AAHb,KAAP;AAKD;;AAEe,SAATG,SAAS,CAACC,YAAD,EAAkD;AAChE,WAAOA,YAAY,CAACC,GAAb,CAAkBC,WAAD,IAAiB;AACvC,aAAO,IAAIV,WAAJ,CAAgBU,WAAW,CAACR,UAA5B,EAAwCQ,WAAW,CAACP,QAApD,EAA8DO,WAAW,CAACL,WAA1E,CAAP;AACD,KAFM,CAAP;AAGD;;AAlCsB","sourcesContent":["import { humanizeCompositionId } from '@teambit/compositions.model.composition-id';\n\nexport type CompositionProps = {\n identifier: string;\n filepath?: string;\n displayName?: string;\n};\n\nexport class Composition {\n constructor(\n /**\n * identifier of the composition\n */\n readonly identifier: string,\n\n /**\n * file path in which the composition is contained.\n */\n readonly filepath?: string,\n\n /**\n * set explicit display name\n */\n private _displayName?: string\n ) {}\n\n get displayName() {\n return this._displayName || humanizeCompositionId(this.identifier);\n }\n\n toObject() {\n return {\n identifier: this.identifier,\n filepath: this.filepath,\n displayName: this._displayName,\n };\n }\n\n static fromArray(compositions: CompositionProps[]): Composition[] {\n return compositions.map((composition) => {\n return new Composition(composition.identifier, composition.filepath, composition.displayName);\n });\n }\n}\n"]}
@@ -31,6 +31,7 @@ function compositionsSchema(compositions) {
31
31
  type Composition {
32
32
  filepath: String
33
33
  identifier: String
34
+ displayName: String
34
35
  }
35
36
  `,
36
37
  resolvers: {
@@ -1 +1 @@
1
- {"version":3,"sources":["compositions.graphql.ts"],"names":["compositionsSchema","compositions","typeDefs","resolvers","Component","component","getCompositions"],"mappings":";;;;;;;;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIO,SAASA,kBAAT,CAA4BC,YAA5B,EAAoE;AACzE,SAAO;AACLC,IAAAA,QAAQ,EAAE,0BAAI;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAdS;AAeLC,IAAAA,SAAS,EAAE;AACTC,MAAAA,SAAS,EAAE;AACTH,QAAAA,YAAY,EAAGI,SAAD,IAA0B;AACtC,iBAAOJ,YAAY,CAACK,eAAb,CAA6BD,SAA7B,CAAP;AACD;AAHQ;AADF;AAfN,GAAP;AAuBD","sourcesContent":["import { Component } from '@teambit/component';\nimport { Schema } from '@teambit/graphql';\nimport gql from 'graphql-tag';\n\nimport { CompositionsMain } from './compositions.main.runtime';\n\nexport function compositionsSchema(compositions: CompositionsMain): Schema {\n return {\n typeDefs: gql`\n extend type Component {\n compositions: [Composition]\n }\n\n type Subscription {\n compositionAdded: Composition\n }\n\n type Composition {\n filepath: String\n identifier: String\n }\n `,\n resolvers: {\n Component: {\n compositions: (component: Component) => {\n return compositions.getCompositions(component);\n },\n },\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["compositions.graphql.ts"],"names":["compositionsSchema","compositions","typeDefs","resolvers","Component","component","getCompositions"],"mappings":";;;;;;;;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIO,SAASA,kBAAT,CAA4BC,YAA5B,EAAoE;AACzE,SAAO;AACLC,IAAAA,QAAQ,EAAE,0BAAI;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAfS;AAgBLC,IAAAA,SAAS,EAAE;AACTC,MAAAA,SAAS,EAAE;AACTH,QAAAA,YAAY,EAAGI,SAAD,IAA0B;AACtC,iBAAOJ,YAAY,CAACK,eAAb,CAA6BD,SAA7B,CAAP;AACD;AAHQ;AADF;AAhBN,GAAP;AAwBD","sourcesContent":["import { Component } from '@teambit/component';\nimport { Schema } from '@teambit/graphql';\nimport gql from 'graphql-tag';\n\nimport { CompositionsMain } from './compositions.main.runtime';\n\nexport function compositionsSchema(compositions: CompositionsMain): Schema {\n return {\n typeDefs: gql`\n extend type Component {\n compositions: [Composition]\n }\n\n type Subscription {\n compositionAdded: Composition\n }\n\n type Composition {\n filepath: String\n identifier: String\n displayName: String\n }\n `,\n resolvers: {\n Component: {\n compositions: (component: Component) => {\n return compositions.getCompositions(component);\n },\n },\n },\n };\n}\n"]}
@@ -239,7 +239,10 @@ class CompositionsMain {
239
239
  pathArray[pathArray.length - 1] = 'js';
240
240
  const module = this.schema.parseModule((0, _path().join)(this.workspace.componentDir(component.id), file.relative));
241
241
  return module.exports.map(exportModel => {
242
- return new (_composition().Composition)(exportModel.identifier, file.relative);
242
+ var _exportModel$staticPr;
243
+
244
+ const displayName = (_exportModel$staticPr = exportModel.staticProperties) === null || _exportModel$staticPr === void 0 ? void 0 : _exportModel$staticPr.get('compositionName');
245
+ return new (_composition().Composition)(exportModel.identifier, file.relative, typeof displayName === 'string' ? displayName : undefined);
243
246
  });
244
247
  }
245
248
 
@@ -1 +1 @@
1
- {"version":3,"sources":["compositions.main.runtime.ts"],"names":["CompositionsMain","constructor","compositionFilePattern","previewFilePattern","preview","workspace","schema","devFiles","getPreviewFiles","components","ComponentMap","as","component","compositionFiles","state","filesystem","byGlob","previewFiles","Set","map","file","relative","files","filter","has","getCompositions","entry","aspects","get","CompositionsAspect","id","compositions","data","Composition","fromArray","readCompositions","maybeFiles","byComponent","computeCompositions","onComponentLoad","composition","toObject","pathArray","path","split","length","module","parseModule","componentDir","exports","exportModel","identifier","provider","graphql","config","compositionPreviewFilePattern","registerDevPattern","register","registerDefinition","CompositionPreviewDefinition","bind","MainRuntime","PreviewAspect","GraphqlAspect","WorkspaceAspect","SchemaAspect","DevFilesAspect","ComponentAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;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AJ,EAAe;AACbA,MAAAA,SAAS,CAACkC,eAAV,CAA0BR,YAAY,CAACQ,eAAb,CAA6BqB,IAA7B,CAAkC7B,YAAlC,CAA1B;AACD;;AAED,WAAOA,YAAP;AACD;;AA3H2B;;;gCAAjB/B,gB,mBA6FgC;AACzCE,EAAAA,sBAAsB,EAAE,CAAC,wBAAD,CADiB;AAEzCqD,EAAAA,6BAA6B,EAAE,CAAC,iBAAD;AAFU,C;gCA7FhCvD,gB,aAkGM6D,kB;gCAlGN7D,gB,kBAmGW,CAAC8D,wBAAD,EAAgBC,wBAAhB,EAA+BC,4BAA/B,EAAgDC,sBAAhD,EAA8DC,0BAA9D,EAA8EC,4BAA9E,C;;AA2BxBtC,mCAAmBuC,UAAnB,CAA8BpE,gBAA9B","sourcesContent":["import { join } from 'path';\nimport { MainRuntime } from '@teambit/cli';\nimport { Component, ComponentAspect, ComponentMap, AspectData } from '@teambit/component';\nimport { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { PreviewAspect, PreviewMain } from '@teambit/preview';\nimport { SchemaAspect, SchemaMain } from '@teambit/schema';\nimport { Workspace, WorkspaceAspect } from '@teambit/workspace';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { flatten } from '@teambit/legacy/dist/utils';\nimport { DevFilesAspect, DevFilesMain } from '@teambit/dev-files';\nimport { Composition } from './composition';\nimport { CompositionsAspect } from './compositions.aspect';\nimport { compositionsSchema } from './compositions.graphql';\nimport { CompositionPreviewDefinition } from './compositions.preview-definition';\n\nexport type CompositionsConfig = {\n /**\n * glob pattern to detect composition files. This includes all related files, like styles and jsons.\n * @example ['/*.composition?(s).*']\n */\n compositionFilePattern: string[];\n /**\n * glob pattern to select Preview files. this will only include files matched by compositionFilePattern.\n * @example ['*.{t,j}s', '*.{t,j}sx']\n */\n compositionPreviewFilePattern: string[];\n};\n\n/**\n * the component documentation extension.\n */\nexport class CompositionsMain {\n constructor(\n /**\n * Glob pattern to select all composition files\n */\n private compositionFilePattern: string[],\n\n /**\n * Glob pattern to select composition preview files\n */\n private previewFilePattern: string[],\n\n /**\n * envs extension.\n */\n private preview: PreviewMain,\n\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * schema extension.\n */\n private schema: SchemaMain,\n\n private devFiles: DevFilesMain\n ) {}\n\n /**\n * returns an array of doc file paths for a set of components.\n */\n getPreviewFiles(components: Component[]): ComponentMap<AbstractVinyl[]> {\n return ComponentMap.as<AbstractVinyl[]>(components, (component) => {\n // this includes non executables, like `button.compositions.module.scss` or `presets.compositions.json`\n const compositionFiles = component.state.filesystem.byGlob(this.compositionFilePattern);\n\n // select only relevant preview files (.tsx, etc)\n const previewFiles = new Set(\n component.state.filesystem.byGlob(this.previewFilePattern).map((file) => file.relative)\n );\n const files = compositionFiles.filter((file) => previewFiles.has(file.relative));\n\n return files;\n });\n }\n\n /**\n * get component compositions.\n */\n getCompositions(component: Component): Composition[] {\n const entry = component.state.aspects.get(CompositionsAspect.id);\n if (!entry) return [];\n const compositions = entry.data.compositions;\n if (!compositions) return [];\n\n return Composition.fromArray(compositions);\n }\n\n /**\n * read composition from the component source code.\n */\n readCompositions(component: Component): Composition[] {\n const maybeFiles = this.getPreviewFiles([component]).byComponent(component);\n\n if (!maybeFiles) return [];\n const [, files] = maybeFiles;\n return flatten(\n files.map((file) => {\n return this.computeCompositions(component, file);\n })\n );\n }\n\n async onComponentLoad(component: Component): Promise<AspectData> {\n const compositions = this.readCompositions(component);\n return {\n compositions: compositions.map((composition) => composition.toObject()),\n };\n }\n\n private computeCompositions(component: Component, file: AbstractVinyl): Composition[] {\n // :TODO hacked for a specific file extension now until david will take care in the compiler.\n const pathArray = file.path.split('.');\n pathArray[pathArray.length - 1] = 'js';\n\n const module = this.schema.parseModule(join(this.workspace.componentDir(component.id), file.relative));\n return module.exports.map((exportModel) => {\n return new Composition(exportModel.identifier, file.relative);\n });\n }\n\n static defaultConfig: CompositionsConfig = {\n compositionFilePattern: ['**/*.composition?(s).*'],\n compositionPreviewFilePattern: ['**/*.{t,j}s?(x)'],\n };\n\n static runtime = MainRuntime;\n static dependencies = [PreviewAspect, GraphqlAspect, WorkspaceAspect, SchemaAspect, DevFilesAspect, ComponentAspect];\n\n static async provider(\n [preview, graphql, workspace, schema, devFiles]: [PreviewMain, GraphqlMain, Workspace, SchemaMain, DevFilesMain],\n config: CompositionsConfig\n ) {\n const compositions = new CompositionsMain(\n config.compositionFilePattern,\n config.compositionPreviewFilePattern,\n preview,\n workspace,\n schema,\n devFiles\n );\n devFiles.registerDevPattern(config.compositionFilePattern);\n\n graphql.register(compositionsSchema(compositions));\n preview.registerDefinition(new CompositionPreviewDefinition(compositions));\n\n if (workspace) {\n workspace.onComponentLoad(compositions.onComponentLoad.bind(compositions));\n }\n\n return compositions;\n }\n}\n\nCompositionsAspect.addRuntime(CompositionsMain);\n"]}
1
+ {"version":3,"sources":["compositions.main.runtime.ts"],"names":["CompositionsMain","constructor","compositionFilePattern","previewFilePattern","preview","workspace","schema","devFiles","getPreviewFiles","components","ComponentMap","as","component","compositionFiles","state","filesystem","byGlob","previewFiles","Set","map","file","relative","files","filter","has","getCompositions","entry","aspects","get","CompositionsAspect","id","compositions","data","Composition","fromArray","readCompositions","maybeFiles","byComponent","computeCompositions","onComponentLoad","composition","toObject","pathArray","path","split","length","module","parseModule","componentDir","exports","exportModel","displayName","staticProperties","identifier","undefined","provider","graphql","config","compositionPreviewFilePattern","registerDevPattern","register","registerDefinition","CompositionPreviewDefinition","bind","MainRuntime","PreviewAspect","GraphqlAspect","WorkspaceAspect","SchemaAspect","DevFilesAspect","ComponentAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAA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AIC,6CAAJ,EAAiC/B,YAAjC,CAA3B;;AAEA,QAAI1B,SAAJ,EAAe;AACbA,MAAAA,SAAS,CAACkC,eAAV,CAA0BR,YAAY,CAACQ,eAAb,CAA6BwB,IAA7B,CAAkChC,YAAlC,CAA1B;AACD;;AAED,WAAOA,YAAP;AACD;;AAjI2B;;;gCAAjB/B,gB,mBAmGgC;AACzCE,EAAAA,sBAAsB,EAAE,CAAC,wBAAD,CADiB;AAEzCwD,EAAAA,6BAA6B,EAAE,CAAC,iBAAD;AAFU,C;gCAnGhC1D,gB,aAwGMgE,kB;gCAxGNhE,gB,kBAyGW,CAACiE,wBAAD,EAAgBC,wBAAhB,EAA+BC,4BAA/B,EAAgDC,sBAAhD,EAA8DC,0BAA9D,EAA8EC,4BAA9E,C;;AA2BxBzC,mCAAmB0C,UAAnB,CAA8BvE,gBAA9B","sourcesContent":["import { join } from 'path';\nimport { MainRuntime } from '@teambit/cli';\nimport { Component, ComponentAspect, ComponentMap, AspectData } from '@teambit/component';\nimport { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { PreviewAspect, PreviewMain } from '@teambit/preview';\nimport { SchemaAspect, SchemaMain } from '@teambit/schema';\nimport { Workspace, WorkspaceAspect } from '@teambit/workspace';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { flatten } from '@teambit/legacy/dist/utils';\nimport { DevFilesAspect, DevFilesMain } from '@teambit/dev-files';\nimport { Composition } from './composition';\nimport { CompositionsAspect } from './compositions.aspect';\nimport { compositionsSchema } from './compositions.graphql';\nimport { CompositionPreviewDefinition } from './compositions.preview-definition';\n\nexport type CompositionsConfig = {\n /**\n * glob pattern to detect composition files. This includes all related files, like styles and jsons.\n * @example ['/*.composition?(s).*']\n */\n compositionFilePattern: string[];\n /**\n * glob pattern to select Preview files. this will only include files matched by compositionFilePattern.\n * @example ['*.{t,j}s', '*.{t,j}sx']\n */\n compositionPreviewFilePattern: string[];\n};\n\n/**\n * the component documentation extension.\n */\nexport class CompositionsMain {\n constructor(\n /**\n * Glob pattern to select all composition files\n */\n private compositionFilePattern: string[],\n\n /**\n * Glob pattern to select composition preview files\n */\n private previewFilePattern: string[],\n\n /**\n * envs extension.\n */\n private preview: PreviewMain,\n\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * schema extension.\n */\n private schema: SchemaMain,\n\n private devFiles: DevFilesMain\n ) {}\n\n /**\n * returns an array of doc file paths for a set of components.\n */\n getPreviewFiles(components: Component[]): ComponentMap<AbstractVinyl[]> {\n return ComponentMap.as<AbstractVinyl[]>(components, (component) => {\n // this includes non executables, like `button.compositions.module.scss` or `presets.compositions.json`\n const compositionFiles = component.state.filesystem.byGlob(this.compositionFilePattern);\n\n // select only relevant preview files (.tsx, etc)\n const previewFiles = new Set(\n component.state.filesystem.byGlob(this.previewFilePattern).map((file) => file.relative)\n );\n const files = compositionFiles.filter((file) => previewFiles.has(file.relative));\n\n return files;\n });\n }\n\n /**\n * get component compositions.\n */\n getCompositions(component: Component): Composition[] {\n const entry = component.state.aspects.get(CompositionsAspect.id);\n if (!entry) return [];\n const compositions = entry.data.compositions;\n if (!compositions) return [];\n\n return Composition.fromArray(compositions);\n }\n\n /**\n * read composition from the component source code.\n */\n readCompositions(component: Component): Composition[] {\n const maybeFiles = this.getPreviewFiles([component]).byComponent(component);\n\n if (!maybeFiles) return [];\n const [, files] = maybeFiles;\n return flatten(\n files.map((file) => {\n return this.computeCompositions(component, file);\n })\n );\n }\n\n async onComponentLoad(component: Component): Promise<AspectData> {\n const compositions = this.readCompositions(component);\n return {\n compositions: compositions.map((composition) => composition.toObject()),\n };\n }\n\n private computeCompositions(component: Component, file: AbstractVinyl): Composition[] {\n // :TODO hacked for a specific file extension now until david will take care in the compiler.\n const pathArray = file.path.split('.');\n pathArray[pathArray.length - 1] = 'js';\n\n const module = this.schema.parseModule(join(this.workspace.componentDir(component.id), file.relative));\n return module.exports.map((exportModel) => {\n const displayName = exportModel.staticProperties?.get('compositionName');\n\n return new Composition(\n exportModel.identifier,\n file.relative,\n typeof displayName === 'string' ? displayName : undefined\n );\n });\n }\n\n static defaultConfig: CompositionsConfig = {\n compositionFilePattern: ['**/*.composition?(s).*'],\n compositionPreviewFilePattern: ['**/*.{t,j}s?(x)'],\n };\n\n static runtime = MainRuntime;\n static dependencies = [PreviewAspect, GraphqlAspect, WorkspaceAspect, SchemaAspect, DevFilesAspect, ComponentAspect];\n\n static async provider(\n [preview, graphql, workspace, schema, devFiles]: [PreviewMain, GraphqlMain, Workspace, SchemaMain, DevFilesMain],\n config: CompositionsConfig\n ) {\n const compositions = new CompositionsMain(\n config.compositionFilePattern,\n config.compositionPreviewFilePattern,\n preview,\n workspace,\n schema,\n devFiles\n );\n devFiles.registerDevPattern(config.compositionFilePattern);\n\n graphql.register(compositionsSchema(compositions));\n preview.registerDefinition(new CompositionPreviewDefinition(compositions));\n\n if (workspace) {\n workspace.onComponentLoad(compositions.onComponentLoad.bind(compositions));\n }\n\n return compositions;\n }\n}\n\nCompositionsAspect.addRuntime(CompositionsMain);\n"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/compositions",
3
- "version": "0.0.522",
3
+ "version": "0.0.526",
4
4
  "homepage": "https://bit.dev/teambit/compositions/compositions",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.compositions",
8
8
  "name": "compositions",
9
- "version": "0.0.522"
9
+ "version": "0.0.526"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
@@ -23,32 +23,32 @@
23
23
  "@teambit/documenter.ui.heading": "4.1.1",
24
24
  "@teambit/documenter.ui.property-table": "4.1.3",
25
25
  "@teambit/evangelist.elements.icon": "1.0.2",
26
- "@teambit/component": "0.0.522",
27
- "@teambit/compositions.model.composition-id": "0.0.445",
28
- "@teambit/graphql": "0.0.522",
29
- "@teambit/cli": "0.0.379",
30
- "@teambit/dev-files": "0.0.522",
31
- "@teambit/preview": "0.0.522",
32
- "@teambit/schema": "0.0.522",
33
- "@teambit/workspace": "0.0.522",
34
- "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.445",
35
- "@teambit/envs": "0.0.522",
36
- "@teambit/compositions.ui.compositions-menu-bar": "0.0.122",
37
- "@teambit/compositions.ui.hooks.use-composition": "0.0.122",
38
- "@teambit/design.ui.alert-card": "0.0.12",
39
- "@teambit/design.ui.empty-box": "0.0.351",
40
- "@teambit/design.ui.input.option-button": "0.0.25",
41
- "@teambit/design.ui.separator": "0.0.350",
42
- "@teambit/design.ui.surfaces.status-message-card": "0.0.5",
43
- "@teambit/docs.ui.queries.get-docs": "0.0.445",
44
- "@teambit/mdx.ui.mdx-layout": "0.0.447",
45
- "@teambit/panels": "0.0.379",
46
- "@teambit/preview.ui.component-preview": "0.0.445",
47
- "@teambit/ui-foundation.ui.buttons.collapser": "0.0.150",
48
- "@teambit/ui-foundation.ui.hooks.use-is-mobile": "0.0.138",
49
- "@teambit/ui": "0.0.522",
50
- "@teambit/compositions.model.composition-type": "0.0.445",
51
- "@teambit/compositions.ui.composition-card": "0.0.449"
26
+ "@teambit/component": "0.0.526",
27
+ "@teambit/compositions.model.composition-id": "0.0.447",
28
+ "@teambit/graphql": "0.0.526",
29
+ "@teambit/cli": "0.0.380",
30
+ "@teambit/dev-files": "0.0.526",
31
+ "@teambit/preview": "0.0.526",
32
+ "@teambit/schema": "0.0.526",
33
+ "@teambit/workspace": "0.0.526",
34
+ "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.447",
35
+ "@teambit/envs": "0.0.526",
36
+ "@teambit/compositions.ui.compositions-menu-bar": "0.0.124",
37
+ "@teambit/compositions.ui.hooks.use-composition": "0.0.124",
38
+ "@teambit/design.ui.alert-card": "0.0.13",
39
+ "@teambit/design.ui.empty-box": "0.0.352",
40
+ "@teambit/design.ui.input.option-button": "0.0.26",
41
+ "@teambit/design.ui.separator": "0.0.351",
42
+ "@teambit/design.ui.surfaces.status-message-card": "0.0.6",
43
+ "@teambit/docs.ui.queries.get-docs": "0.0.447",
44
+ "@teambit/mdx.ui.mdx-layout": "0.0.450",
45
+ "@teambit/panels": "0.0.380",
46
+ "@teambit/preview.ui.component-preview": "0.0.447",
47
+ "@teambit/ui-foundation.ui.buttons.collapser": "0.0.152",
48
+ "@teambit/ui-foundation.ui.hooks.use-is-mobile": "0.0.140",
49
+ "@teambit/ui": "0.0.526",
50
+ "@teambit/compositions.model.composition-type": "0.0.448",
51
+ "@teambit/compositions.ui.composition-card": "0.0.452"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/react": "^17.0.8",
@@ -59,14 +59,14 @@
59
59
  "@types/jest": "^26.0.0",
60
60
  "@types/react-dom": "^17.0.5",
61
61
  "@types/node": "12.20.4",
62
- "@teambit/compositions.aspect-docs.compositions": "0.0.85"
62
+ "@teambit/compositions.aspect-docs.compositions": "0.0.88"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "@teambit/legacy": "1.0.76",
66
66
  "react-dom": "^16.8.0 || ^17.0.0",
67
67
  "react": "^16.8.0 || ^17.0.0"
68
68
  },
69
- "license": "SEE LICENSE IN LICENSE",
69
+ "license": "Apache-2.0",
70
70
  "bit": {
71
71
  "bindingPrefix": "@teambit",
72
72
  "env": {},