CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-turbo

High-performance build system for JavaScript and TypeScript codebases with intelligent caching and task scheduling.

Pending
Overview
Eval results
Files

code-generation.mddocs/

Code Generation

Tools for generating new packages, applications, and workspace components with customizable templates and interactive prompts for rapid development setup.

Capabilities

Generate Command

Generate new applications, packages, or run custom generators with configurable templates and interactive workflows.

turbo generate [generator] [options]
turbo gen [generator] [options]        # shorthand
turbo g [generator] [options]          # shorter shorthand

# Interactive generation
turbo generate

# Generate with specific generator
turbo generate my-custom-generator

# Generate with configuration
turbo generate --config=./gen-config.js

Generate Options:

--tag <tag>                        # Generator tag/version (default: "latest")
--config <file> / -c               # Generator configuration file
--root <path> / -r                 # Repository root directory
--args <args...> / -a              # Arguments passed to generator

# Generation examples
turbo generate --tag=canary
turbo generate --config=./custom-gen.js my-generator
turbo generate my-generator --args="name=my-app" "template=react"

Usage Examples:

# Interactive generator selection
turbo generate

# Generate with specific configuration
turbo generate --config=./generators/workspace.js

# Generate with custom arguments
turbo generate my-app-generator --args="name=new-app" "framework=nextjs"

# Use canary version of generators
turbo generate --tag=canary my-generator

Workspace Generation

Create new workspaces (packages/applications) within your monorepo with template-based scaffolding.

turbo generate workspace [options]
turbo gen workspace [options]          # shorthand
turbo gen w [options]                   # shorter shorthand

# Generate empty workspace
turbo generate workspace --name=my-new-app --empty

# Generate workspace from template
turbo generate workspace --name=web-app --copy=@myorg/template-app

# Generate workspace from GitHub template
turbo generate workspace --copy="https://github.com/user/repo/tree/main/apps/example"

Workspace Options:

--name <name> / -n                 # Workspace name
--empty / -b                       # Generate empty workspace (default: true)
--copy <source> / -c               # Copy from existing workspace or GitHub URL
--destination <path> / -d          # Output destination directory
--type <type> / -t                 # Workspace type
--root <path> / -r                 # Repository root
--example-path <path> / -p         # GitHub subdirectory path
--show-all-dependencies            # Show all available dependencies

Workspace Source Types:

# Local workspace as template
--copy=@myorg/existing-app

# GitHub repository (main branch)
--copy="https://github.com/user/repo"

# GitHub repository with specific branch
--copy="https://github.com/user/repo/tree/feature-branch"

# GitHub repository with subdirectory
--copy="https://github.com/user/repo/tree/main/apps/example"

# GitHub with branch and subdirectory (use --example-path)
--copy="https://github.com/user/repo/tree/feature/branch"
--example-path="apps/example"

Usage Examples:

# Create empty React application
turbo generate workspace --name=new-react-app --type=app --empty

# Copy from existing local workspace
turbo generate workspace --name=admin-panel --copy=@myorg/web-app

# Copy from GitHub template
turbo generate workspace \
  --name=new-service \
  --copy="https://github.com/company/templates/tree/main/services/api"

# Generate library with custom destination
turbo generate workspace \
  --name=ui-components \
  --type=lib \
  --destination=packages/ui

# Copy complex GitHub template with specific path
turbo generate workspace \
  --name=mobile-app \
  --copy="https://github.com/company/templates/tree/feature/mobile" \
  --example-path="apps/react-native"

Custom Generators

Run custom generators defined in your repository or external packages.

turbo generate run [generator] [options]
turbo gen run [generator] [options]     # shorthand  
turbo gen r [generator] [options]       # shorter shorthand

# Run custom generator
turbo generate run my-component-generator

# Run with custom config and arguments
turbo generate run api-generator \
  --config=./gen/api-config.js \
  --args="service=user" "database=postgres"

Custom Generator Options:

--config <file> / -c               # Generator configuration file
--root <path> / -r                 # Repository root
--args <args...> / -a              # Arguments passed to generator

Usage Examples:

# Run component generator
turbo generate run component-generator --args="name=Button" "variant=primary"

# Run API generator with config
turbo generate run api-generator \
  --config=./generators/api.config.js \
  --args="resource=user" "crud=true"

# Run custom page generator
turbo generate run page-generator --args="route=/dashboard" "auth=required"

Generator Configuration

Configure generators through configuration files and workspace settings.

# Generator configuration file examples
./turbo/generators/config.js       # Default generator config location
./generators/custom.config.js      # Custom config file location

# Usage with configuration
turbo generate --config=./turbo/generators/workspace.js
turbo generate workspace --config=./generators/component.js

Configuration Examples:

// Example generator configuration (JavaScript)
module.exports = {
  name: 'component-generator',
  description: 'Generates React components with TypeScript',
  prompts: [
    {
      type: 'input',
      name: 'name',
      message: 'Component name:',
    },
    {
      type: 'select',
      name: 'variant',
      message: 'Component variant:',
      choices: ['basic', 'form', 'layout'],
    },
  ],
  actions: [
    {
      type: 'add',
      path: 'components/{{kebabCase name}}/{{pascalCase name}}.tsx',
      templateFile: 'templates/component.hbs',
    },
  ],
};

Generator Types

interface GenerateOptions {
  tag: string;
  generator_name?: string;
  config?: string;
  root?: string;
  args: string[];
  command?: GenerateCommand;
}

interface GenerateWorkspaceOptions {
  name?: string;
  empty: boolean;
  copy?: string;
  destination?: string;
  type?: string;
  root?: string;
  example_path?: string;
  show_all_dependencies: boolean;
}

interface GeneratorCustomOptions {
  generator_name?: string;
  config?: string;
  root?: string;
  args: string[];
}

interface GeneratorConfig {
  name: string;
  description?: string;
  prompts?: GeneratorPrompt[];
  actions: GeneratorAction[];
}

interface GeneratorPrompt {
  type: "input" | "select" | "multiselect" | "confirm";
  name: string;
  message: string;
  choices?: string[] | PromptChoice[];
  default?: any;
  validate?: (input: any) => boolean | string;
}

interface PromptChoice {
  name: string;
  value: any;
  disabled?: boolean;
}

interface GeneratorAction {
  type: "add" | "modify" | "delete";
  path: string;
  template?: string;
  templateFile?: string;
  data?: Record<string, any>;
}

interface WorkspaceTemplate {
  name: string;
  path: string;
  type: "app" | "lib" | "tool";
  framework?: string;
  language?: string;
  dependencies: string[];
}

Template System

Turbo generators support various templating approaches:

Template Engines:

  • Handlebars templates (.hbs)
  • EJS templates (.ejs)
  • Plain text with variable substitution

Built-in Helpers:

  • {{pascalCase name}} - PascalCase conversion
  • {{camelCase name}} - camelCase conversion
  • {{kebabCase name}} - kebab-case conversion
  • {{snakeCase name}} - snake_case conversion
  • {{upperCase name}} - UPPERCASE conversion

Template Variables:

  • Generator arguments passed via --args
  • User responses from interactive prompts
  • Built-in variables (workspace root, package manager, etc.)

File Operations:

  • Add new files from templates
  • Modify existing files with patches
  • Delete files and directories
  • Copy files and directory structures

Install with Tessl CLI

npx tessl i tessl/npm-turbo

docs

caching-performance.md

code-generation.md

index.md

package-management.md

remote-cache.md

system-management.md

task-execution.md

tile.json