Extend a Turborepo with code generation utilities for creating workspaces and custom generators
npx @tessl/cli install tessl/npm-turbo--gen@2.5.0Turbo 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.
npm install @turbo/genimport 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";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-packageimport { workspace } from "@turbo/gen/dist/commands";
// Create a new workspace programmatically
await workspace({
name: "my-new-package",
type: "package",
empty: true,
showAllDependencies: false
});Turbo Gen is structured around several key components:
run, workspace, raw)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>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>;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>;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>;// Re-exported from node-plop for generator configuration
export type { PlopTypes };
type WorkspaceType = "app" | "package";
interface CopyData {
type: "internal" | "external";
source: string;
}interface TurboGeneratorArguments {
project: Project;
opts: TurboGeneratorOptions;
}
interface CustomGeneratorArguments {
generator: string | undefined;
project: Project;
opts: CustomGeneratorCLIOptions;
}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);
}