diff --git a/.all-contributorsrc b/.all-contributorsrc index c25044ade..345d54075 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -183,7 +183,12 @@ "avatar_url": "https://avatars.githubusercontent.com/u/16447041?v=4", "profile": "https://github.com/lmgyuan", "contributions": [ - "doc" + "doc", + "bug", + "code", + "ideas", + "review", + "test" ] }, { @@ -205,6 +210,20 @@ "contributions": [ "bug" ] + }, + { + "login": "Gmin2", + "name": "Mintu Gogoi", + "avatar_url": "https://avatars.githubusercontent.com/u/127925465?v=4", + "profile": "https://github.com/Gmin2", + "contributions": [ + "bug", + "code", + "ideas", + "doc", + "review", + "test" + ] } ], "contributorsPerLine": 3, diff --git a/.eslintignore b/.eslintignore index 8177e20b5..42485b09e 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,4 +3,4 @@ apps/generator/output/* .github/templates-list-validator/dist/* apps/generator/test/temp/* apps/generator/test/test-templates/react-template/__transpiled/* - +packages/components/lib/* \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index 727aafeae..63261ef51 100644 --- a/.eslintrc +++ b/.eslintrc @@ -110,4 +110,5 @@ rules: react/react-in-jsx-scope: off react/display-name: off react/prop-types: off - react/jsx-key: off \ No newline at end of file + react/jsx-key: off + react/no-unescaped-entities: off \ No newline at end of file diff --git a/.github/workflows/pr-testing-with-test-project.yml b/.github/workflows/pr-testing-with-test-project.yml index 7c543f907..b9f10c0d4 100644 --- a/.github/workflows/pr-testing-with-test-project.yml +++ b/.github/workflows/pr-testing-with-test-project.yml @@ -1,9 +1,17 @@ -#This workflow runs the tests in the test projects to make sure the generator works as a library where it is a Node dependency along with the template. +# This workflow runs the tests in the test projects to make sure the generator works as a library where it is a Node dependency along with the template. name: Test using test project on: pull_request: types: [opened, reopened, synchronize, ready_for_review] + paths: + - 'package.json' + - 'package-lock.json' + - 'apps/**' + - 'packages/**' + - '.github/workflows/**' + - '!**/*.md' + - '!docs/**' jobs: test: @@ -16,6 +24,27 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Run test + + - name: Determine if tests should run + id: should_run + if: > + !github.event.pull_request.draft && !( + (github.actor == 'asyncapi-bot' && ( + startsWith(github.event.pull_request.title, 'ci: update of files from global .github repo') || + startsWith(github.event.pull_request.title, 'chore(release):') + )) || + (github.actor == 'asyncapi-bot-eve' && ( + startsWith(github.event.pull_request.title, 'ci: update of files from global .github repo') || + startsWith(github.event.pull_request.title, 'chore(release):') + )) || + (github.actor == 'allcontributors[bot]' && + startsWith(github.event.pull_request.title, 'docs: add') + ) + ) + run: echo "shouldrun=true" >> $GITHUB_OUTPUT + shell: bash + + - if: steps.should_run.outputs.shouldrun == 'true' + name: Run test run: NODE_IMAGE_TAG=${{ matrix.node }} docker compose up --abort-on-container-exit --remove-orphans --force-recreate working-directory: ./apps/generator/test/test-project diff --git a/.github/workflows/update-maintainers-trigger.yaml b/.github/workflows/update-maintainers-trigger.yaml new file mode 100644 index 000000000..12fc4abe4 --- /dev/null +++ b/.github/workflows/update-maintainers-trigger.yaml @@ -0,0 +1,28 @@ +# This action is centrally managed in https://github.com/asyncapi/.github/ +# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo + +name: Trigger MAINTAINERS.yaml file update + +on: + push: + branches: [ master ] + paths: + # Check all valid CODEOWNERS locations: + # https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-file-location + - 'CODEOWNERS' + - '.github/CODEOWNERS' + - '.docs/CODEOWNERS' + +jobs: + trigger-maintainers-update: + name: Trigger updating MAINTAINERS.yaml because of CODEOWNERS change + runs-on: ubuntu-latest + + steps: + - name: Repository Dispatch + uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # https://github.com/peter-evans/repository-dispatch/releases/tag/v3.0.0 + with: + # The PAT with the 'public_repo' scope is required + token: ${{ secrets.GH_TOKEN }} + repository: ${{ github.repository_owner }}/community + event-type: trigger-maintainers-update diff --git a/.gitignore b/.gitignore index a53c05bd1..d51895b8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ **/node_modules/ - +.DS_Store # Local env files .env .env.local @@ -15,3 +15,4 @@ coverage .turbo /.idea +temp \ No newline at end of file diff --git a/.sonarcloud.properties b/.sonarcloud.properties index 208c092d7..f0bcdf028 100644 --- a/.sonarcloud.properties +++ b/.sonarcloud.properties @@ -1,2 +1,2 @@ #we need to explicitly exclude them as some are commit to the repo -sonar.exclusions=test/**/* +sonar.exclusions=**/test/**/*,**/*__transpiled/**/*.js,packages/templates/clients/js/websocket/example.js, \ No newline at end of file diff --git a/Development.md b/Development.md index f62d50476..61144d0c3 100644 --- a/Development.md +++ b/Development.md @@ -78,7 +78,7 @@ cd apps/generator 3. Run the generator with the react-template: ```bash -asyncapi generate fromTemplate ./test/docs/dummy.yml ./test/test-templates/react-template -o ./test/output --force-write +node ./cli ./test/docs/dummy.yml ./test/test-templates/react-template -o ./test/output --force-write ``` 4. Check the output in the `./test/output` directory to verify the output that you desired. diff --git a/README.md b/README.md index 5fe3c6018..6c6789828 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,19 @@ [![AsyncAPI Generator](./assets/readme-banner.png)](https://www.asyncapi.com/tools/generator) +> Some parts of the AsyncAPI Generator are deprecated and the plan is to remove them in October 2025. For more details read notes from release [@asyncapi/generator@2.6.0](https://github.com/asyncapi/generator/releases/tag/%40asyncapi%2Fgenerator%402.6.0). + This is a Monorepo managed using [Turborepo](https://turbo.build/) and contains the following package: 1. [Generator](apps/generator): This is a tool that you can use to generate whatever you want basing on the AsyncAPI specification file as an input. -2. [Nunjucks-filters](apps/nunjucks-filters): This library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. These filters are designed specifically for Nunjucks templates and are included by default with the generator, so there's no need to add them to dependencies seprately. +1. [Hooks](apps/hooks): This library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. Hooks are designed to let template developers hook into the template generation process. For example, one can create a hook code that will be automatically invoked right after the template generation process has ended. +1. [Nunjucks-filters](apps/nunjucks-filters): This library contains generator filters that can be reused across multiple templates helping to avoid redundant work. These filters are designed specifically for Nunjucks templates and are included by default with the generator, so there's no need to add them to dependencies separately. -![npm](https://img.shields.io/npm/v/@asyncapi/generator?style=for-the-badge) ![npm](https://img.shields.io/npm/dt/@asyncapi/generator?style=for-the-badge) +> [!IMPORTANT] +> **Deprecation Notice:** The Nunjucks renderer engine is deprecated and will be removed in future releases. We strongly recommend using the React renderer engine instead. You can find how to migrate from Nunjucks to React in the [migration guide](apps/generator/docs/nunjucks-depreciate.md) -> warning: This package doesn't support AsyncAPI 1.x anymore. We recommend to upgrade to the latest AsyncAPI version using the [AsyncAPI converter](https://github.com/asyncapi/converter-js) (You can refer to [installation guide](/apps/generator//docs//installation-guide.md)). If you need to convert documents on the fly, you may use the [Node.js](https://github.com/asyncapi/converter-js) or [Go](https://github.com/asyncapi/converter-go) converters. +![npm](https://img.shields.io/npm/v/@asyncapi/generator?style=for-the-badge) ![npm](https://img.shields.io/npm/dt/@asyncapi/generator?style=for-the-badge) @@ -17,6 +21,8 @@ This is a Monorepo managed using [Turborepo](https://turbo.build/) and contains - [Overview](#overview) - [List of official generator templates](#list-of-official-generator-templates) +- [Filters](#filters) +- [Hooks](#hooks) - [Contributing](#contributing) - [Contributors ✨](#contributors-%E2%9C%A8) @@ -53,18 +59,24 @@ There is a large number of templates that are ready to use and are officially su You can find above templates and the ones provided by the community in **[this list](https://github.com/search?q=topic%3Aasyncapi+topic%3Agenerator+topic%3Atemplate)** -# Generator Filters +## Filters -This library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. These filters are designed specifically for Nunjucks templates and are included by default with the generator, so there's no need to add them to dependencies seprately. + `apps/nunjucks-filters` library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. These filters are designed specifically for Nunjucks templates and are included by default with the generator, so there's no need to add them to dependencies separately. This library consists of: - Custom filters. Check out [API docs](apps/nunjucks-filters/docs/api.md) for complete list - Lodash-powered filters. For the list of all available filters check [official docs](https://lodash.com/docs/) +## Hooks + +The `apps/hooks` library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. [Hooks](https://www.asyncapi.com/docs/tools/generator/hooks) are functions called by the generator at specific moments in the generation process. Hooks can be anonymous functions, but you can also assign them function names. These hooks can have arguments provided to them, or they may be expected to return a value. + +These hooks are included in the generator without adding any specific dependency to the library. You still have to enable the given hook in the configuration explicitly because some hooks can execute automatically without passing a specific parameter. [Learn more about configuration and what hooks are available out of the box](https://www.asyncapi.com/docs/tools/generator/hooks#official-library). + ## Contributing -For developement setup you can follow the detailed guide in [Developement guide](Development.md) +For the development setup, you can follow the detailed guide in [Developement guide](Development.md) Read [CONTRIBUTING](CONTRIBUTING.md) guide. @@ -100,11 +112,12 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d swastik suvam singh
swastik suvam singh

