Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(generator): update latest generator documentation #3349

Conversation

asyncapi-bot
Copy link
Contributor

@asyncapi-bot asyncapi-bot commented Oct 30, 2024

Updated generator documentation is available and this PR introduces update to generator folder on the website

Summary by CodeRabbit

  • Documentation
    • Updated the generator property documentation in package.json to clarify hooks configuration, including details about an official hooks library.
    • Enhanced the hooks.md document with new sections on hook types and an official hooks library, improving clarity and usability for users.

Copy link

coderabbitai bot commented Oct 30, 2024

Walkthrough

The pull request includes updates to the documentation for the generator property in the package.json file and enhancements to the hooks documentation. Key changes involve expanding the description of the hooks property to include the official hooks library @asyncapi/generator-hooks, modifying example configurations, and adding new sections in the hooks.md file to clarify hook types, their usage, and organization. The overall structure of the documentation has been improved for better clarity and usability.

Changes

File Path Change Summary
markdown/docs/tools/generator/configuration-file.md Updated documentation for hooks in package.json, added details on official hooks library, and modified example JSON configuration.
markdown/docs/tools/generator/hooks.md Enhanced structure and clarity of hooks documentation, added new sections on Types and Official library, and reformatted Examples section.

Possibly related PRs

Suggested reviewers

  • quetzalliwrites
  • devilkiller-ag
  • sambhavgupta0705
  • J0SAL
  • BhaswatiRoy
  • VaishnaviNandakumar
  • TRohit20
  • asyncapi-bot-eve

🐰 In the meadow, hops a clever hare,
With docs so bright, we now can share.
Hooks and types, all clear and neat,
AsyncAPI's magic, can't be beat!
So gather 'round, let's celebrate,
With joyful hearts, we elevate! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Oct 30, 2024

Deploy Preview for asyncapi-website ready!

Name Link
🔨 Latest commit 6b8aef3
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/672492b3e8ef010008735c2c
😎 Deploy Preview https://deploy-preview-3349--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.14%. Comparing base (29c76f7) to head (6b8aef3).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3349   +/-   ##
=======================================
  Coverage   49.14%   49.14%           
=======================================
  Files          21       21           
  Lines         647      647           
=======================================
  Hits          318      318           
  Misses        329      329           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@asyncapi-bot
Copy link
Contributor Author

asyncapi-bot commented Oct 30, 2024

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 44
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3349--asyncapi-website.netlify.app/

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (6)
markdown/docs/tools/generator/hooks.md (5)

Line range hint 8-17: Fix table formatting for better maintainability.

The table content is well-structured, but there are some formatting inconsistencies.

Apply these changes to follow Markdown best practices:

-|Hook type|Description| Return type | Arguments 
-|---|---|---|---|
+| Hook type | Description | Return type | Arguments |
+| --- | --- | --- | --- |
🧰 Tools
🪛 LanguageTool

[uncategorized] ~6-~6: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...rocess. Hooks can be anonymous functions but you can also add function names. These ...

(COMMA_COMPOUND_SENTENCE)


18-23: Fix grammar in the location section.

The content is clear, but there's a minor grammatical issue.

Apply this change:

-All modules listed in the template configuration and triggers only hooks whose names were added to the config.
+All modules listed in the template configuration, triggering only hooks whose names were added to the config.

Line range hint 24-86: Examples are well-structured and informative.

The examples effectively demonstrate various hook implementations. Consider adding TypeScript type annotations in the examples for better type safety and documentation.

Example with TypeScript:

import { Generator } from '@asyncapi/generator';

interface FileTemplateHookArguments {
  originalFilename: string;
}

module.exports = {
  'setFileTemplateName': (generator: Generator, hookArguments: FileTemplateHookArguments): string => {
    const currentFilename = hookArguments.originalFilename;
    return currentFilename.replace('-', '_');
  }
};
🧰 Tools
🪛 LanguageTool

[formatting] ~26-~26: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...efault location or in a separate library, because such hooks need to be explicitly config...

(COMMA_BEFORE_BECAUSE)

🪛 Markdownlint

16-16: null
Spaces inside code span elements

(MD038, no-space-in-code)


88-118: Improve table formatting and spacing in the Official library section.

The content is excellent, but there are some formatting improvements needed.

  1. Add blank lines around the table
  2. Fix table formatting:
