Create a component generator

Create your own component generator to speed up your development process and standardize the basic structure of new components, in terms of their source files and configuration.

Run the following command to create a new component generator:

$bit
Copiedcopy

Your component generator should have a file structure similar to this:

my-generator
files
files/composition.ts
composition.ts
files/implementation.ts
implementation.ts
files/index.ts
index.ts
files/test-file.ts
test-file.ts
index.ts
index.ts
my-generator.ts
my-generator.ts

Using component generators

Component generators are run via the envs registering them. To use your generator, follow these steps:

  1. Create a new env or use an existing one.
  2. Set the env to use the generator .
  3. Export the env and the generator to a remote scope (to test a starter locally, see the next section.)

Define the generated component configuration

The following example shows how to define the generated component configuration with a specific env (by default, a component is configured with the same env that was used to generate it):

export class CreateComponentGeneratorComponentTemplate
  implements ComponentTemplate
{
  constructor(
    readonly name = 'my-generator-name',
    readonly description = 'my wonderful generator',
    readonly hidden = false
  ) {}


/**
* define the generated component configuration 
**/
  config = {
    'teambit.node/node': {},
    'teambit.envs/envs': {
      env: 'teambit.node/node',
    },
  };

  generateFiles(context: ComponentContext): ComponentFile[] {
    // ...
  }
CopiedCopy