-
-
Notifications
You must be signed in to change notification settings - Fork 232
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
fix: add the migration guide and nunjucks depreciation notes #1253
base: master
Are you sure you want to change the base?
Changes from all commits
461877d
13a3a70
1e339c7
1399f23
8dbeef8
1035a3d
347fc17
826f203
3228c57
3f5c7fd
4c5344f
4182ca5
af8cff7
cc50175
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,5 @@ | ||||||
--- | ||||||
"@asyncapi/generator": major | ||||||
--- | ||||||
|
||||||
Migrating from Nunjucks render engine to React render engine | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,139 @@ | ||||||||||||
-- | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please rename file, the document focus not on deprecation but on migration
|
||||||||||||
title: "Migrating from Nunjucks to React render engine" | ||||||||||||
weight: 170 | ||||||||||||
--- | ||||||||||||
|
||||||||||||
## Migration Guide from nunjucks render engine to react render engine | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove
Suggested change
@Florence-Njeri @Gmin2 below you can see a preview from website, how would this document render - we would have strange duplication. |
||||||||||||
|
||||||||||||
### Introduction | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
when you see other generator docs, we don't write "introduction" we just write it without heading
we can of course change it if you think it is wrong, but then it should be a followup PR that unifies approach in all generator docs |
||||||||||||
|
||||||||||||
The asyncAPI generator is moving away from Nunjucks templates in favor of React templates. This guide will help you migrate your existing Nunjucks templates to React. For a comprehensive understanding of why we introduced React as an alternative in 2021 and why we're now removing Nunjucks entirely, please read our article [React as a Generator Engine](https://www.asyncapi.com/blog/react-as-generator-engine). The principles discussed in this article still apply to our current transition. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
### Step-by-step migration guide | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably because of my previous comments you will have to do changes to heading sizes, and start this from "##" and update the rest as well |
||||||||||||
|
||||||||||||
#### 1. Update package.json | ||||||||||||
|
||||||||||||
Change your template configuration in `package.json`: | ||||||||||||
|
||||||||||||
```json | ||||||||||||
{ | ||||||||||||
"generator": { | ||||||||||||
"renderer": "react" | ||||||||||||
} | ||||||||||||
} | ||||||||||||
``` | ||||||||||||
|
||||||||||||
Once the deprecation period has ended, and we remove the default Nunjucks, the React render engine will be used by default and this setting will no longer be needed to configure | ||||||||||||
|
||||||||||||
#### 2. Install dependencies | ||||||||||||
|
||||||||||||
Install the necessary React dependencies: | ||||||||||||
|
||||||||||||
```bash | ||||||||||||
npm install @asyncapi/generator-react-sdk | ||||||||||||
``` | ||||||||||||
|
||||||||||||
#### 3. File naming | ||||||||||||
|
||||||||||||
In Nunjucks, the template's filename directly corresponds to the output file. For example, a template named index.html will generate an index.html file. | ||||||||||||
|
||||||||||||
In React, the filename of the generated file is not controlled by the file itself, but rather by the File component. The React component itself can be named anything with a `.js` extension, but the output file is controlled by the `name` attribute of the File component: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see nunjucks: |
||||||||||||
|
||||||||||||
#### 4. Basic template structure | ||||||||||||
|
||||||||||||
Nunjucks: | ||||||||||||
```js | ||||||||||||
<h1>{{ asyncapi.info().title() }}</h1> | ||||||||||||
<p>{{ asyncapi.info().description() }}</p> | ||||||||||||
``` | ||||||||||||
|
||||||||||||
React: | ||||||||||||
```js | ||||||||||||
import { File } from '@asyncapi/generator-react-sdk'; | ||||||||||||
|
||||||||||||
export default function({ asyncapi }) { | ||||||||||||
return ( | ||||||||||||
<File name="index.html"> | ||||||||||||
<h1>{asyncapi.info().title()}</h1> | ||||||||||||
<p>{asyncapi.info().description()}</p> | ||||||||||||
</File> | ||||||||||||
); | ||||||||||||
} | ||||||||||||
``` | ||||||||||||
|
||||||||||||
#### 5. Macros and Partials | ||||||||||||
|
||||||||||||
Replace macros with React components: | ||||||||||||
|
||||||||||||
Nunjucks: | ||||||||||||
```js | ||||||||||||
{% macro renderChannel(channel) %} | ||||||||||||
<div class="channel"> | ||||||||||||
<h3>{{ channel.address() }}</h3> | ||||||||||||
<p>{{ channel.description() }}</p> | ||||||||||||
</div> | ||||||||||||
{% endmacro %} | ||||||||||||
|
||||||||||||
{{ renderChannel(someChannel) }} | ||||||||||||
``` | ||||||||||||
|
||||||||||||
React: | ||||||||||||
```js | ||||||||||||
// components/Channel.js | ||||||||||||
import { Text } from '@asyncapi/generator-react-sdk'; | ||||||||||||
|
||||||||||||
export function Channel({ channel }) { | ||||||||||||
return ( | ||||||||||||
<Text> | ||||||||||||
<div className="channel"> | ||||||||||||
<h3>{channel.address()}</h3> | ||||||||||||
<p>{channel.description()}</p> | ||||||||||||
</div> | ||||||||||||
</Text> | ||||||||||||
); | ||||||||||||
} | ||||||||||||
|
||||||||||||
// Main template | ||||||||||||
import { File, Text } from '@asyncapi/generator-react-sdk'; | ||||||||||||
import { Channel } from './components/Channel'; | ||||||||||||
|
||||||||||||
export default function({ asyncapi }) { | ||||||||||||
return ( | ||||||||||||
<File name="channels.html"> | ||||||||||||
<Text> | ||||||||||||
<h2>Channels</h2> | ||||||||||||
</Text> | ||||||||||||
{asyncapi.channels().map(channel => ( | ||||||||||||
<Channel channel={channel} /> | ||||||||||||
))} | ||||||||||||
</File> | ||||||||||||
); | ||||||||||||
} | ||||||||||||
``` | ||||||||||||
|
||||||||||||
#### 6. File template | ||||||||||||
|
||||||||||||
The detailed guide on file template can be found in [this](file-templates.md) guide. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
links always should be descriptive for accessibility reasons - the screen reader would only read "this" to the reader, which basically means nothing for the reader with sight disabilities. |
||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
totally new section that I think is important to have, to safe people time |
||||||||||||
### Additional Resources and Information | ||||||||||||
|
||||||||||||
#### Template Examples | ||||||||||||
For a complete example of React features in use, please refer to the [AsyncAPI Template for Generator Templates](https://github.com/asyncapi/template-for-generator-templates). The `master` branch demonstrates all React features, while the `nunjucks` branch shows the old Nunjucks implementation. This comparison can be particularly helpful in understanding the differences and migration process. | ||||||||||||
|
||||||||||||
#### Filters to Helpers | ||||||||||||
If you've been using Nunjucks filters placed in the `filters` directory, you can still use this functionality in React. However, they should be treated as normal functions that you import into your components. We recommend renaming the `filters` directory to `helpers` to better reflect their new usage in React. | ||||||||||||
|
||||||||||||
#### Hooks Remain Unchanged | ||||||||||||
It's important to note that hooks remain unchanged in this migration process. Hooks are not related to the render engine functionality, so you can continue to use them as you have been. | ||||||||||||
|
||||||||||||
### Testing your migration | ||||||||||||
|
||||||||||||
After migrating, test your template thoroughly: | ||||||||||||
|
||||||||||||
1. Run the generator using your new React template | ||||||||||||
2. Compare the output with the previous Nunjucks template output | ||||||||||||
3. Check for any missing or incorrectly rendered content | ||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
### Conclusion | ||||||||||||
|
||||||||||||
Migrating from Nunjucks to React templates may require some initial effort, but it will result in more maintainable. You can learn more about why we introduced ther React render engine [here](https://www.asyncapi.com/blog/react-as-generator-engine) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Gmin2 when you apply this change, please also improve the list - as per my other comment about links |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ weight: 120 | |
--- | ||
|
||
[Nunjucks](https://mozilla.github.io/nunjucks) is the default render engine, however, we strongly recommend adopting the [React](#react) engine. | ||
> **Note**: Nunjucks renderer engine will be depreciated in the future release and we strongly recommend using the react renderer engine instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it should be warning @Florence-Njeri ? probably in few months we should even consider removing any nunjucks mention from the docs, other than migration guide - but that is for later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Gmin2 make it clear that it is not that "nunjucks will be deprecated in the future releases", basically when people will see this text in docs, it means deprecation is in place already, and in future releases we will remove it |
||
|
||
### Common assumptions | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ const nunjucksFilters = require('@asyncapi/nunjucks-filters'); | |
|
||
/** | ||
* Registers all template filters. | ||
* @deprecated since version 3.0 | ||
* @param {Object} nunjucks Nunjucks environment. | ||
* @param {Object} templateConfig Template configuration. | ||
* @param {String} templateDir Directory where template is located. | ||
|
@@ -21,6 +22,7 @@ module.exports.registerFilters = async (nunjucks, templateConfig, templateDir, f | |
|
||
/** | ||
* Registers the local template filters. | ||
* @deprecated since version 3.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have assumed this to be included in the next major release, is this fine @derberg ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no it won't, so we cannot predict version of the release since it is deprecated just write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if jsdocs allows it, please use a link, and text specifying that more info someone can find in https://www.asyncapi.com/docs/tools/generator/nunjucks-react-migration |
||
* @private | ||
* @param {Object} nunjucks Nunjucks environment. | ||
* @param {String} templateDir Directory where template is located. | ||
|
@@ -68,6 +70,7 @@ function registerLocalFilters(nunjucks, templateDir, filtersDir) { | |
|
||
/** | ||
* Registers the additionally configured filters. | ||
* @deprecated since version 3.0 | ||
* @private | ||
* @param {Object} nunjucks Nunjucks environment. | ||
* @param {String} templateDir Directory where template is located. | ||
|
@@ -112,6 +115,7 @@ async function registerConfigFilters(nunjucks, templateDir, templateConfig) { | |
|
||
/** | ||
* Add filter functions to Nunjucks environment. Only owned functions from the module are added. | ||
* @deprecated since version 3.0 | ||
* @private | ||
* @param {Object} nunjucks Nunjucks environment. | ||
* @param {Object} filters Module with functions. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not a major release, otherwise we would use
!
in the PR title prefix.Major is when we introduce breaking changes - and here are no breaking changes, we just need to release
minor
to make sure added deprecation notes are visible to the user in the distro.