These AST libraries are used by Blueprint and .NET engines. Node.js plugins use different methods for code generation as detailed in the Node.js Plugin Events documentation.
Amplication AST libraries provide functionality for generating Abstract Syntax Trees (AST) for different programming languages in the Amplication platform. These libraries are used to generate type-safe, well-structured code for various programming languages.
The AST libraries are not intended to cover all language functionality. Instead, they focus on the elements needed to create the foundation and boilerplate code with Amplication plugins. These libraries provide the essential building blocks for generating well-structured code across different languages.When more specialized or custom code is needed, the CodeBlock can be used as a generic node that can include any code as a string. This flexibility allows you to generate both structured AST-based code and custom code blocks when necessary.
Copy
import { CodeBlock } from '@amplication/java-ast'; // or '@amplication/csharp-ast'// Create a custom code block when neededconst customLogic = new CodeBlock(` // Custom implementation that may not be supported by the AST library directly if (condition) { specialFunction(); return customResult; }`);
Amplication’s plugin architecture is built around the AST libraries. When developing plugins, you can leverage these libraries to generate code that integrates seamlessly with Amplication’s code generation process.
Using the AST libraries gives you fine-grained control over code generation while ensuring the generated code integrates correctly with the rest of the Amplication-generated codebase.