or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli-commands.mdcustom-generators.mdgenerator-utilities.mdindex.mdworkspace-generation.md
tile.json

tessl/npm-turbo--gen

Extend a Turborepo with code generation utilities for creating workspaces and custom generators

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@turbo/gen@2.5.x

To install, run

npx @tessl/cli install tessl/npm-turbo--gen@2.5.0

index.mddocs/

Turbo Gen

Turbo Gen is a code generation tool for Turborepo monorepos that provides utilities for creating workspaces and running custom generators. It offers both a CLI interface and programmatic APIs for extending Turborepo projects with scaffolding capabilities.

Package Information

  • Package Name: @turbo/gen
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @turbo/gen

Core Imports

import type { PlopTypes } from "@turbo/gen";

For programmatic use (accessing internal APIs):

import { workspace, run, raw } from "@turbo/gen/dist/commands";
import { generate } from "@turbo/gen/dist/generators";

Basic Usage

CLI Usage

Most common usage is through the CLI:

# Run a custom generator
npx @turbo/gen run my-generator

# Create a new workspace
npx @turbo/gen workspace --name my-package --type package

# Copy existing workspace as template
npx @turbo/gen workspace --copy existing-package --name new-package

Programmatic Usage

import { workspace } from "@turbo/gen/dist/commands";

// Create a new workspace programmatically
await workspace({
  name: "my-new-package",
  type: "package",
  empty: true,
  showAllDependencies: false
});

Architecture

Turbo Gen is structured around several key components:

  • CLI Interface: Commander.js-based CLI with three main commands (run, workspace, raw)
  • Generator System: Built on node-plop for code generation with three built-in generators (custom, empty, copy)
  • Command Layer: High-level command handlers that orchestrate generator execution
  • Utility Layer: Core functionality for project management, workspace operations, and plop integration
  • Template System: Built-in templates for TypeScript and JavaScript generator configurations

Capabilities

CLI Commands

Command-line interface for running generators and creating workspaces. Provides interactive prompts and validation for all operations.

// CLI command signatures (accessed via npx @turbo/gen)
run [generator-name] --config <config> --root <dir> --args <args...>
workspace --name <name> --type <type> --empty|--copy [source] --destination <dir>
raw <type> --json <arguments>

CLI Commands

Workspace Generation

Programmatic APIs for creating new workspaces in Turborepo monorepos. Supports both empty workspace creation and copying from existing templates.

interface TurboGeneratorCLIOptions {
  name?: string;
  empty: boolean;
  copy?: string | boolean;
  destination?: string;
  type?: WorkspaceType;
  root?: string;
  examplePath?: string;
  showAllDependencies: boolean;
}

function workspace(opts: TurboGeneratorCLIOptions): Promise<void>;

Workspace Generation

Custom Generators

System for running custom plop-based generators with Turborepo integration. Supports both TypeScript and JavaScript generator configurations.

interface CustomGeneratorCLIOptions {
  config?: string;
  root?: string;
  args?: Array<string>;
}

function run(generator: string | undefined, opts: CustomGeneratorCLIOptions): Promise<void>;

Custom Generators

Generator Utilities

Core utilities for generator development including plop integration, project management, and workspace operations.

function getProject(args: { root?: string }): Promise<Project>;

function getPlop(args: {
  project: Project;
  configPath?: string;
}): NodePlopAPI | undefined;

function runCustomGenerator(args: {
  project: Project;
  generator: string;
  bypassArgs?: Array<string>;
  configPath?: string;
}): Promise<void>;

Generator Utilities

Types

Core Types

// Re-exported from node-plop for generator configuration
export type { PlopTypes };

type WorkspaceType = "app" | "package";

interface CopyData {
  type: "internal" | "external";
  source: string;
}

Generator Arguments

interface TurboGeneratorArguments {
  project: Project;
  opts: TurboGeneratorOptions;
}

interface CustomGeneratorArguments {
  generator: string | undefined;
  project: Project;
  opts: CustomGeneratorCLIOptions;
}

Error Types

type GenerateErrorType =
  | "plop_error_running_generator"
  | "plop_unable_to_load_config"
  | "plop_generator_not_found"
  | "plop_no_config"
  | "config_directory_already_exists"
  | "unknown";

class GeneratorError extends Error {
  public type: GenerateErrorType;
  constructor(message: string, opts?: GeneratorErrorOptions);
}