-|Hook name|Hook type|Description|
-|---|---|---|
+
+| Hook name | Hook type | Description |
+| --- | --- | --- |
+
🧰 Tools
🪛 Markdownlint

93-93: Expected: leading_only; Actual: leading_and_trailing; Unexpected trailing pipe
Table pipe style

(MD055, table-pipe-style)


94-94: Expected: leading_only; Actual: leading_and_trailing; Unexpected trailing pipe
Table pipe style

(MD055, table-pipe-style)


95-95: Expected: leading_only; Actual: leading_and_trailing; Unexpected trailing pipe
Table pipe style

(MD055, table-pipe-style)


93-93: null
Tables should be surrounded by blank lines

(MD058, blanks-around-tables)


7-7: Consider adding version compatibility information.

To help users understand compatibility requirements, consider adding a section about:

  • Minimum generator version required
  • Node.js version compatibility
  • Any breaking changes in hook behavior across versions

Would you like me to help draft this section?

markdown/docs/tools/generator/configuration-file.md (1)

23-23: Fix table formatting and improve readability.

The updated hooks documentation is comprehensive and well-structured. However, there are a few minor improvements needed:

  1. Add a trailing pipe to maintain consistent table formatting
  2. Add a comma after "For each module" to improve readability

Apply this diff:

