CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-yeoman-generator

Rails-inspired generator system that provides scaffolding for your apps

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Yeoman Generator

Yeoman Generator is a Rails-inspired generator system that provides scaffolding for applications. It offers a comprehensive framework for building interactive command-line tools that can scaffold entire applications, copy boilerplate files, prompt users for preferences, and generate tailored project structures.

Package Information

  • Package Name: yeoman-generator
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install yeoman-generator

Core Imports

import Generator from "yeoman-generator";

For ESM with typed import:

import Generator, { type BaseOptions, type BaseFeatures, Storage } from "yeoman-generator";

For CommonJS:

const Generator = require("yeoman-generator");

Basic Usage

import Generator from "yeoman-generator";

export default class MyGenerator extends Generator {
  // Define lifecycle methods
  async prompting() {
    this.answers = await this.prompt([
      {
        type: "input",
        name: "name",
        message: "Your project name",
        default: this.appname
      }
    ]);
  }

  writing() {
    this.fs.copy(
      this.templatePath("index.js"),
      this.destinationPath("src/index.js")
    );
    
    this.renderTemplate(
      "package.json",
      "package.json",
      { name: this.answers.name }
    );
  }

  async install() {
    await this.spawnCommand("npm", ["install"]);
  }
}

Architecture

Yeoman Generator is built around several key components:

  • Generator Lifecycle: Predefined execution queues (initializing, prompting, configuring, default, writing, transform, conflicts, install, end)
  • Mixin System: Functional mixins that extend the base generator with specialized capabilities
  • File System: mem-fs-editor integration for in-memory file operations with conflict resolution
  • Configuration Storage: Persistent storage system using JSON files for user preferences and project configuration
  • Task System: Queue-based task execution with custom priorities and composition support
  • User Interaction: Inquirer.js integration for interactive prompts with storage and prefilling

Capabilities

Core Generator System

The foundational Generator class and lifecycle management system that orchestrates the entire scaffolding process.

export default class Generator<
  O extends BaseOptions = BaseOptions,
  F extends BaseFeatures = BaseFeatures
> extends BaseGenerator<O, F> {
  constructor(options: O, features?: F);
  constructor(args: string[], options: O, features?: F);
  
  readonly options: O;
  readonly env: Environment;
  readonly fs: MemFsEditor;
  readonly log: Logger;
  readonly args: string[];
  readonly appname: string;
  readonly config: Storage;
  readonly packageJson: Storage;
  readonly yoGeneratorVersion: string;
  readonly simpleGit: SimpleGit;
  
  run(): Promise<void>;
}

Core Generator System

File System Operations

Template rendering, file copying, and destination management with support for EJS templating and conflict resolution.

function renderTemplate<D>(
  source: string | string[],
  destination?: string | string[],
  templateData?: string | D,
  templateOptions?: TemplateOptions,
  copyOptions?: CopyOptions
): void;

function copyTemplate(...args: Parameters<MemFsEditor['copy']>): ReturnType<MemFsEditor['copy']>;
function readDestination(...args: Parameters<MemFsEditor['read']>): ReturnType<MemFsEditor['read']>;
function writeDestination(...args: Parameters<MemFsEditor['write']>): ReturnType<MemFsEditor['write']>;

File System Operations

User Interaction & Prompting

Interactive prompting system with storage, prefilling, and validation capabilities built on Inquirer.js.

async prompt<A extends PromptAnswers = PromptAnswers>(
  questions: PromptQuestions<A>,
  storage?: string | Storage
): Promise<A>;

function registerConfigPrompts(questions: QuestionRegistrationOptions[]): void;

User Interaction & Prompting

Configuration Management

Persistent storage system for generator configurations, user preferences, and project settings.

class Storage {
  constructor(name: string | undefined, fs: MemFsEditor, configPath: string, options?: StorageOptions);
  
  get<T>(key: string): T;
  set<V>(key: string | number | V, value?: V): V | undefined;
  getAll(): StorageRecord;
  merge(source: StorageRecord): StorageRecord;
  createStorage(path: string): Storage;
}

Configuration Management

Command Line Interface

Options and arguments definition system with parsing, validation, and help generation.

function option(name: string | CliOptionSpec | CliOptionSpec[], config?: Partial<Omit<CliOptionSpec, 'name'>>): this;
function argument(name: string, config?: Partial<ArgumentSpec>): this;
function help(): string;
function usage(): string;

Command Line Interface

Task & Lifecycle Management

Queue-based task execution system with custom priorities, composition, and lifecycle management.

function queueTask(task: Task): void;
function composeWith<G extends BaseGenerator = BaseGenerator>(
  generator: string | { Generator: any; path: string },
  options?: ComposeOptions<G>
): Promise<G | G[]>;

Task & Lifecycle Management

Package Management

Package.json manipulation and dependency resolution with version management.

async function addDependencies(dependencies: string | string[] | Record<string, string>): Promise<Record<string, string>>;
async function addDevDependencies(devDependencies: string | string[] | Record<string, string>): Promise<Record<string, string>>;

Package Management

Command Execution

Process spawning and command execution with both synchronous and asynchronous support.

function spawnCommand(command: string, options?: ExecaOptions): ExecaChildProcess;
function spawn(command: string, args?: readonly string[], options?: ExecaOptions): ExecaChildProcess;
function spawnCommandSync(command: string, options?: SyncOptions): ExecaSyncReturnValue;

Command Execution

Git Integration

Git utilities for user information and repository operations through simple-git integration.

interface GitUtil {
  name(): Promise<string | undefined>;
  email(): Promise<string | undefined>;
}

readonly git: GitUtil;
readonly simpleGit: SimpleGit;

Git Integration

Types

interface BaseOptions {
  destinationRoot?: string;
  skipInstall?: boolean;
  skipCheckEnv?: boolean;
  ignoreVersionCheck?: boolean;
  askAnswered?: boolean;
  localConfigOnly?: boolean;
  skipCache?: boolean;
  skipLocalCache?: boolean;
  description?: string;
}

interface BaseFeatures {
  uniqueBy?: string;
  unique?: true | 'argument' | 'namespace';
  tasksMatchingPriority?: boolean;
  taskPrefix?: string;
  customInstallTask?: boolean | ((...args: any[]) => void | Promise<void>);
  customCommitTask?: boolean | ((...args: any[]) => void | Promise<void>);
  skipParseOptions?: boolean;
  customPriorities?: Priority[];
  inheritTasks?: boolean;
}

interface CliOptionSpec {
  name: string;
  type: typeof Boolean | typeof String | typeof Number | ((opt: string) => any);
  required?: boolean;
  alias?: string;
  default?: any;
  description?: string;
  hide?: boolean;
  storage?: string | Storage;
}

interface ArgumentSpec {
  name: string;
  description?: string;
  required?: boolean;
  optional?: boolean;
  type: typeof String | typeof Number | typeof Array | typeof Object;
  default?: any;
}

type StorageValue = string | number | boolean | null | undefined | StorageValue[] | StorageRecord;
type StorageRecord = Record<string, StorageValue>;
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/yeoman-generator@7.5.x
Publish Source
CLI
Badge
tessl/npm-yeoman-generator badge