⌘K

Nativeblocks Compiler

This document describes the functionality of the NativeblocksCompiler executable, its associated plugins, and how to use them effectively in your development workflow.


Plugins Description

The NativeblocksCompiler includes three key plugins to streamline your development tasks:

  1. GenerateProvider Plugin: Automates the creation of TargetActionProvider.swift and TargetBlockProvider.swift for specified targets.
  2. Sync Plugin: Synchronizes local JSON files of Blocks and Actions with the Nativeblocks Studio.
  3. PrepareSchema Plugin: Prepares JSON schemas and saves them locally in the .nativeblocks directory.

Plugins Overview

The NativeblocksCompiler integrates with plugins defined in Swift Package Manager. These plugins expose the commands for use directly within Xcode or the command line.

Available Plugins

1. GenerateProvider Plugin

  • Name: GenerateProvider
  • Description: Generates provider files in the source root.
  • Command Capability:
  • Verb: GenerateProvider
  • Description: "Generate Provider"
  • Permissions:
  • Writes to the package directory.
  • Dependencies:
  • Depends on the NativeblocksTool target.

How to use

  1. Project(Right click) -> NativeblocksCompiler Choose GenerateProvider

  2. Select Target

  3. Add TagetBlockProvider.swift to Target

  4. Use providers after init nativeblocks sdk

  TargetBlockProvider.provideBlocks()
  TargetActionProvider.provideActions()

2. Sync Plugin

  • Name: Sync
  • Description: Synchronizes data with the Nativeblocks server.
  • Command Capability:
  • Verb: Sync
  • Description: "Sync"
  • Permissions:
  • Writes to the package directory.
  • Allows network connections to sync JSON files.
  • Dependencies:
  • Depends on the NativeblocksTool target.

How to use

  1. Add a nativeblocks.json

To use the Sync plugin, you must add a nativeblocks.json file to the root of your project. This file should contain the following structure:

{
    "endpoint": "",
    "authToken": "",
    "organizationId": ""
}

You can download this file from Nativeblocks Studio.

  1. Project(Right click) -> NativeblocksCompiler Choose Sync

  2. Select Target

3. PrepareSchema Plugin

  • Name: PrepareSchema
  • Description: Prepares JSON schemas.
  • Command Capability:
  • Verb: PrepareSchema
  • Description: "Prepare Schema"
  • Permissions:
  • Writes to the package directory.
  • Dependencies:
  • Depends on the NativeblocksTool target.

How to use

  1. Project(Right click) -> NativeblocksCompiler Choose PrepareSchema

  2. Select Target

  3. it will generate in the .nativeblocks directory

NativeblocksTool Overview

The NativeblocksTool serves as a command-line utility to facilitate various operations related to Nativeblocks development. It processes inputs, generates required outputs, and integrates seamlessly with plugins for extended capabilities.

Features

  • Provider Generation: Automates the creation of providers based on input files.
  • Schema Preparation: Generates JSON schema files for integration.
  • Synchronization: Uploads JSON blocks and actions to a remote server.

Key Commands

1. Generate Provider

  • Command: generate-provider
  • Description: Generates a provider for a specified target using input files. This command will generate TargetActionProvider.swift and TargetBlockProvider.swift from the Block and Action macros.

2. Prepare Schema

  • Command: prepare-schema
  • Description: Prepares JSON schemas based on input files. This command will generate local JSON files of Blocks and Actions in the .nativeblocks directory.

3. Sync

  • Command: sync
  • Description: Synchronizes generated JSON blocks and actions with a remote server. This command will generate JSON files and upload Blocks and Actions to the Nativeblocks Studio.

How PrepareSchema Works

Command Execution Flow

  1. Arguments Parsing:
  • The tool extracts commands and arguments from the input.
  • Arguments include --target, --directory, --endpoint, --authToken, and --organizationId.
  1. Validation:
  • Validates required arguments (e.g., directory existence, non-empty targets).
  • Ensures commands like sync have necessary credentials (e.g., endpoint, authToken).
  1. Execution:
  • Executes specific logic based on the parsed commands.
  • For example:
  • generate-provider: Uses the ProviderGenerator class to create and save providers.
  • prepare-schema: Uses the JsonGenerator class to generate and save schemas.
  • sync: Uploads data using the JsonUploader class.

Example Usage

Generate Provider

nativeblocks-tool generate-provider --target MyTarget --directory ./inputs

Prepare Schema

nativeblocks-tool prepare-schema --directory ./inputs

Sync

nativeblocks-tool sync --directory ./inputs --endpoint https://example.com --authToken my-auth-token --organizationId my-org-id

Workflow Integration

  1. Setup:
  • Include NativeblocksTool and its plugins in your Swift Package.
  1. Run Commands:
  • Use the appropriate plugin or command-line arguments to execute tasks.
  1. Automate:
  • Integrate the commands and plugins into your CI/CD pipeline for streamlined development and deployment.