-|`hooks`| Object[String, String] or Object[String, Array[String]] | A list of modules containing hooks, except for the ones you keep locally in your template in the default location. For each module you must specify the exact name of the hook that should be used in the template. For a single hook, you can specify it as a string; for more hooks, you must pass an array of strings. In the case of external modules, remember they need to be added as a dependency in `package.json` of your template. There is also [an official hooks library](hooks#official-library) always included in the generator. As this is a library of multiple hooks, you still need to explicitly specify in the configuration which one you want to use. Use `@asyncapi/generator-hooks` as the library name.
+|`hooks`| Object[String, String] or Object[String, Array[String]] | A list of modules containing hooks, except for the ones you keep locally in your template in the default location. For each module, you must specify the exact name of the hook that should be used in the template. For a single hook, you can specify it as a string; for more hooks, you must pass an array of strings. In the case of external modules, remember they need to be added as a dependency in `package.json` of your template. There is also [an official hooks library](hooks#official-library) always included in the generator. As this is a library of multiple hooks, you still need to explicitly specify in the configuration which one you want to use. Use `@asyncapi/generator-hooks` as the library name. |
🧰 Tools
🪛 LanguageTool

[typographical] ~23-~23: It appears that a comma is missing.
Context: ...plate in the default location. For each module you must specify the exact name of the ...

(DURING_THAT_TIME_COMMA)

🪛 Markdownlint

23-23: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style

(MD055, table-pipe-style)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between baa5f90 and 31e8b61.

📒 Files selected for processing (2)
  • markdown/docs/tools/generator/configuration-file.md (2 hunks)
  • markdown/docs/tools/generator/hooks.md (3 hunks)
🧰 Additional context used
🪛 LanguageTool
markdown/docs/tools/generator/configuration-file.md

[typographical] ~23-~23: It appears that a comma is missing.
Context: ...plate in the default location. For each module you must specify the exact name of the ...

(DURING_THAT_TIME_COMMA)

markdown/docs/tools/generator/hooks.md

[formatting] ~26-~26: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...efault location or in a separate library, because such hooks need to be explicitly config...

(COMMA_BEFORE_BECAUSE)

🪛 Markdownlint
markdown/docs/tools/generator/configuration-file.md

23-23: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style

(MD055, table-pipe-style)

markdown/docs/tools/generator/hooks.md

93-93: Expected: leading_only; Actual: leading_and_trailing; Unexpected trailing pipe
Table pipe style

(MD055, table-pipe-style)


94-94: Expected: leading_only; Actual: leading_and_trailing; Unexpected trailing pipe
Table pipe style

(MD055, table-pipe-style)


95-95: Expected: leading_only; Actual: leading_and_trailing; Unexpected trailing pipe
Table pipe style

(MD055, table-pipe-style)


93-93: null
Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

🔇 Additional comments (1)
markdown/docs/tools/generator/configuration-file.md (1)

67-68: LGTM! Clear and helpful examples.

The examples effectively demonstrate both single hook usage with @asyncapi/generator-hooks and multiple hooks usage with a custom package.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
markdown/docs/tools/generator/hooks.md (4)

Line range hint 8-17: Enhance table formatting for better readability.

The Types section is a valuable addition. Consider these improvements for consistency:

  • Use consistent formatting for return types (e.g., "void" vs "string")
  • Add specific parameter types in the Arguments column
|Hook type|Description| Return type | Arguments|
|---|---|---|---|
-| `generate:before` | Called after registration of all filters and before the generator starts processing of the template. | void : Nothing is expected to be returned. | [The generator instance](/api)
-| `generate:after` | Called at the very end of the generation. | void : Nothing is expected to be returned. | [The generator instance](/api)
-| `setFileTemplateName ` | Called right before saving a new file generated by [file template](./file-templates.md). | string : a new filename for the generator to use for the file template. | [The generator instance](/api) and object in the form of `{ "originalFilename" : string }`
+| `generate:before` | Called after registration of all filters and before the generator starts processing of the template. | `void` | `generator: Generator` |
+| `generate:after` | Called at the very end of the generation. | `void` | `generator: Generator` |
+| `setFileTemplateName` | Called right before saving a new file generated by [file template](./file-templates.md). | `string` | `generator: Generator, args: { originalFilename: string }` |
🧰 Tools
🪛 LanguageTool

[uncategorized] ~6-~6: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...rocess. Hooks can be anonymous functions but you can also add function names. These ...

(COMMA_COMPOUND_SENTENCE)


Line range hint 24-86: Consider enhancing the code examples with best practices.

While the examples are clear and informative, consider these improvements:

  1. Add error handling in the file writing operation
  2. Add type checking for the AsyncAPI instance
  3. Include JSDoc comments for better documentation

Example enhancement for the AsyncAPI file creation:

 module.exports = {
-  'generate:after': generator => {
+  'generate:after': async generator => {
+    try {
       const asyncapi = generator.originalAsyncAPI;
       let extension;
 
       try {
         JSON.parse(asyncapi);
         extension = 'json';
       } catch (e) {
         extension = 'yaml';
       }
 
-      fs.writeFileSync(path.resolve(generator.targetDir, `asyncapi.${extension}`), asyncapi);
+      await fs.promises.writeFile(
+        path.resolve(generator.targetDir, `asyncapi.${extension}`),
+        asyncapi
+      );
+    } catch (error) {
+      console.error('Failed to create AsyncAPI file:', error);
+      throw error;
+    }
   }
 };
🧰 Tools
🪛 LanguageTool

[formatting] ~26-~26: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...efault location or in a separate library, because such hooks need to be explicitly config...

(COMMA_BEFORE_BECAUSE)

🪛 Markdownlint

16-16: null
Spaces inside code span elements

(MD038, no-space-in-code)


88-118: Enhance the official library documentation.

The section provides valuable information about the official hooks library. Consider these improvements:

  1. Fix table formatting (remove trailing pipes)
  2. Add version information for the @asyncapi/generator-hooks package
  3. Include a link to the package's repository
-|Hook name|Hook type|Description|
-|---|---|---|
-| `createAsyncapiFile` | `generate:after` | It creates an AsyncAPI file with the content of the spec file passed to the generator. By default, it creates the file in the root of the generation output directory. This hook also supports custom parameters that the user can pass to template generation. The parameter called `asyncapiFileDir` allows the user to specify the location where the spec file should be created. To make your template users use this parameter, you need to add it to the configuration of your template like other parameters |
+Hook name|Hook type|Description
+---|---|---
+`createAsyncapiFile` | `generate:after` | Creates an AsyncAPI file with the content of the spec file passed to the generator. By default, creates the file in the root of the generation output directory. Supports the `asyncapiFileDir` parameter to specify a custom file location.

Also, consider adding installation instructions:

Install the official hooks library:
```bash
npm install @asyncapi/generator-hooks

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 LanguageTool</summary>

[uncategorized] ~107-~107: Possible missing article found.
Context: ...me hooks support custom parameters that template's user can use to specify different beh...

(AI_HYDRA_LEO_MISSING_THE)

</details>
<details>
<summary>🪛 Markdownlint</summary>

93-93: Expected: leading_only; Actual: leading_and_trailing; Unexpected trailing pipe
Table pipe style

(MD055, table-pipe-style)

---

94-94: Expected: leading_only; Actual: leading_and_trailing; Unexpected trailing pipe
Table pipe style

(MD055, table-pipe-style)

---

95-95: Expected: leading_only; Actual: leading_and_trailing; Unexpected trailing pipe
Table pipe style

(MD055, table-pipe-style)

---

93-93: null
Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

</details>

</details>

---

`107-107`: **Fix grammar in the documentation.**

Add the missing article "the" before "template's user":
```diff
-Some hooks support custom parameters that template's user can use
+Some hooks support custom parameters that the template's user can use
🧰 Tools
🪛 LanguageTool

[uncategorized] ~107-~107: Possible missing article found.
Context: ...me hooks support custom parameters that template's user can use to specify different beh...

(AI_HYDRA_LEO_MISSING_THE)

markdown/docs/tools/generator/configuration-file.md (1)

23-23: Add comma for better readability.

The description is comprehensive and well-structured. However, there's a minor grammatical improvement needed.

Apply this change:

-|`hooks`| Object[String, String] or Object[String, Array[String]] | A list of modules containing hooks, except for the ones you keep locally in your template in the default location. For each module you must specify the exact name of the hook that should be used in the template. For a single hook, you can specify it as a string; for more hooks, you must pass an array of strings. In the case of external modules, remember they need to be added as a dependency in `package.json` of your template. There is also [an official hooks library](hooks#official-library) always included in the generator. As this is a library of multiple hooks, you still need to explicitly specify in the configuration which one you want to use. Use `@asyncapi/generator-hooks` as the library name.
+|`hooks`| Object[String, String] or Object[String, Array[String]] | A list of modules containing hooks, except for the ones you keep locally in your template in the default location. For each module, you must specify the exact name of the hook that should be used in the template. For a single hook, you can specify it as a string; for more hooks, you must pass an array of strings. In the case of external modules, remember they need to be added as a dependency in `package.json` of your template. There is also [an official hooks library](hooks#official-library) always included in the generator. As this is a library of multiple hooks, you still need to explicitly specify in the configuration which one you want to use. Use `@asyncapi/generator-hooks` as the library name.
🧰 Tools
🪛 LanguageTool

[typographical] ~23-~23: It appears that a comma is missing.
Context: ...plate in the default location. For each module you must specify the exact name of the ...

(DURING_THAT_TIME_COMMA)

🪛 Markdownlint

23-23: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style

(MD055, table-pipe-style)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between baa5f90 and 31e8b61.

📒 Files selected for processing (2)
  • markdown/docs/tools/generator/configuration-file.md (2 hunks)
  • markdown/docs/tools/generator/hooks.md (3 hunks)
🧰 Additional context used
🪛 LanguageTool
markdown/docs/tools/generator/configuration-file.md

[typographical] ~23-~23: It appears that a comma is missing.
Context: ...plate in the default location. For each module you must specify the exact name of the ...

(DURING_THAT_TIME_COMMA)

markdown/docs/tools/generator/hooks.md

[formatting] ~26-~26: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...efault location or in a separate library, because such hooks need to be explicitly config...

(COMMA_BEFORE_BECAUSE)


[uncategorized] ~107-~107: Possible missing article found.
Context: ...me hooks support custom parameters that template's user can use to specify different beh...

(AI_HYDRA_LEO_MISSING_THE)

🪛 Markdownlint
markdown/docs/tools/generator/configuration-file.md

23-23: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style

(MD055, table-pipe-style)

markdown/docs/tools/generator/hooks.md

93-93: Expected: leading_only; Actual: leading_and_trailing; Unexpected trailing pipe
Table pipe style

(MD055, table-pipe-style)


94-94: Expected: leading_only; Actual: leading_and_trailing; Unexpected trailing pipe
Table pipe style

(MD055, table-pipe-style)


95-95: Expected: leading_only; Actual: leading_and_trailing; Unexpected trailing pipe
Table pipe style

(MD055, table-pipe-style)


93-93: null
Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

🔇 Additional comments (2)
markdown/docs/tools/generator/hooks.md (1)

18-23: LGTM!

The Location section clearly explains hook locations and properly references related documentation sections.

markdown/docs/tools/generator/configuration-file.md (1)

67-68: LGTM! Clear and instructive example.

The example effectively demonstrates both single hook usage with the official library and multiple hooks configuration with a custom package.

@akshatnema
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit 2e33ac3 into master Nov 1, 2024
20 checks passed
@asyncapi-bot asyncapi-bot deleted the update-generator-docs-2d16234f26e6af4307ece99d8d7ccf9cc97ee5de branch November 1, 2024 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants