@teambit/docs 1.0.108 → 1.0.109

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.
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.docs_docs@1.0.108/dist/docs.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.docs_docs@1.0.108/dist/docs.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.docs_docs@1.0.109/dist/docs.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.docs_docs@1.0.109/dist/docs.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/docs",
3
- "version": "1.0.108",
3
+ "version": "1.0.109",
4
4
  "homepage": "https://bit.cloud/teambit/docs/docs",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.docs",
8
8
  "name": "docs",
9
- "version": "1.0.108"
9
+ "version": "1.0.109"
10
10
  },
11
11
  "dependencies": {
12
12
  "graphql-tag": "2.12.1",
@@ -18,20 +18,20 @@
18
18
  "@teambit/docs.ui.overview-compare": "1.0.10",
19
19
  "@teambit/component.ui.component-meta": "0.0.358",
20
20
  "@teambit/base-ui.loaders.skeleton": "1.0.1",
21
- "@teambit/compiler": "1.0.108",
22
- "@teambit/component": "1.0.108",
23
- "@teambit/pkg": "1.0.108",
24
- "@teambit/workspace": "1.0.108",
25
- "@teambit/cli": "0.0.840",
26
- "@teambit/dev-files": "1.0.108",
27
- "@teambit/envs": "1.0.108",
28
- "@teambit/graphql": "1.0.108",
29
- "@teambit/logger": "0.0.933",
30
- "@teambit/preview": "1.0.108",
31
- "@teambit/scope": "1.0.108",
32
- "@teambit/component-compare": "1.0.108",
33
- "@teambit/ui": "1.0.108",
34
- "@teambit/pubsub": "1.0.108",
21
+ "@teambit/compiler": "1.0.109",
22
+ "@teambit/component": "1.0.109",
23
+ "@teambit/pkg": "1.0.109",
24
+ "@teambit/workspace": "1.0.109",
25
+ "@teambit/cli": "0.0.841",
26
+ "@teambit/dev-files": "1.0.109",
27
+ "@teambit/envs": "1.0.109",
28
+ "@teambit/graphql": "1.0.109",
29
+ "@teambit/logger": "0.0.934",
30
+ "@teambit/preview": "1.0.109",
31
+ "@teambit/scope": "1.0.109",
32
+ "@teambit/component-compare": "1.0.109",
33
+ "@teambit/ui": "1.0.109",
34
+ "@teambit/pubsub": "1.0.109",
35
35
  "@teambit/compositions.panels.composition-gallery": "0.0.202",
36
36
  "@teambit/react.ui.docs.properties-table": "0.0.22",
37
37
  "@teambit/preview.ui.component-preview": "1.0.3"
@@ -44,7 +44,7 @@
44
44
  "@types/testing-library__jest-dom": "^5.9.5",
45
45
  "@teambit/docs.content.docs-overview": "1.95.9",
46
46
  "@teambit/component-id": "1.2.0",
47
- "@teambit/harmony.envs.core-aspect-env": "0.0.13"
47
+ "@teambit/harmony.envs.core-aspect-env": "0.0.14"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "react": "^17.0.0 || ^18.0.0",
@@ -1,29 +0,0 @@
1
- import { resolve } from 'path';
2
- import type { PkgMain } from '@teambit/pkg';
3
- import type { Component } from '@teambit/component';
4
- import type { CompilerMain } from '@teambit/compiler';
5
- import type { Workspace } from '@teambit/workspace';
6
- import { Doc } from '@teambit/docs.entities.doc';
7
- import { DocReader } from './doc-reader';
8
-
9
- export class DefaultDocReader implements DocReader {
10
- constructor(private pkg: PkgMain, private compiler: CompilerMain, private workspace: Workspace) {}
11
-
12
- async read(path: string, contents: Buffer, component: Component) {
13
- const packageName = this.pkg.getPackageName(component);
14
- const distPath = this.compiler.getDistPathBySrcPath(component, path);
15
- // eslint-disable-next-line
16
- const docsModule = require(resolve(`${this.workspace.path}/node_modules/${packageName}/${distPath}`));
17
- return Doc.from(path, {
18
- labels: docsModule.labels || docsModule.default?.labels,
19
- description: docsModule.abstract || docsModule.default?.abstract || docsModule.description,
20
- displayName: docsModule.displayName || docsModule.default?.componentDisplayName,
21
- });
22
- }
23
-
24
- readonly supportedExtensions = ['.ts', '.js', '.jsx', '.tsx'];
25
-
26
- isFormatSupported(format: string) {
27
- return this.supportedExtensions.includes(format);
28
- }
29
- }
package/doc-module.ts DELETED
@@ -1,17 +0,0 @@
1
- export class DocModule {
2
- constructor(
3
- readonly path: string,
4
-
5
- /**
6
- * original doc module.
7
- */
8
- readonly module: any
9
- ) {}
10
-
11
- /**
12
- * get the abstract.
13
- */
14
- get abstract() {
15
- return this.module.abstract || this.module.default?.abstract;
16
- }
17
- }
package/doc-reader.ts DELETED
@@ -1,15 +0,0 @@
1
- import type { Component } from '@teambit/component';
2
- import { Doc } from '@teambit/docs.entities.doc';
3
-
4
- export interface DocReader {
5
- /**
6
- * read a component doc.
7
- * @TODO refactor to virtual-file component after @david completes.
8
- */
9
- read(path: string, contents: Buffer, component: Component): Promise<Doc>;
10
-
11
- /**
12
- * determine which file formats are supported by the doc reader.
13
- */
14
- isFormatSupported(ext: string): boolean;
15
- }
package/docs.aspect.ts DELETED
@@ -1,9 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const DocsAspect = Aspect.create({
4
- id: 'teambit.docs/docs',
5
- dependencies: [],
6
- defaultConfig: {},
7
- });
8
-
9
- export default DocsAspect;
package/docs.graphql.ts DELETED
@@ -1,26 +0,0 @@
1
- import gql from 'graphql-tag';
2
- import { Component } from '@teambit/component';
3
- import { DocsMain } from './docs.main.runtime';
4
-
5
- export function docsSchema(docs: DocsMain) {
6
- return {
7
- typeDefs: gql`
8
- extend type Component {
9
- description: String
10
- labels: [String]
11
- }
12
- `,
13
- resolvers: {
14
- Component: {
15
- description: (component: Component) => {
16
- return docs.getDescription(component);
17
- },
18
-
19
- labels: (component: Component) => {
20
- const doc = docs.getDoc(component);
21
- return doc?.labels || [];
22
- },
23
- },
24
- },
25
- };
26
- }
@@ -1,234 +0,0 @@
1
- import { Slot, SlotRegistry } from '@teambit/harmony';
2
- import { MainRuntime } from '@teambit/cli';
3
- import { LoggerAspect, LoggerMain, Logger } from '@teambit/logger';
4
- import { CompilerAspect, CompilerMain } from '@teambit/compiler';
5
- import { Component, ComponentMap, IComponent } from '@teambit/component';
6
- import ScopeAspect, { ScopeMain } from '@teambit/scope';
7
- import { PkgAspect, PkgMain } from '@teambit/pkg';
8
- import type { Environment } from '@teambit/envs';
9
- import { GraphqlAspect, GraphqlMain } from '@teambit/graphql';
10
- import { PreviewAspect, PreviewMain } from '@teambit/preview';
11
- import DevFilesAspect, { DevFilesMain } from '@teambit/dev-files';
12
- import { ComponentLoadOptions } from '@teambit/legacy/dist/consumer/component/component-loader';
13
- import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
14
- import { Workspace, WorkspaceAspect } from '@teambit/workspace';
15
- import { Doc, DocPropList } from '@teambit/docs.entities.doc';
16
- import { isFunction } from 'lodash';
17
- import { EnvsAspect, EnvsMain } from '@teambit/envs';
18
- import { DocsAspect } from './docs.aspect';
19
- import { DocsPreviewDefinition } from './docs.preview-definition';
20
- import { docsSchema } from './docs.graphql';
21
- import { DocReader } from './doc-reader';
22
- import { DefaultDocReader } from './default-doc-reader';
23
- import { FileExtensionNotSupported } from './exceptions';
24
-
25
- export type ComponentDocs = {
26
- files: string[];
27
- component: Component;
28
- };
29
-
30
- export type DocProp = {};
31
-
32
- export type DocPropSlot = SlotRegistry<DocProp>;
33
-
34
- export type DocReaderSlot = SlotRegistry<DocReader>;
35
-
36
- export type DocsConfig = {
37
- /**
38
- * glob patterns to identify doc files.
39
- */
40
- patterns: string[];
41
- };
42
-
43
- /**
44
- * the component documentation extension.
45
- */
46
- export class DocsMain {
47
- constructor(
48
- private patterns: string[],
49
- /**
50
- * envs extension.
51
- */
52
- private preview: PreviewMain,
53
-
54
- private pkg: PkgMain,
55
-
56
- private compiler: CompilerMain,
57
-
58
- private workspace: Workspace,
59
-
60
- private logger: Logger,
61
-
62
- private devFiles: DevFilesMain,
63
-
64
- private envs: EnvsMain,
65
-
66
- private docPropSlot: DocPropSlot,
67
-
68
- private docReaderSlot: DocReaderSlot
69
- ) {}
70
-
71
- /**
72
- * returns an array of doc file paths for a set of components.
73
- */
74
- getDocsMap(components: Component[]): ComponentMap<AbstractVinyl[]> {
75
- return ComponentMap.as<AbstractVinyl[]>(components, (component) => {
76
- return this.getDocsFiles(component);
77
- });
78
- }
79
-
80
- getDocsFiles(component: Component): AbstractVinyl[] {
81
- const devFiles = this.devFiles.getDevFiles(component);
82
- const docFiles = devFiles.get(DocsAspect.id);
83
- return component.state.filesystem.files.filter((file) => docFiles.includes(file.relative));
84
- }
85
-
86
- /**
87
- * compute the description of the component from its source code and docs file.
88
- */
89
- async getDescription(component: Component): Promise<string> {
90
- const componentDoc = this.getDoc(component);
91
- const desc = componentDoc?.description;
92
- return desc || '';
93
- }
94
-
95
- async getTemplate(env: Environment): Promise<string | undefined> {
96
- if (env.getDocsTemplate && isFunction(env.getDocsTemplate)) {
97
- return env.getDocsTemplate();
98
- }
99
- return undefined;
100
- }
101
-
102
- getDocReader(extension: string) {
103
- return this.docReaderSlot.values().find((docReader) => docReader.isFormatSupported(extension));
104
- }
105
-
106
- /**
107
- * compute a doc for a component.
108
- */
109
- async computeDoc(component: Component) {
110
- const docFiles = this.getDocsFiles(component);
111
- if (docFiles.length) {
112
- // currently taking the the first docs file found with an abstract. (we support only one)
113
- const docFile = docFiles[0];
114
-
115
- try {
116
- const docReader = this.getDocReader(docFile.extname);
117
- if (!docReader) throw new FileExtensionNotSupported(docFile.relative, docFile.extname);
118
- const doc = await docReader.read(docFile.relative, docFile.contents, component);
119
- return doc;
120
- } catch (err: any) {
121
- // it's ok to fail here.
122
- this.logger.debug(`docs.main.runtime.computeDoc caught an error: ${err.message}`);
123
- return null;
124
- }
125
- }
126
-
127
- return null;
128
- }
129
-
130
- getDoc(component: IComponent) {
131
- const docData = component.get(DocsAspect.id)?.data?.doc;
132
- if (!docData) return null;
133
- return new Doc(docData.filePath, new DocPropList(docData.props));
134
- }
135
-
136
- getPatterns() {
137
- return this.patterns;
138
- }
139
-
140
- getComponentDevPatterns(component: Component) {
141
- const env = this.envs.calculateEnv(component, { skipWarnings: !!this.workspace?.inInstallContext }).env;
142
- const componentEnvDocsDevPatterns: string[] = env.getDocsDevPatterns ? env.getDocsDevPatterns(component) : [];
143
- const componentPatterns = componentEnvDocsDevPatterns.concat(this.getPatterns());
144
- return { name: 'docs', pattern: componentPatterns };
145
- }
146
-
147
- getDevPatternToRegister() {
148
- return this.getComponentDevPatterns.bind(this);
149
- }
150
- /**
151
- * register a new doc reader. this allows to support further
152
- * documentation file formats.
153
- */
154
- registerDocReader(docReader: DocReader) {
155
- this.docReaderSlot.register(docReader);
156
- return this;
157
- }
158
-
159
- static slots = [Slot.withType<DocProp>(), Slot.withType<DocReader>()];
160
-
161
- static runtime = MainRuntime;
162
- static dependencies = [
163
- PreviewAspect,
164
- GraphqlAspect,
165
- WorkspaceAspect,
166
- PkgAspect,
167
- CompilerAspect,
168
- LoggerAspect,
169
- DevFilesAspect,
170
- EnvsAspect,
171
- ScopeAspect,
172
- ];
173
-
174
- static defaultConfig = {
175
- patterns: ['**/*.docs.*'],
176
- };
177
-
178
- static async provider(
179
- [preview, graphql, workspace, pkg, compiler, loggerAspect, devFiles, envs, scope]: [
180
- PreviewMain,
181
- GraphqlMain,
182
- Workspace,
183
- PkgMain,
184
- CompilerMain,
185
- LoggerMain,
186
- DevFilesMain,
187
- EnvsMain,
188
- ScopeMain
189
- ],
190
- config: DocsConfig,
191
- [docPropSlot, docReaderSlot]: [DocPropSlot, DocReaderSlot]
192
- ) {
193
- const logger = loggerAspect.createLogger(DocsAspect.id);
194
- const docs = new DocsMain(
195
- config.patterns,
196
- preview,
197
- pkg,
198
- compiler,
199
- workspace,
200
- logger,
201
- devFiles,
202
- envs,
203
- docPropSlot,
204
- docReaderSlot
205
- );
206
- docs.registerDocReader(new DefaultDocReader(pkg, compiler, workspace));
207
- devFiles.registerDevPattern(docs.getDevPatternToRegister());
208
-
209
- const computeDocsOnLoad = async (component: Component, opts?: ComponentLoadOptions) => {
210
- if (opts?.loadDocs === false) return undefined;
211
- // const docFiles = await docs.computeDocs(component);
212
- const doc = await docs.computeDoc(component);
213
-
214
- return {
215
- doc: doc?.toObject(),
216
- // docFiles
217
- };
218
- };
219
-
220
- if (workspace) {
221
- workspace.registerOnComponentLoad(computeDocsOnLoad);
222
- }
223
- if (scope) {
224
- scope.registerOnCompAspectReCalc(computeDocsOnLoad);
225
- }
226
-
227
- graphql.register(docsSchema(docs));
228
-
229
- preview.registerDefinition(new DocsPreviewDefinition(docs));
230
- return docs;
231
- }
232
- }
233
-
234
- DocsAspect.addRuntime(DocsMain);
@@ -1,38 +0,0 @@
1
- import { Component, ComponentMap } from '@teambit/component';
2
- import type { Environment, ExecutionContext } from '@teambit/envs';
3
- import { PreviewDefinition } from '@teambit/preview';
4
- import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
5
-
6
- import { DocsMain } from './docs.main.runtime';
7
-
8
- export class DocsPreviewDefinition implements PreviewDefinition {
9
- readonly prefix = 'overview';
10
- readonly include = ['compositions'];
11
- readonly includePeers = true;
12
-
13
- constructor(
14
- /**
15
- * docs extension.
16
- */
17
- private docs: DocsMain
18
- ) {}
19
-
20
- /**
21
- * application root
22
- */
23
- async renderTemplatePath(context: ExecutionContext): Promise<string | undefined> {
24
- return this.renderTemplatePathByEnv(context.env);
25
- }
26
-
27
- async renderTemplatePathByEnv(env: Environment): Promise<string | undefined> {
28
- return this.docs.getTemplate(env);
29
- }
30
-
31
- /**
32
- * files to load.
33
- */
34
- async getModuleMap(components: Component[]): Promise<ComponentMap<AbstractVinyl[]>> {
35
- const map = this.docs.getDocsMap(components);
36
- return map;
37
- }
38
- }
package/docs.service.ts DELETED
@@ -1,9 +0,0 @@
1
- import { EnvService, ExecutionContext } from '@teambit/envs';
2
-
3
- export class DocsService implements EnvService<any> {
4
- name = 'docs';
5
-
6
- async run(context: ExecutionContext) {
7
- return context.env.getDocsTemplate();
8
- }
9
- }
package/docs.ts DELETED
@@ -1,38 +0,0 @@
1
- import React, { ReactElement } from 'react';
2
-
3
- export type Example = {
4
- title?: string;
5
- description?: ReactElement;
6
- scope?: { [key: string]: any };
7
- jsx?: JSX.Element;
8
- code: string;
9
- };
10
-
11
- export type Docs = {
12
- /**
13
- * default is the docs content.
14
- */
15
- default: React.ComponentType;
16
-
17
- /**
18
- * component abstract.
19
- */
20
- abstract: string;
21
-
22
- /**
23
- * array of labels.
24
- */
25
- labels: string[];
26
-
27
- /**
28
- * @deprecated
29
- */
30
- examples: Example[];
31
- };
32
-
33
- export const defaultDocs: Docs = {
34
- default: () => null,
35
- labels: [],
36
- abstract: '',
37
- examples: [],
38
- };
package/index.ts DELETED
@@ -1,21 +0,0 @@
1
- import { DocsAspect } from './docs.aspect';
2
-
3
- /**
4
- * Doc entity.
5
- * @deprecated - please dont use this. use directly from @teambit/docs.entities.doc.
6
- */
7
- export { Doc, DocProp, DocPropList } from '@teambit/docs.entities.doc';
8
-
9
- export type { DocsMain } from './docs.main.runtime';
10
- export type { DocsUI } from './docs.ui.runtime';
11
- export type { DocsPreview, DocsRootProps } from './docs.preview.runtime';
12
- export type { DocReader } from './doc-reader';
13
- export type { Docs, Example } from './docs';
14
- export { defaultDocs } from './docs';
15
-
16
- export type { TitleBadgeSlot, TitleBadge, OverviewOptionsSlot, OverviewOptions } from './overview';
17
- export { BadgePosition } from './overview';
18
- export { Overview } from './overview';
19
-
20
- export { DocsAspect };
21
- export default DocsAspect;