-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
385 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"projectId": "b4228f2e-a928-445e-83d8-6bc7a05c420e", | ||
"ignoredFiles": [ | ||
".DS_Store", | ||
".env", | ||
".archivist/", | ||
".idea/", | ||
".vscode/", | ||
"env/", | ||
"venv/", | ||
".git/", | ||
".gitignore", | ||
"__pycache__/", | ||
"__init__.py", | ||
"dist/", | ||
"node_modules/", | ||
"package-lock.json", | ||
"yarn.lock", | ||
"*.config.js", | ||
".next/" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ coverage | |
# Turbo | ||
.turbo | ||
|
||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Generator is a tool that you can use to generate whatever you want basing on the AsyncAPI specification file as an input. For more information [read the docs](https://www.asyncapi.com/docs/tools/generator). | ||
|
||
There is a large number of templates that are ready to use and are officially supported by the AsyncAPI Initiative. | ||
|
||
## List of official generator templates | ||
|
||
<!-- templates list is validated with GitHub Actions do not remove list markers --> | ||
<!-- TEMPLATES-LIST:START --> | ||
|
||
| Template Name | Description | Source code | | ||
| --------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------------------- | | ||
| `@asyncapi/nodejs-template` | Generates Nodejs service that uses Hermes package | [click here](https://github.com/asyncapi/nodejs-template) | | ||
| `@asyncapi/nodejs-ws-template` | Generates Nodejs service that supports WebSockets protocol only | [click here](https://github.com/asyncapi/nodejs-ws-template) | | ||
| `@asyncapi/java-template` | Generates Java JMS application | [click here](https://github.com/asyncapi/java-template) | | ||
| `@asyncapi/java-spring-template` | Generates Java Spring service | [click here](https://github.com/asyncapi/java-spring-template) | | ||
| `@asyncapi/java-spring-cloud-stream-template` | Generates Java Spring Cloud Stream service | [click here](https://github.com/asyncapi/java-spring-cloud-stream-template) | | ||
| `@asyncapi/python-paho-template` | Generates Python service that uses Paho library | [click here](https://github.com/asyncapi/python-paho-template) | | ||
| `@asyncapi/html-template` | Generates HTML documentation site | [click here](https://github.com/asyncapi/html-template) | | ||
| `@asyncapi/markdown-template` | Generates documentation in Markdown file | [click here](https://github.com/asyncapi/markdown-template) | | ||
| `@asyncapi/ts-nats-template` | Generates TypeScript NATS client | [click here](https://github.com/asyncapi/ts-nats-template/) | | ||
| `@asyncapi/go-watermill-template` | Generates Go client using Watermill | [click here](https://github.com/asyncapi/go-watermill-template) | | ||
| `@asyncapi/dotnet-nats-template` | Generates .NET C# client using NATS | [click here](https://github.com/asyncapi/dotnet-nats-template) | | ||
| `@asyncapi/php-template` | Generates PHP client using RabbitMQ | [click here](https://github.com/asyncapi/php-template) | | ||
| `@asyncapi/dotnet-rabbitmq-template` | Generates .NET C# client using RabbitMQ | [click here](https://github.com/asyncapi/dotnet-rabbitmq-template) | | ||
|
||
<!-- TEMPLATES-LIST:END --> | ||
|
||
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)** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
--- | ||
title: "Depreciation of nunjucks render engine" | ||
weight: 170 | ||
--- | ||
|
||
# Migration Guide from nunjucks render engine to react render engine | ||
|
||
## Introduction | ||
|
||
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. | ||
|
||
## Step-by-Step Migration Guide | ||
|
||
### 1. Update package.json | ||
|
||
Change your template configuration in `package.json`: | ||
|
||
```json | ||
{ | ||
"generator": { | ||
"renderer": "react" | ||
} | ||
} | ||
``` | ||
|
||
### 2. Install Dependencies | ||
|
||
Install the necessary React dependencies: | ||
|
||
```bash | ||
npm install @asyncapi/generator-react-sdk | ||
``` | ||
|
||
### 3. Basic Template Structure | ||
|
||
Nunjucks: | ||
```jsx | ||
<h1>{{ asyncapi.info().title() }}</h1> | ||
<p>{{ asyncapi.info().description() }}</p> | ||
``` | ||
|
||
React: | ||
```jsx | ||
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> | ||
); | ||
} | ||
``` | ||
|
||
### 4. Macros | ||
|
||
Replace macros with React components: | ||
|
||
Nunjucks: | ||
```jsx | ||
{% macro renderChannel(channel) %} | ||
<div class="channel"> | ||
<h3>{{ channel.address() }}</h3> | ||
<p>{{ channel.description() }}</p> | ||
</div> | ||
{% endmacro %} | ||
|
||
{{ renderChannel(someChannel) }} | ||
``` | ||
|
||
React: | ||
```jsx | ||
// 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 key={channel.address()} channel={channel} /> | ||
))} | ||
</File> | ||
); | ||
} | ||
``` | ||
|
||
### 5. File template | ||
|
||
//TODO: we can add a link to Florence docs once it is merged | ||
|
||
## Testing Your Migration | ||
|
||
After migrating, test your template thoroughly: | ||
|
||
1. Run the generator with your new React template | ||
2. Compare the output with the previous Nunjucks template output | ||
3. Check for any missing or incorrectly rendered content | ||
|
||
## Conclusion | ||
|
||
Migrating from Nunjucks to React templates may require some initial effort, but it will result in more maintainable. You can read why we introduced react render engine [here](https://www.asyncapi.com/blog/react-as-generator-engine) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const path = require("path"); | ||
const Generator = require("./lib/generator"); | ||
const { promises: fsPromise } = require("fs"); | ||
const reactTemplate = 'test/test-templates/react-template'; | ||
|
||
// const reactTemplate = path.resolve(__dirname, "./test/test-templates/react-template"); | ||
// console.log("reactTemplate", reactTemplate); | ||
const dummySpecPath = path.resolve(__dirname, './test/docs/dummy.yml'); | ||
|
||
async function main() { | ||
const outputDir = path.resolve(__dirname, "test/hello"); | ||
console.log("outputDir", outputDir); | ||
// await fsPromise.mkdir(outputDir, { recursive: true }); | ||
|
||
// Create temp.md.js file dynamically | ||
const tempJsContent = ` | ||
import { File, Text } from '@asyncapi/generator-react-sdk'; | ||
export default function() { | ||
return ( | ||
<File name="temp.md"> | ||
<Text>Test</Text> | ||
</File> | ||
); | ||
} | ||
`; | ||
// const reactTemplate = path.resolve(__dirname, "./test/test-templates/react-template"); | ||
console.log("reactTemplate", reactTemplate); | ||
const transpiledPath = path.join(reactTemplate, '__transpiled'); | ||
|
||
// await fsPromise.unlink(path.join(transpiledPath, 'temp.md.js')) | ||
// await fsPromise.unlink(path.join(transpiledPath, 'temp.md.js.map')) | ||
|
||
const tempJsPath = path.join(reactTemplate, "template","temp.md.js"); | ||
await fsPromise.writeFile(tempJsPath, tempJsContent); | ||
console.log("tempJsPath", tempJsPath); | ||
|
||
const generator = new Generator(reactTemplate, outputDir, { | ||
forceWrite: true, | ||
debug: true, | ||
compile: false, | ||
}); | ||
await generator.generateFromFile(dummySpecPath); | ||
|
||
// Check if temp.md is created in the output directory | ||
const tempMdPath = path.join(outputDir, "temp.md"); | ||
console.log("tempMdPath", tempMdPath); | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.