Back to Turborepo

@turbo/gen

apps/docs/content/docs/reference/turbo-gen.mdx

2.10.61.9 KB
Original Source

Use this package for type definitions in your Turborepo code generators.

ts
import type { PlopTypes } from "@turbo/gen"; // [!code highlight]

// [!code word:PlopTypes]
export default function generator(plop: PlopTypes.NodePlopAPI): void {
  // Create a generator
  plop.setGenerator("Generator name", {
    description: "Generator description",
    // Gather information from the user
    prompts: [
      ...
    ],
    // Perform actions based on the prompts
    actions: [
      ...
    ],
  });
}

Turborepo variables

When running generator actions, Turborepo injects a turbo object into the action answers data. This object provides information about the repository and the generator's context.

turbo.paths

VariableTypeDescription
turbo.paths.cwdstringThe current working directory when the generator was invoked.
turbo.paths.rootstringThe root directory of the Turborepo project.
turbo.paths.workspacestring | undefinedThe root directory of the workspace that contains the generator. undefined for root-level generators that are not within a workspace.

turbo.configs

An array of TurboConfig objects representing all turbo.json and turbo.jsonc files found in the repository.

Each TurboConfig object has the following shape:

PropertyTypeDescription
configobjectThe parsed contents of the Turbo configuration file.
turboConfigPathstringThe absolute path to the Turbo configuration file.
workspacePathstringThe absolute path to the workspace directory containing the configuration.
isRootConfigbooleanWhether the configuration is from the root of the monorepo.

For more information, visit the Generating code guide.