Docs

Docs

  • Try Bit next-gen (beta) ⮕
  • Docs
  • Tutorials
  • Guides
  • Github

›Extending Bit

Introduction

  • Quick Start
  • Installation
  • How bit Works?
  • Bit Workspace
  • FAQ

Components

  • Tracking
  • Compiling
  • Testing
  • Versioning
  • Documenting
  • Exporting
  • Removing & Deprecating
  • Installing
  • Importing
  • Viewing

Advanced

  • Dependencies
  • Overrides
  • CI & Deployment
  • Bit Server

bit.dev

  • Functionality
  • Account
  • Authentication

Reference

  • Bit Client Configuration
  • Workspace Configuration
  • CLI Commands
  • Usage Analytics

Extending Bit

  • Extending Bit
  • Using Extensions
  • Developing Extensions
  • Build a compiler
  • Build a tester
Edit

Using Extensions

Using extensions is fairly straightforward. Let's learn how!

Importing an extension

In order to use an extension, just import it from bit.dev or another remote scope:

bit import bit.extensions/commands/pack --extension

Configuration and options

Extensions' configuration and options are part of the bit config.

{
  "extensions": {
    "ext-docs-parser": {
        "rawConfig": {},
        "options": {
            "core": true
        }
    }
}

Options

System-wide options that are relevant for every Bit extension.

  • core - Determines whether the extension is a core extension (bool).
  • disabled - When true, Bit won't load the extension (bool).
  • file - A path to the extension's main file. The file path is relative to the working directory's location, or an absolute path. When provided, Bit will load the extension from this path, and not from the usual location.

Configuration

Contains all the configuration the extension needs. Unlike the system options, the configuration is used for the usage of the specific extension.

Load an extension programmatically

You can also load an extension programmatically:

loadExtension: async (
   extensionName: string,
   extensionFilePath: string,
   extensionConfig: Object,
   extensionOptions: Object
 ): Extension

loadExtension returns an instance of Extension:

{
  name: string,
  loaded: boolean,
  disabled: boolean,
  filePath: string,
  registeredHooksActions: RegisteredHooksActions,
  newHooks: string[],
  commands: Commands,
  rawConfig: Object,
  options: Object,
  dynamicConfig: Object,
  script: Function, // Store the required plugin
  api
}

Here's an example:

const bit = require('bit-bin');

const extensionName = 'bit-npm-pack';
const extensionFilePath =
  '/Users/giladshoham/dev/temp/pluginTest/dist/bit-pack';
const extensionConfig = {
  rawConfigKey: 'rawConfigVal',
};

bit
  .loadExtension(extensionName, extensionFilePath, extensionConfig)
  .then((extension) => {
    console.log(extension.loaded);
    const packCommand = extension.commands.find((cmd) => {
      return cmd.name.indexOf('plugin-pack') > -1;
    });
    packCommand.action(
      [
        'scoop/plugin-test/component',
        '/Users/giladshoham/dev/temp/pluginTest/scoop',
      ],
      { outDir: '/Users/giladshoham/dev/temp/pluginTest' }
    );
  })
  .catch((err) => {
    console.log(err);
  });

Storage

Imported extensions are stored in .bit/components/extensions directory.

← Extending BitDeveloping Extensions →
  • Importing an extension
  • Configuration and options
    • Options
    • Configuration
  • Load an extension programmatically
  • Storage
Docs
bit.dev
bit.devSupportTerms and PrivacySLA
Community
SlackTwitter
More
Star
Copyright © 2022 bit.dev