Functions:Block Store - bettyblocks/cli GitHub Wiki

Block Store

Via the Betty Block Store, you can share action functions between organizations and applications.

Introduction

It often happens that you want to share action functions with other builders or even another application of your own. This can be done by sharing action functions via the Block Store. You can publish function blocks from your functions project. Click here for more information about initializing a new function project.

Initialize a new block

New blocks can be initialized with: bb blocks new <your-block-identifier>

Example:

$ bb blocks new my-first-block

blocks/my-first-block.json created

This command will create a blocks folder in the root of your functions project and inside that folder there will be a JSON file named by the given identifier. The JSON file will have the following structure:

{
  "dependencies": [],
  "functions": [],
  "includes": []
}

dependencies

If a function in your block is using external dependencies you also need to include them in your block. For example, if you use lodash you do this as follows (there is no need to specify the version number because the CLI uses the version specified in the package.json file):

{
  "dependencies": ["lodash"],
  "functions": ["sayHello 1.0"],
  "includes": []
}

functions

A function block can contain multiple functions. The functions key inside the JSON file will accept an array of string values that should trace back to the function names and versions in your project. If you have a folder structure like functions/say-hello/1.0 you can use it as follows in your block:

{
  "dependencies": [],
  "functions": ["sayHello 1.0", "deleteMany 1.4"],
  "includes": []
}

This will create a function block that contains two functions Say Hello 1.0 and Delete Many 1.4.

includes

It is also possible to include other files or folders outside your function directory. If you use a function that is declared in another file/folder you can use the includes to add them to your block.

{
  "dependencies": ["lodash"],
  "functions": ["sayHello 1.0", "deleteMany 1.4"],
  "includes": ["./utils", "./helpers/parse-name.js"]
}

Publishing blocks

You can publish one or multiple blocks to the block store as follows:

$ bb blocks publish

? Which blocks do you want to publish? ›
◯   my-first-block
◯   my-second-block

Please note that you can switch between blocks using the ↑ and ↓ arrow keys and you can use either the spacebar or the ← and → arrow keys to (de)select a block.

After a successful publish you can view and manage your blocks in My Betty Blocks.

Dev blocks versus Released blocks

Keep in mind that publishing a block with the CLI does not immediately make it available for other builders. To make it available you need to manually release (or update) your function block in your Block Store section.

Published block functions have the following states:

  1. Dev - The block is in the Block Store but it cannot be shared with others yet.
  2. Released - The block has been released and will be available for installation based on the permissions of the block.

After installing a function block the functions will be visible in the palette of the Actions IDE for the builder to use.