Skip to content

Commit 204d2b2

Browse files
authored
Merge pull request #203 from GetStream/generate-component-docs
feat: Doc comments for components, documentation generated from doc c…
2 parents 7a24247 + 3880056 commit 204d2b2

File tree

67 files changed

+1005
-1113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1005
-1113
lines changed

.github/workflows/workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
GH_TOKEN: ${{ secrets.GH_TOKEN }}
5555
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5656
run: npx semantic-release
57-
- name: Generate service docs
57+
- name: Generate docs
5858
run: |
5959
npm run generate-docs
6060
- name: Push to docusaurus

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ testem.log
4141
/typings
4242

4343
# Generated docs
44-
temp-docs
44+
temp-service-docs
45+
temp-component-docs
4546
docusaurus/docs/Angular/services/*.mdx
4647

4748
# System Files

README.md

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,38 @@ The best way to get started is to follow the [Angular Chat Tutorial](https://get
3030
Stream is free for most side and hobby projects. To qualify, your project/company must have no more than 5 team members and earn less than $10k in monthly revenue.
3131
For complete pricing and details visit our [Chat Pricing Page](https://getstream.io/chat/pricing/).
3232

33+
## Docs
34+
35+
The [docs](https://getstream.io/chat/docs/sdk/angular/) provide a brief description about the components and services in the library.
36+
37+
The Angular library is created using the [stream-chat-js](https://github.com/getstream/stream-chat-js) library. For the most common use cases our services should give a nice abstraction over this library, however you might need it for more advanced customization, the [documentation](https://getstream.io/chat/docs/js/) is on our website.
38+
39+
## Contributing
40+
41+
We welcome code changes that improve this library or fix a problem. Please make sure to follow all best practices and add tests, if applicable, before submitting a pull request on GitHub. We are pleased to merge your code into the official repository if it meets a need. Make sure to sign our [Contributor License Agreement (CLA)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our license file for more details.
42+
43+
## We are hiring!
44+
45+
We recently closed a [$38 million Series B funding round](https://techcrunch.com/2021/03/04/stream-raises-38m-as-its-chat-and-activity-feed-apis-power-communications-for-1b-users/) and are actively growing.
46+
Our APIs are used by more than a billion end-users, and by working at Stream, you have the chance to make a huge impact on a team of very strong engineers.
47+
48+
Check out our current openings and apply via [Stream's website](https://getstream.io/team/#jobs).
49+
3350
## Installation
3451

3552
### Install with NPM
3653

37-
```
54+
Run the following command if you are using **Angular 13**:
55+
56+
```shell
3857
npm install stream-chat-angular @stream-io/stream-chat-css stream-chat @ngx-translate/core
3958
```
4059

41-
**Important note** If you are using **Angular 12** you will need to add `--legacy-peer-deps` flag as `@ngx-translate/core`'s newest version only supports Angular 13.
60+
Run this command if you are using **Angular 12**:
61+
62+
```shell
63+
npm install stream-chat-angular @stream-io/stream-chat-css stream-chat@5 @ngx-translate/core --legacy-peer-deps
64+
```
4265

4366
## Sample App
4467

@@ -56,19 +79,12 @@ STREAM_USER_TOKEN=<Your user token>
5679

5780
Run `npm start` and navigate to `http://localhost:4200/`.
5881

59-
## Docs
82+
## Local development
6083

61-
The [docs](https://getstream.io/chat/docs/sdk/angular/) provide a brief description about the components and services in the library.
62-
63-
The Angular library is created using the [stream-chat-js](https://github.com/getstream/stream-chat-js) library. For the most common use cases our services should give a nice abstraction over this library, however you might need it for more advanced customization, the [documentation](https://getstream.io/chat/docs/js/) is on our website.
84+
Run `npm install` in the root of the project. You can use the `npm run start:dev` command to start the SampleApp with automatic reloading.
6485

65-
## Contributing
86+
A note about the documentation:
6687

67-
We welcome code changes that improve this library or fix a problem. Please make sure to follow all best practices and add tests, if applicable, before submitting a pull request on GitHub. We are pleased to merge your code into the official repository if it meets a need. Make sure to sign our [Contributor License Agreement (CLA)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our license file for more details.
68-
69-
## We are hiring!
70-
71-
We recently closed a [$38 million Series B funding round](https://techcrunch.com/2021/03/04/stream-raises-38m-as-its-chat-and-activity-feed-apis-power-communications-for-1b-users/) and are actively growing.
72-
Our APIs are used by more than a billion end-users, and by working at Stream, you have the chance to make a huge impact on a team of very strong engineers.
73-
74-
Check out our current openings and apply via [Stream's website](https://getstream.io/team/#jobs).
88+
- Documentations for Angular services are generated from doc comments in the source files (not under source control)
89+
- Documentations for inputs and outputs of Angular components are generated from doc comments in the source files (not under source control)
90+
- Everything else in the documentation is written in `mdx` files located in the `docusaurus` folder

copy-generated-component-docs.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
const fs = require('fs');
2+
3+
const generatedDocsPath = 'temp-component-docs/classes';
4+
const componentDocsPath = 'docusaurus/docs/Angular/components';
5+
const startOfGeneratedContentMark = '[//]: # "Start of generated content"';
6+
const endOfGeneratedContentMark = '[//]: # "End of generated content"';
7+
8+
const extractProperties = (content: string) => {
9+
const lines: string[] = content.split('\n');
10+
const startOfPropertiesMark = '## Properties';
11+
const endOfPropertiesMark = '## '; // End of properties: next heading
12+
const startOfPropertiesLineNumber = lines.indexOf(startOfPropertiesMark);
13+
const endOfPropertiesLineNumber = lines.findIndex(
14+
(line, index) =>
15+
line.startsWith(endOfPropertiesMark) &&
16+
index > startOfPropertiesLineNumber
17+
);
18+
19+
if (startOfPropertiesLineNumber === -1) {
20+
return [];
21+
}
22+
23+
return lines.filter(
24+
(_, lineNumber) =>
25+
lineNumber > startOfPropertiesLineNumber &&
26+
(endOfPropertiesLineNumber === -1 ||
27+
lineNumber < endOfPropertiesLineNumber)
28+
);
29+
};
30+
31+
const insertGeneratedParts = (
32+
fileContent: string,
33+
generatedContent: string[]
34+
) => {
35+
const lines: string[] = fileContent.split('\n');
36+
const startOfGeneratedContentLineNumber = lines.indexOf(
37+
startOfGeneratedContentMark
38+
);
39+
const result = [
40+
...lines.splice(0, startOfGeneratedContentLineNumber + 1),
41+
generatedContent.length ? '## Inputs and outputs \n' : '\n',
42+
...generatedContent,
43+
...lines.splice(0),
44+
];
45+
46+
return result.join('\n');
47+
};
48+
49+
fs.readdir(generatedDocsPath, (err: any, files: string[]) => {
50+
if (err) {
51+
throw err;
52+
}
53+
files.forEach((file) => {
54+
fs.readFile(
55+
`${generatedDocsPath}/${file}`,
56+
'utf8',
57+
(err: any, generatedFileContent: string) => {
58+
if (err) {
59+
throw err;
60+
}
61+
62+
const propertiesContent = extractProperties(generatedFileContent);
63+
64+
fs.readFile(
65+
`${componentDocsPath}/${file}x`,
66+
'utf8',
67+
(err: any, docFile: any) => {
68+
if (err)
69+
throw new Error(
70+
`${componentDocsPath}/${file}x couldn't be opened, error: ${err}, make sure that this file exists`
71+
);
72+
73+
if (file !== '_category_.json') {
74+
const result = insertGeneratedParts(docFile, propertiesContent);
75+
76+
fs.writeFile(
77+
`${componentDocsPath}/${file}x`,
78+
result,
79+
'utf8',
80+
(err: any) => {
81+
if (err) throw err;
82+
}
83+
);
84+
}
85+
}
86+
);
87+
}
88+
);
89+
});
90+
});

copy-generated-docs.ts renamed to copy-generated-service-docs.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
const fs = require('fs');
22

3-
const sourcePath = 'temp-docs/classes';
4-
const targetPath = 'docusaurus/docs/Angular/services';
3+
const sourcePath = 'temp-service-docs/classes';
4+
const serviceDocsTargetPath = 'docusaurus/docs/Angular/services';
55

6-
fs.readdir(targetPath, (err: any, files: string[]) => {
6+
// remove docs from the source folder
7+
fs.readdir(serviceDocsTargetPath, (err: any, files: string[]) => {
78
if (err) {
89
throw err;
910
}
1011
files.forEach((file) => {
1112
if (file !== '_category_.json') {
1213
try {
13-
fs.unlinkSync(`${targetPath}/${file}`);
14+
fs.unlinkSync(`${serviceDocsTargetPath}/${file}`);
1415
} catch (err: any) {
1516
throw err;
1617
}
1718
}
1819
});
1920
});
2021

22+
// copy generated files
2123
fs.readdir(sourcePath, (err: any, files: string[]) => {
2224
if (err) {
2325
throw err;
@@ -27,6 +29,8 @@ fs.readdir(sourcePath, (err: any, files: string[]) => {
2729
if (err) {
2830
throw err;
2931
}
32+
33+
// Remove the thre prefix from the title
3034
const result = data.replace(/# Class:/g, '#');
3135

3236
fs.writeFile(`${sourcePath}/${file}`, result, 'utf8', (err: any) => {
@@ -35,7 +39,7 @@ fs.readdir(sourcePath, (err: any, files: string[]) => {
3539
}
3640
fs.copyFile(
3741
`${sourcePath}/${file}`,
38-
`${targetPath}/${file}x`,
42+
`${serviceDocsTargetPath}/${file}x`,
3943
(err: any) => {
4044
if (err) {
4145
throw err;

docusaurus/docs/Angular/code-examples/emoji-picker.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class AppModule {}
6161

6262
3. Component class
6363

64-
Your emoji picker component should have an input with the type `Subject<string>` to emit the selected emojis. This input will be provided by the [`MessageInput`](../components/message-input.mdx) component.
64+
Your emoji picker component should have an input with the type `Subject<string>` to emit the selected emojis. This input will be provided by the [`MessageInput`](../components/MessageInputComponent.mdx) component.
6565

6666
We also defined an `isOpened` property that tells if the emoji picker should be opened or closed.
6767

@@ -153,7 +153,7 @@ button {
153153

154154
## Provide your custom template
155155

156-
Let's provide our custom emoji picker template to the [`MessageInput`](../components/message-input.mdx) component:
156+
Let's provide our custom emoji picker template to the [`MessageInput`](../components/MessageInputComponent.mdx) component:
157157

158158
```html
159159
<div id="root">

docusaurus/docs/Angular/components/attachment-list.mdx renamed to docusaurus/docs/Angular/components/AttachmentListComponent.mdx

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
---
2-
id: attachment-list
3-
sidebar_position: 2
4-
title: Attachments
5-
---
6-
71
import AttachmentsScreenshot from "../assets/attachments-screenshot.png";
82

9-
TEST
10-
113
The `AttachmentList` compontent displays the attachments of a message. The following attachments are supported:
124

135
- Images (including GIFs) are displayed inline
@@ -41,20 +33,5 @@ export class CustomMessageComponent {
4133
}
4234
```
4335

44-
## Inputs
45-
46-
### <div class="label required basic">Required</div> attachments
47-
48-
The attachments to display
49-
50-
| Type | Default |
51-
| ----------------------------------------------------------------------------------------------------------------- | ------- |
52-
| [`Attachment`](https://getstream.io/chat/docs/javascript/message_format/?language=javascript#attachment-format)[] | [] |
53-
54-
### <div class="label required basic">Required</div> messageId
55-
56-
The id of the message the attachments belong to
57-
58-
| Type |
59-
| ------ |
60-
| string |
36+
[//]: # "Start of generated content"
37+
[//]: # "End of generated content"

docusaurus/docs/Angular/components/attachment-preview-list.mdx renamed to docusaurus/docs/Angular/components/AttachmentPreviewListComponent.mdx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
---
2-
id: attachment-preview-list
3-
sidebar_position: 3
4-
title: Attachment previews
5-
---
6-
71
import Screenshot from "../assets/attachment-preview-list-screenshot.png";
82

93
The `AttachmentPreviewList` compontent displays a preview of the attachments uploaded to a message. Users can delete attachments using the preview component, or retry upload if it failed previously.
@@ -30,3 +24,6 @@ export class CustomMessageInputComponent {}
3024
```
3125

3226
The `AttachmentPreviewList` uses the [`AttachmentService`](../services/AttachmentService.mdx) to display the attachment previews.
27+
28+
[//]: # "Start of generated content"
29+
[//]: # "End of generated content"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
The `AutocompleteTextarea` component is used by the [`MessageInput`](./MessageInputComponent.mdx) component to display the input HTML element where users can type their message.
2+
3+
Message send can be triggered with the `Enter` key, new line can be added with the `Shift+Enter` combination.
4+
5+
The `AutocompleteTextarea` extends the funcitonalities of the [`Textarea`](./TextareaComponent.mdx) component with autocomplete features:
6+
7+
- users can mention other users in a message (transliteration is used to support languages with non-Latin characters)
8+
- users can send commands (for example /giphy)
9+
10+
## Basic usage
11+
12+
You can use the `AutocompleteTextarea` component if you want to create your own message input component to override the default one:
13+
14+
```typescript
15+
@Component({
16+
selector: "app-custom-message-input",
17+
template: `
18+
<stream-autocomplete-textarea
19+
[(value)]="textareaValue"
20+
(send)="messageSent()"
21+
(userMentions)="mentionedUsers = $event"
22+
></stream-autocomplete-textarea>
23+
<!-- Other parts of the custom message input component -->
24+
`,
25+
})
26+
export class CustomMessageInputComponent {
27+
textareaValue = "";
28+
mentionedUsers = [];
29+
30+
messageSent() {
31+
// Send your message
32+
}
33+
}
34+
```
35+
36+
[//]: # "Start of generated content"
37+
[//]: # "End of generated content"
Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
---
2-
id: avatar
3-
sidebar_position: 1
4-
title: Avatar
5-
---
6-
71
The `Avatar` component displays the provided image, with fallback to the first letter of the optional name input.
82

93
## Basic Usage
@@ -27,28 +21,5 @@ export class CustomMessageComponent {
2721
}
2822
```
2923

30-
## Inputs
31-
32-
### imageUrl
33-
34-
The URL of the image to be displayed. If the image can't be displayed the first letter of the name input is displayed.
35-
36-
| Type | Default |
37-
| -------------- | ------------------------- |
38-
| string \| null | first initial of the name |
39-
40-
### name
41-
42-
An optional name of the image, used for fallback image or image title (if `imageUrl` is provided)
43-
44-
| Type |
45-
| -------------- |
46-
| string \| null |
47-
48-
### size
49-
50-
The size in pixels of the avatar image.
51-
52-
| Type | Default |
53-
| ------ | ------- |
54-
| number | 32px |
24+
[//]: # "Start of generated content"
25+
[//]: # "End of generated content"

0 commit comments

Comments
 (0)