Nativeblocks Compiler
The Nativeblocks Compiler is a powerful framework designed to streamline the creation of dynamic, reusable blocks and actions for your applications. By leveraging macros and structured plugins, Nativeblocks Compiler simplifies complex workflows, reduces boilerplate, and enhances developer productivity.
Key Features
- Macros for Blocks and Actions:
- Define reusable components with minimal effort using macros like NativeBlock and NativeAction.
- Custom Plugins:
- Automate repetitive tasks such as generating providers and preparing schemas.
- Integration with Nativeblocks Studio:
- Synchronize blocks and actions seamlessly with Nativeblocks Studio for centralized management.
- Extensible Design:
- Easily extend the framework to accommodate new features or workflows.
Getting Started
1. Install Nativeblocks Compiler
Add the Nativeblocks Compiler to your Swift project using Swift Package Manager. Include the following in your Package.swift file:
.package(url: "https://github.com/nativeblocks/nativeblocks-compiler.git", from: "1.0.0")
Include the NativeblocksCompiler and NativeblocksTool targets in your dependencies:
.target(
name: "YourProjectName",
dependencies: [
"NativeblocksCompiler",
"NativeblocksTool"
]
)
2. Define a Block
Create a reusable block using the NativeBlock macro. For example:
@NativeBlock(name: "My Text Block", keyType: "MY_TEXT", description: "A block to display text")
struct MyTextBlock: View {
@NativeBlockData(description: "The text content")
var text: String
var body: some View {
Text(text)
}
}
This will generate a block that can be reused across your application.
3. Define an Action
Create a reusable action using the NativeAction macro. For example:
@NativeAction(name: "Show Alert", keyType: "SHOW_ALERT", description: "Displays an alert with a message")
public class ShowAlert {
@NativeActionParameter
struct Parameter {
@NativeActionData(description: "Alert message")
var message: String
}
@NativeActionFunction
func callAsFunction(param: Parameter) {
print("Alert: \(param.message)")
}
}
This action can be triggered within your application to perform tasks.
4. Use the Plugins
Generate Provider
Generate provider files for your blocks and actions:
Prepare Schema
Prepare JSON schemas for blocks and actions:
Sync with Nativeblocks Studio
Synchronize blocks and actions with the Nativeblocks Studio:
Workflow Integration
- Setup:
- Include NativeblocksTool and its plugins in your Swift Package.
- Run Commands:
- Use the appropriate plugin or command-line arguments to execute tasks.
- Automate:
- Integrate the commands and plugins into your CI/CD pipeline for streamlined development and deployment.