💻 GavinZhengOI
GavinZhengOI

📖 - lmgyuan
lmgyuan

📖 + lmgyuan
lmgyuan

📖 🐛 💻 🤔 👀 ⚠️ pierrick-boule
pierrick-boule

💻 ⚠️ 📖 Dhairya Majmudar
Dhairya Majmudar

🐛 + Mintu Gogoi
Mintu Gogoi

🐛 💻 🤔 📖 👀 ⚠️ diff --git a/apps/generator/.gitignore b/apps/generator/.gitignore index 4c5f72e17..ff229014e 100644 --- a/apps/generator/.gitignore +++ b/apps/generator/.gitignore @@ -19,3 +19,4 @@ test/temp/reactTemplate test/test-project/package-lock.json test/test-project/verdaccio/storage/ test/test-project/storage/ +__transpiled diff --git a/apps/generator/CHANGELOG.md b/apps/generator/CHANGELOG.md index 2ead8e4ea..9f0a59603 100644 --- a/apps/generator/CHANGELOG.md +++ b/apps/generator/CHANGELOG.md @@ -1,5 +1,23 @@ # @asyncapi/generator +## 2.6.0 + +### Minor Changes + +- fd5dfd7: - **Deprecation of `ag` CLI**: The `ag` CLI is deprecated in favour of the `AsyncAPI CLI` that is a single entry point for all the AsyncAPI tools. No new features will be added to `ag` and it will be completely removed. The official documentation of AsyncAPI Generator has not mentioned `ag` for over a year, instead only using `AsyncAPI CLI` and `asyncapi generate fromTemplate` commands. Refer to the [migration guide](https://www.asyncapi.com/docs/tools/generator/migration-cli) that will help you understand how to migrate your `ag` commands to the new `AsyncAPI CLI` command. + + - **Deprecation of Nunjucks render engine:** The [Nunjucks render engine](https://www.asyncapi.com/docs/tools/generator/nunjucks-render-engine) is deprecated and will be removed in October 2025. It is recommended to switch to the [React render engine](https://www.asyncapi.com/docs/tools/generator/react-render-engine) instead. If you are using Nunjucks in production, read the [migration guide](https://www.asyncapi.com/docs/tools/generator/migration-nunjucks-react) that will help you understand how to migrate to the new engine. The removal of the Nunjucks render engine results also in removal of [Nunjucks-filters](apps/nunjucks-filters) library. + + Removal of both deprecated parts of the generator is planned for October 2025, which gives you 9 months to migrate. + +## 2.5.0 + +### Minor Changes + +- 2d16234: - Package `@asyncapi/generator-hooks` is now part of `generator` repo and won't be released separately. Theource code is stored under `apps/hooks` but the `package/library` name stays as it was originally for backward compatibility, + - By default, the `@asyncapi/generator-hooks` package, known as **package** contains many different hooks used in templates and is available in the generator. You no longer have to configure it in your `package.json` in `dependencies`. The package, `@asyncapi/generator-hooks` will no longer be published to NPM separately and is deprecated. You can still have your own hooks, store them in a separate package, and configure them with your template. + - Remember that the fact that the hooks package is now included by default, doesn't mean all hooks from it are enabled by default. You still have to enable a given hook in the configuration file explicitly because some hooks can execute automatically without passing a specific parameter. Also, a hook's supported parameters need to be defined in your template's config. + ## 2.4.1 ### Patch Changes diff --git a/apps/generator/cli.js b/apps/generator/cli.js index feb12446a..ffae4b0f8 100755 --- a/apps/generator/cli.js +++ b/apps/generator/cli.js @@ -89,10 +89,17 @@ program .option('-o, --output ', 'directory where to put the generated files (defaults to current directory)', parseOutput, process.cwd()) .option('-p, --param ', 'additional param to pass to templates', paramParser) .option('--force-write', 'force writing of the generated files to given directory even if it is a git repo with unstaged files or not empty dir (defaults to false)') + .option('--disable-warning', 'disable "ag" deprecation warning (defaults to false)') .option('--watch-template', 'watches the template directory and the AsyncAPI document, and re-generate the files when changes occur. Ignores the output directory. This flag should be used only for template development.') .option('--map-base-url ','maps all schema references from base url to local folder',mapBaseUrlParser) .parse(process.argv); +if (!program.disableWarning) { + console.warn(yellow( + 'Warning: The "ag" CLI is deprecated and will be removed in a future release. Please use the AsyncAPI CLI instead. See release notes for details: https://github.com/asyncapi/generator/releases/tag/%40asyncapi%2Fgenerator%402.6.0. You can hide this working using --disable-warning flag.') + ); +} + if (!asyncapiDocPath) { console.error(red('> Path or URL to AsyncAPI file not provided.')); program.help(); // This exits the process diff --git a/apps/generator/docs/api.md b/apps/generator/docs/api.md index b59a87e33..3dd56e79e 100644 --- a/apps/generator/docs/api.md +++ b/apps/generator/docs/api.md @@ -13,6 +13,7 @@ Reference API documentation for AsyncAPI Generator library. * [Generator](#Generator) * [new Generator(templateName, targetDir, options)](#new_Generator_new) * _instance_ + * [.compile](#Generator+compile) : `Boolean` * [.registry](#Generator+registry) : `Object` * [.templateName](#Generator+templateName) : `String` * [.targetDir](#Generator+targetDir) : `String` @@ -38,9 +39,9 @@ Reference API documentation for AsyncAPI Generator library. * [.executeAfterHook()](#Generator+executeAfterHook) ⇒ `Promise.` * [.parseInput()](#Generator+parseInput) * [.configureTemplate()](#Generator+configureTemplate) - * ~~[.generateFromString(asyncapiString, [parseOptions])](#Generator+generateFromString) ⇒ `Promise`~~ - * [.generateFromURL(asyncapiURL)](#Generator+generateFromURL) ⇒ `Promise` - * [.generateFromFile(asyncapiFile)](#Generator+generateFromFile) ⇒ `Promise` + * ~~[.generateFromString(asyncapiString, [parseOptions])](#Generator+generateFromString) ⇒ `Promise.<(TemplateRenderResult|undefined)>`~~ + * [.generateFromURL(asyncapiURL)](#Generator+generateFromURL) ⇒ `Promise.<(TemplateRenderResult|undefined)>` + * [.generateFromFile(asyncapiFile)](#Generator+generateFromFile) ⇒ `Promise.<(TemplateRenderResult|undefined)>` * [.installTemplate([force])](#Generator+installTemplate) * _static_ * [.getTemplateFile(templateName, filePath, [templatesDir])](#Generator.getTemplateFile) ⇒ `Promise` @@ -64,6 +65,7 @@ Instantiates a new Generator object. - [.forceWrite] `Boolean` ` = false` - Force writing of the generated files to given directory even if it is a git repo with unstaged files or not empty dir. Default is set to false. - [.install] `Boolean` ` = false` - Install the template and its dependencies, even when the template has already been installed. - [.debug] `Boolean` ` = false` - Enable more specific errors in the console. At the moment it only shows specific errors about filters. Keep in mind that as a result errors about template are less descriptive. + - [.compile] `Boolean` ` = true` - Whether to compile the template or use the cached transpiled version provided by template in '__transpiled' folder - [.mapBaseUrlToFolder] `Object.` - Optional parameter to map schema references from a base url to a local base folder e.g. url=https://schema.example.com/crm/ folder=./test/docs/ . - [.registry] `Object` - Optional parameter with private registry configuration - [.url] `String` - Parameter to pass npm registry url @@ -85,6 +87,13 @@ const generator = new Generator('@asyncapi/html-template', path.resolve(__dirnam }); ``` + + +* generator.compile : `Boolean`** : +Whether to compile the template or use the cached transpiled version provided by template in '__transpiled' folder. + +**Kind**: instance property of [`Generator`](#Generator) + * generator.registry : `Object`** : diff --git a/apps/generator/docs/configuration-file.md b/apps/generator/docs/configuration-file.md index c11cfd00e..dda21e983 100644 --- a/apps/generator/docs/configuration-file.md +++ b/apps/generator/docs/configuration-file.md @@ -20,7 +20,7 @@ The `generator` property from `package.json` file must contain a JSON object tha |`nonRenderableFiles`| [String] | A list of file paths or [globs](https://en.wikipedia.org/wiki/Glob_(programming)) that must be copied "as-is" to the target directory, i.e., without performing any rendering process. This is useful when you want to copy binary files. |`generator`| [String] | A string representing the generator version-range the template is compatible with. This value must follow the [semver](https://nodejs.dev/learn/semantic-versioning-using-npm) syntax. E.g., `>=1.0.0`, `>=1.0.0 <=2.0.0`, `~1.0.0`, `^1.0.0`, `1.0.0`, etc. [Read more about semver](https://docs.npmjs.com/about-semantic-versioning). |`filters`| [String] | A list of modules containing functions that can be used as Nunjucks filters. In case of external modules, remember they need to be added as a dependency in `package.json` of your template. -|`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 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 you must pass an array of strings. In case of external modules, remember they need to be added as a dependency in `package.json` of your template. +|`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. ### Example @@ -64,7 +64,8 @@ The `generator` property from `package.json` file must contain a JSON object tha "my-package-with-filters" ], "hooks": { - "@asyncapi/generator-hooks": "hookFunctionName" + "@asyncapi/generator-hooks": "hookFunctionName", + "my-custom-hooks-package": ["myHook", "andAnotherOne"] } } ``` diff --git a/apps/generator/docs/file-templates.md b/apps/generator/docs/file-templates.md index 7a7a8ce77..2b5c05431 100644 --- a/apps/generator/docs/file-templates.md +++ b/apps/generator/docs/file-templates.md @@ -7,6 +7,8 @@ weight: 140 > **Note**: This section applies only to the Nunjucks render engine. For information on using the React render engine, refer to the [Generating files with the React render engine](#generating-files-with-the-react-render-engine) section below. +> **Note**: Nunjucks renderer engine is deprecated and will be removed in the future. Use the React renderer engine instead. For more details read notes from release [@asyncapi/generator@2.6.0](https://github.com/asyncapi/generator/releases/tag/%40asyncapi%2Fgenerator%402.6.0). + It is possible to generate files for each specific object in your AsyncAPI documentation using the Nunjucks render engine. For example, you can specify a filename like `$$channel$$.js` to generate a file for each channel defined in your AsyncAPI. The following file-template names and extra variables are available: - `$$channel$$`, within the template-file you have access to two variables [`channel`](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#channel) and [`channelName`](https://github.com/asyncapi/parser-api/blob/master/docs/api.md#channels). Where the `channel` contains the current channel being rendered. diff --git a/apps/generator/docs/hooks.md b/apps/generator/docs/hooks.md index d2c06ddc0..422ff2191 100644 --- a/apps/generator/docs/hooks.md +++ b/apps/generator/docs/hooks.md @@ -4,21 +4,26 @@ weight: 130 --- Hooks are functions called by the generator on a specific moment in the generation process. Hooks can be anonymous functions but you can also add function names. These hooks can have arguments provided to them or being expected to return a value. + +## Types + The following types of hooks are currently supported: |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](https://github.com/asyncapi/generator/blob/master/docs/api.md) -| `generate:after` | Called at the very end of the generation. | void : Nothing is expected to be returned. | [The generator instance](https://github.com/asyncapi/generator/blob/master/docs/api.md) -| `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](https://github.com/asyncapi/generator/blob/master/docs/api.md) 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 : 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 }` + +## Location The generator parses: - All the files in the `.hooks` directory inside the template. -- All modules listed in the template configuration and triggers only hooks that names were added to the config. You can use the official AsyncAPI [hooks library](https://github.com/asyncapi/generator-hooks). To learn how to add hooks to configuration [read more about the configuration file](https://www.asyncapi.com/docs/tools/generator/configuration-file). +- All modules listed in the template configuration and triggers only hooks whose names were added to the config. You can use an [official hooks library](#official-library) that is bundled together with the generator. To learn how to add hooks to configuration [read more about the configuration file](configuration-file). -### Examples +## Examples -> Some of the examples have names of hook functions provided and some not. Keep in mind that hook functions kept in template in default location do not require a name. Name is required only if you keep hooks in non default location or in a separate library, because such hooks need to be explicitly configured in the configuration file. For more details on hooks configuration [read more about the configuration file](https://www.asyncapi.com/docs/tools/generator/configuration-file). +> Some of the examples have names of hook functions provided and some not. Keep in mind that hook functions kept in template in default location do not require a name. Name is required only if you keep hooks in non default location or in a separate library, because such hooks need to be explicitly configured in the configuration file. For more details on hooks configuration [read more about the configuration file](configuration-file). Most basic modules with hooks look like this: ```js @@ -79,3 +84,35 @@ module.exports = { }; }; ``` + +## Official library + +It is a library of reusable hooks that you can use in your templates. You only have to add its name to the configuration: `@asyncapi/generator-hooks` and specify which hook you want to enable. + +This library consists of the following hooks: +|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 | + +1. In your template configuration in `package.json` specify you want to use this library and what hook exactly: + ```json + { + "generator": { + "hooks": { + "@asyncapi/generator-hooks": "createAsyncapiFile" + } + } + } + ``` +1. Some hooks support custom parameters that template's user can use to specify different behaviour of the hook. To enable these, you need to also add them to the list of your template's parameters: + ```json + { + "generator": { + "parameters": { + "asyncapiFileDir": { + "description": "This template by default also outputs the AsyncAPI document that was passed as input. You can specify with this parameter what should be the location of this AsyncAPI document, relative to specified template output." + } + } + } + } + ``` \ No newline at end of file diff --git a/apps/generator/docs/migration-cli.md b/apps/generator/docs/migration-cli.md new file mode 100644 index 000000000..c51c5f1d7 --- /dev/null +++ b/apps/generator/docs/migration-cli.md @@ -0,0 +1,70 @@ +--- +title: "Migrating from `ag` CLI to AsyncAPI CLI" +weight: 260 +--- + +This guide provides detailed instructions on how to transition from the old `ag` Generator CLI to the new AsyncAPI CLI. + +## Options Overview + +Here is a list of `ag` options and their equivalents in the AsyncAPI CLI: + +- **-d, --disable-hook [hooks...]** + - **AsyncAPI CLI equivalent:** `asyncapi generate fromTemplate