Add Component


The blocklet add command adds a new component as a dependency to your blocklet. It automatically updates the components section of your blocklet.yml file with the necessary configuration.

This command simplifies dependency management by fetching the component's metadata from a specified blocklet store or a direct URL, ensuring that all required information is correctly added to your project configuration.

Command Syntax#

The basic syntax for the add command is as follows:

blocklet add <component> [options]

Arguments#

<component>
string
required

The identifier for the component you want to add. This can be specified in several formats: - By Name and Version: component-name@1.2.3. If the version is omitted (e.g., component-name), it defaults to latest. - By DID: z8... (The decentralized identifier of the blocklet). - By URL: A direct URL to the component's blocklet.json metadata file (e.g., https://example.com/path/to/blocklet.json).

Options#

The following options are available to customize how the component is added:

--store <url>
string

Specifies the URL of the blocklet store to search for the component. If not provided, the command uses the store configured in your Blocklet CLI profile, falling back to the default official blocklet store.

--title <title>
string

Sets a custom title for the component in your blocklet.yml. If omitted, the title from the component's own metadata will be used.

--mount-point <path>
string

Defines the URL path where the component will be mounted. If not specified, a default mount point is generated based on a URL-friendly version of the component's name (e.g., /component-name).

--profile <name>
string

Selects a specific configuration profile to use for settings like the default blocklet store.

Usage Examples#

Here are some practical examples of how to use the blocklet add command.

Add a Component from the Default Store#

To add the latest version of a component named did-wallet from the default blocklet store:

blocklet add did-wallet

To add a specific version of the component:

blocklet add did-wallet@1.6.0

After running the command, your blocklet.yml will be updated with a new entry similar to this:

# blocklet.yml
components:
  - name: did-wallet
    title: DID Wallet
    mountPoint: /did-wallet
    source:
      store: 'https://store.blocklet.dev'
      name: did-wallet
      version: 1.6.0

Add a Component from a URL#

If the component is not in a store, you can add it directly from its metadata URL.

blocklet add https://github.com/arcblock/did-wallet/releases/download/v1.6.25/blocklet.json

This will add an entry to your blocklet.yml that points directly to the URL:

# blocklet.yml
components:
  - name: did-wallet
    title: DID Wallet
    mountPoint: /did-wallet
    source:
      url: 'https://github.com/arcblock/did-wallet/releases/download/v1.6.25/blocklet.json'

Add a Component with Custom Options#

You can override the default title and mount point for the component.

blocklet add did-wallet --title "My Custom Wallet" --mount-point "/my-wallet"

The resulting configuration in blocklet.yml will reflect these custom values:

# blocklet.yml
components:
  - name: did-wallet
    title: My Custom Wallet
    mountPoint: /my-wallet
    source:
      store: 'https://store.blocklet.dev'
      name: did-wallet
      version: latest

Summary#

The blocklet add command is a crucial tool for managing dependencies within your blocklet project. It automates the process of updating your blocklet.yml file, ensuring consistency and reducing the chance of manual errors. For removing dependencies, you can use the corresponding blocklet remove command.