@types/yeoman-generator

  • Version 5.2.14
  • Published
  • 37.4 kB
  • 7 dependencies
  • MIT license

Install

npm i @types/yeoman-generator
yarn add @types/yeoman-generator
pnpm add @types/yeoman-generator

Overview

TypeScript definitions for yeoman-generator

Index

Classes

class Generator

class Generator<
T extends Generator.GeneratorOptions = Generator.GeneratorOptions
> extends EventEmitter {}
  • The class provides the common API shared by all generators. It define options, arguments, file, prompt, log, API, etc.

    Every generator should extend this base class.

constructor

constructor(
args: string | string[],
options: Generator.GeneratorOptions,
features?: Generator.GeneratorFeatures
);

    property appname

    appname: string;
    • The application name.

    property args

    args: string[];
    • Provides arguments at initialization.

    property config

    config: Storage;
    • The .yo-rc config file manager.

    property contextRoot

    contextRoot: string;
    • The path from where the user is running yo.

    property copyDestination

    copyDestination: Editor;
    • Copy file from destination folder to another destination folder. mem-fs-editor method's shortcut, for more information see [mem-fs-editor](https://github.com/SBoudrias/mem-fs-editor). Shortcut for:

      this.fs.copy(this.destinationPath(from), this.destinationPath(to))

    property copyTemplate

    copyTemplate: Editor;
    • Copy file from templates folder to destination folder. mem-fs-editor method's shortcut, for more information see [mem-fs-editor](https://github.com/SBoudrias/mem-fs-editor). Shortcut for:

      this.fs.copy(this.templatePath(from), this.destinationPath(to))

    property debug

    debug: (...args: Parameters<Debugger>) => void;
    • Convenience debug method.

    property deleteDestination

    deleteDestination: Editor;
    • Deletes file from destination folder. mem-fs-editor method's shortcut, for more information see [mem-fs-editor](https://github.com/SBoudrias/mem-fs-editor). Shortcut for:

      this.fs.delete(this.destinationPath(filepath))

    property description

    description: string;
    • The description to display in the --help output.

    property env

    env: Environment;
    • The current Environment being run.

    property existsDestination

    existsDestination: Editor;
    • Checks whether a file exists in the destination folder. mem-fs-editor method's shortcut, for more information see [mem-fs-editor](https://github.com/SBoudrias/mem-fs-editor). Shortcut for:

      this.fs.exists(this.destinationPath(filepath))

    property fs

    fs: Editor;
    • An instance of [mem-fs-editor](https://github.com/SBoudrias/mem-fs-editor).

    property log

    log: Logger;
    • Provides the functionality to log messages.

    property moveDestination

    moveDestination: Editor;
    • Move file from destination folder to another destination folder. mem-fs-editor method's shortcut, for more information see [mem-fs-editor](https://github.com/SBoudrias/mem-fs-editor). Shortcut for:

      this.fs.move(this.destinationPath(from), this.destinationPath(to))

    property options

    options: Generator.GeneratorOptions;
    • Provides options at initialization.

    property packageJson

    packageJson: Storage;
    • The storage containing the destination-package.json.

    property readDestination

    readDestination: Editor;
    • Read file from destination folder. mem-fs-editor method's shortcut, for more information see [mem-fs-editor](https://github.com/SBoudrias/mem-fs-editor). Shortcut for:

      this.fs.read(this.destinationPath(filepath))

    property readDestinationJSON

    readDestinationJSON: Editor;
    • Read JSON file from destination folder. mem-fs-editor method's shortcut, for more information see [mem-fs-editor](https://github.com/SBoudrias/mem-fs-editor). Shortcut for:

      this.fs.readJSON(this.destinationPath(filepath))

    property readTemplate

    readTemplate: Editor;
    • Read file from templates folder. mem-fs-editor method's shortcut, for more information see [mem-fs-editor](https://github.com/SBoudrias/mem-fs-editor). Shortcut for:

      this.fs.read(this.templatePath(filepath))

    property resolved

    resolved: string;
    • The path to the current generator.

    property user

    readonly user: {
    readonly git: { email(): string; name(): string };
    readonly github: { username(): Promise<string> };
    };

      property writeDestination

      writeDestination: Editor;
      • Write file to destination folder mem-fs-editor method's shortcut, for more information see [mem-fs-editor](https://github.com/SBoudrias/mem-fs-editor). Shortcut for:

        this.fs.write(this.destinationPath(filepath))

      property writeDestinationJSON

      writeDestinationJSON: Editor;
      • Write json file to destination folder mem-fs-editor method's shortcut, for more information see [mem-fs-editor](https://github.com/SBoudrias/mem-fs-editor). Shortcut for:

        this.fs.writeJSON(this.destinationPath(filepath))

      method addDependencies

      addDependencies: (
      dependencies: Record<string, string> | string | string[]
      ) => Promise<Record<string, string>>;
      • Adds dependencies to the destination package.json.

        Parameter dependencies

        The packages to add.

        Returns

        The newly added dependencies.

      method addDevDependencies

      addDevDependencies: (
      devDependencies: Record<string, string> | string | string[]
      ) => Promise<Record<string, string>>;
      • Adds development-dependencies to the destination package.json.

        Parameter devDependencies

        The packages to add to the development-dependencies.

        Returns

        The newly added development-dependencies.

      method argument

      argument: (name: string, config: Generator.ArgumentConfig) => this;
      • Adds an argument to the class and creates an attribute getter for it.

        Arguments are different from options in several aspects. The first one is how they are parsed from the command line, arguments are retrieved based on their position.

        Besides, arguments are used inside your code as a property (), while options are all kept in a hash ().

        Parameter name

        Argument name.

        Parameter config

        Argument options. This generator.

      method argumentsHelp

      argumentsHelp: () => string;
      • Generates a help-text for the arguments.

        Returns

        A help-text for the arguments.

      method bowerInstall

      bowerInstall: (
      components?: string | string[],
      options?: object,
      spawnOptions?: SpawnOptions
      ) => void;
      • Parameter components

        Components to install

        Parameter options

        Options to pass to dargs as arguments

        Parameter spawnOptions

        Options to pass .

        Deprecated

        Receives a list of and an object to install through bower.

        The installation will automatically run during the run loop install phase.

      method cancelCancellableTasks

      cancelCancellableTasks: () => void;
      • Cancels all cancellable tasks.

      method composeWith

      composeWith: {
      (
      generators:
      | Array<Generator.CompositionOptions | string>
      | Generator.CompositionOptions
      | string,
      options?: Generator.GeneratorOptions,
      returnNewGenerator?: false
      ): this;
      (
      generators: string | Generator.CompositionOptions,
      options: Generator.GeneratorOptions,
      returnNewGenerator: true
      ): Generator<Generator.GeneratorOptions>;
      (
      generators: (string | Generator.CompositionOptions)[],
      options: Generator.GeneratorOptions,
      returnNewGenerator: true
      ): Generator<Generator.GeneratorOptions>[];
      };
      • Compose this generator with another one.

        Parameter generator

        The path to the generator module or an object (see examples).

        Parameter options

        The options passed to the Generator.

        Parameter returnNewGenerator

        Returns the created generator instead of returning this. This generator or the composed generator when is true.

        Returns

        Either returns this generator or the newly created generator.

        Example 1

        this.composeWith('bootstrap', { sass: true });

        Example 2

        this.composeWith(require.resolve('generator-bootstrap/app/main.js'), { sass: true });

        Example 3

        this.composeWith({ Generator: MyGenerator, path: '../generator-bootstrap/app/main.js' }, { sass: true });

      • Compose this generator with another one.

        Parameter generator

        The path to the generator module or an object (see examples).

        Parameter options

        The options passed to the Generator.

        Parameter returnNewGenerator

        Returns the created generator instead of returning this. This generator or the composed generator when returnNewGenerator=true

        Returns

        Either returns this generator or the newly created generator.

        Example 1

        this.composeWith('bootstrap', { sass: true });

        Example 2

        this.composeWith(require.resolve('generator-bootstrap/app/main.js'), { sass: true });

        Example 3

        this.composeWith({ Generator: MyGenerator, path: '../generator-bootstrap/app/main.js' }, { sass: true });

      method createStorage

      createStorage: (
      storagePath: string,
      key?: string,
      lodashPath?: boolean
      ) => Storage;
      • Creates a new storage.

        Parameter storagePath

        The path to the json-file of the storage.

        Parameter key

        The key in which the options are stored inside the json.

        Parameter lodashPath

        A value indicating whether the argument should be treated as a lodash path.

      method desc

      desc: (description: string) => this;
      • Sets a custom for the help output.

        Parameter description

        The new description.

      method destinationPath

      destinationPath: (...path: string[]) => string;
      • Joins a path to the destination root.

        Parameter path

        The path parts.

      method destinationRoot

      destinationRoot: (rootPath?: string, skipEnvironment?: boolean) => string;
      • Changes the generator destination root directory.

        This path is used to find storage, when using file system helper methods (such as and ).

        Parameter rootPath

        The new destination root path.

        Parameter skipEnvironment

        A value indicating whether and the current working directory shouldn't be changed.

      method determineAppname

      determineAppname: () => string;
      • Determines the name of the application.

        First checks for the name in bower.json, then checks for the name in package.json. Finally defaults to the name of the current directory.

        Returns

        The name of the application.

      method help

      help: () => string;
      • Tries to get the description from a USAGE file one folder above the source root, otherwise uses a default description.

      method installDependencies

      installDependencies: (options?: Generator.InstallOptions) => void;
      • Example 1

        this.installDependencies({ bower: true, npm: true }).then(() => console.log('Everything is ready!'));

        Example 2

        this.installDependencies({ yarn: {force: true}, npm: false }).then(() => console.log('Everything is ready!'));

        Deprecated

        Runs npm and bower, in sequence, in the generated directory and prints a message to let the user know.

      method npmInstall

      npmInstall: (
      packages?: string | string[],
      options?: object,
      spawnOptions?: SpawnOptions
      ) => void;
      • Parameter packages

        Packages to install

        Parameter options

        Options to pass to dargs as arguments

        Parameter spawnOptions

        Options to pass .

        Deprecated

        Receives a list of and an object to install through npm.

        The installation will automatically run during the run loop install phase.

      method option

      option: (name: string, config?: Generator.OptionConfig) => this;
      • Adds an option to the set of generator expected options, only used to generate generator usage. By default, generators get all the cli options parsed by nopt as a hash object.

        Parameter name

        The name of the option.

        Parameter config

        The configuration of the option.

        Returns

        This generator

      method optionsHelp

      optionsHelp: () => string;
      • Gets help text for options.

      method prompt

      prompt: <T extends InquirerAnswers>(
      questions: Generator.Questions<T>
      ) => Promise<T>;
      • Prompt user to answer questions.

      method queueBasicTasks

      queueBasicTasks: () => void;
      • Queues the basic tasks of the generator.

      method queueMethod

      queueMethod: (
      method: ((...args: any[]) => any) | Record<string, (...args: any[]) => any>,
      methodName?: string,
      queueName?: string,
      reject?: Generator.Callback
      ) => void;
      • Schedules methods on a run queue.

        Parameter method

        The method or an object containing function properties to schedule.

        Parameter methodName

        The name of the method to be scheduled.

        Parameter queueName

        The name of the queue to schedule on.

        Parameter reject

        A callback for handling rejections.

      method queueTask

      queueTask: (task: Generator.Task) => void;
      • Schedules a task on a run queue.

        Parameter task

        The task to queue.

      method queueTaskGroup

      queueTaskGroup: (
      taskGroup: Record<string, (...args: any[]) => any>,
      taskOptions?: Generator.TaskOptions
      ) => void;
      • Schedules methods on a run queue.

        Parameter taskGroup

        An object containing tasks.

        Parameter taskOptions

        The options for creating the tasks.

      method queueTransformStream

      queueTransformStream: (stream: Transform | Transform[]) => this;
      • Adds a transform stream to the commit stream.

        Parameter stream

        An array of transform streams or a single one.

      method registerConfigPrompts

      registerConfigPrompts: <TAnswers extends InquirerAnswers>(
      questions:
      | Generator.QuestionRegistrationOptions<TAnswers>
      | Array<Generator.QuestionRegistrationOptions<TAnswers>>
      ) => void;
      • Registers stored config prompts and optional option alternatives.

        Parameter questions

        The questions to register.

      method registerPriorities

      registerPriorities: (priorities: Generator.Priority[]) => void;
      • Registers the specified .

        Parameter priorities

        The priorities to register.

      method renderTemplate

      renderTemplate: (
      source: string | string[],
      destination?: string | string[],
      templateData?: TemplateData | string,
      templateOptions?: TemplateOptions | string,
      copyOptions?: CopyOptions
      ) => void;
      • Copies a template from templates folder to the destination.

        Parameter source

        The template file, absolute or relative to .

        Parameter destination

        The destination, absolute or relative to .

        Parameter templateData

        The ejs-data or the name of the storage-key to get the data from.

        Parameter templateOptions

        The ejs-options.

        Parameter copyOptions

        The mem-fs-editor copy options.

      method renderTemplates

      renderTemplates: (
      templates: Array<Generator.TemplateRenderOptions<this>>,
      templateData?: TemplateData | string
      ) => void;
      • Copies templates from the templates folder to the destination.

        Parameter templates

        The template files to copy.

        Parameter templateData

        The ejs data or the name of the storage-key to get the data from.

      method rootGeneratorName

      rootGeneratorName: () => string;
      • Determines the root generator name (the one who's extending this generator).

      method rootGeneratorVersion

      rootGeneratorVersion: () => string;
      • Determines the root generator version (the one who's extending this generator).

      method run

      run: { (): Promise<void>; (cb: Generator.Callback): Promise<void> };
      • Runs the generator, scheduling prototype methods on a run queue. Method names will determine the order each method is run. Methods without special names will run in default queue.

        Any method named constructor and any methods prefixed by a _ won't be scheduled.

      • Runs the generator, scheduling prototype methods on a run queue. Method names will determine the order each method is run. Methods without special names will run in default queue.

        Any method named constructor and any methods prefixed by a _ won't be scheduled.

        Parameter cb

        The callback.

        Deprecated

      method scheduleInstallTask

      scheduleInstallTask: (
      installer: string,
      paths?: string | string[],
      options?: object,
      spawnOptions?: SpawnOptions
      ) => void;
      • Parameter installer

        Which package manager to use

        Parameter paths

        Packages to install. Use an empty string for npm install

        Parameter options

        Options to pass to dargs as arguments

        Parameter spawnOptions

        Options to pass .

        Deprecated

        Combine package manager cmd line arguments and run the install command.

        During the install step, every command will be scheduled to run once, on the run loop.

      method sourceRoot

      sourceRoot: (rootPath?: string) => string;
      • Changes the generator source root directory. This path is used by multiple file system methods.

        Parameter rootPath

        The new source root path.

      method spawnCommand

      spawnCommand: (command: string, args: string[], opt?: SpawnOptions) => any;
      • Normalizes a command across OS and spawns it (asynchronously).

        Parameter command

        The program to execute.

        Parameter args

        A list of arguments to pass to the program.

        Parameter opt

        Any cross-spawn options.

      method spawnCommandSync

      spawnCommandSync: (
      command: string,
      args: string[],
      opt?: SpawnSyncOptions
      ) => any;
      • Normalizes a command across the OS and spawns it (synchronously).

        Parameter command

        The program to execute.

        Parameter args

        A list of arguments to pass to the program

        Parameter opt

        Any cross-spawn options.

      method startOver

      startOver: (options?: T) => void;
      • Starts the generator again.

        Parameter The

        options to assign.

      method templatePath

      templatePath: (...path: string[]) => string;
      • Joins a path to the source root.

        Parameter path

        The path parts.

      method usage

      usage: () => string;
      • Gets usage information for this generator, depending on its arguments or options.

      method yarnInstall

      yarnInstall: (
      packages?: string | string[],
      options?: object,
      spawnOptions?: SpawnOptions
      ) => void;
      • Parameter packages

        Packages to install

        Parameter options

        Options to pass to dargs as arguments

        Parameter spawnOptions

        Options to pass .

        Deprecated

        Receives a list of and an object to install through npm.

        The installation will automatically run during the run loop install phase.

      Interfaces

      interface ArgumentConfig

      interface ArgumentConfig {}
      • Provides options for creating a new argument.

      property default

      default?: any;
      • The default value of the argument.

      property description

      description?: string | undefined;
      • Description for the argument.

      property optional

      optional?: boolean | undefined;
      • A value indicating whether the argument is optional.

      property required

      required?: boolean | undefined;
      • A value indicating whether the argument is required.

      property type

      type?: typeof String | typeof Number | typeof Array | typeof Object | undefined;
      • The type of the argument.

      interface CompositionOptions

      interface CompositionOptions {}
      • Represents options for composing a generator.

      property Generator

      Generator: GeneratorConstructor;
      • The constructor of the generator.

      property path

      path: string;
      • The path to the file containing the generator.

      interface GeneratorConstructor

      interface GeneratorConstructor {}
      • Represents a generator-constructor.

      construct signature

      new (...args: any[]): Generator<any>;

        interface GeneratorFeatures

        interface GeneratorFeatures {}
        • Represents generators feature

        property customCommitTask

        customCommitTask?: boolean | undefined;
        • Enable customCommitTask()

        property customInstallTask

        customInstallTask?: boolean | undefined;
        • Enable customInstallTask()

        property taskPrefix

        taskPrefix?: string | undefined;
        • Tasks methods starts with prefix. Allows api methods (non tasks) without prefix.

        property tasksMatchingPriority

        tasksMatchingPriority?: boolean | undefined;
        • Only queue methods that matches a priority

        property unique

        unique?: string | undefined;
        • The Generator instance unique identifier. The Environment will ignore duplicated identifiers.

        property uniqueBy

        uniqueBy?: GeneratorFeaturesUniqueBy | undefined;
        • uniqueBy calculation method (undefined/argument/namespace)

        interface GeneratorOptions

        interface GeneratorOptions {}
        • Provides options for generators.

        property customPriorities

        customPriorities?: Priority[] | undefined;
        • Gets or sets a collection of custom priorities.

        property destinationRoot

        destinationRoot?: string | undefined;
        • The destination-root to write the files to.

        property env

        env?: Environment | undefined;
        • The environment to use for creating the generator.

        property resolved

        resolved?: string;
        • The path to the generator.

        index signature

        [name: string]: any;
        • Gets or sets additional properties.

        interface InstallOptions

        interface InstallOptions {}
        • Provides options for performing installations.

        property bower

        bower?: boolean | object | undefined;
        • A value indicating whether to run bower install or options to pass to dargs as arguments.

        property npm

        npm?: boolean | object | undefined;
        • A value indicating whether to run npm install or options to pass to dargs as arguments.

        property skipMessage

        skipMessage?: boolean | undefined;
        • A value indicating whether messages should be logged.

        property yarn

        yarn?: boolean | object | undefined;
        • A value indicating whether to run yarn install or options to pass to dargs as arguments.

        interface OptionConfig

        interface OptionConfig {}
        • Provides settings for creating a new generator-option.

        property alias

        alias?: string | undefined;
        • The option name alias (example -h and --help`).

        property default

        default?: any;
        • The default value.

        property description

        description?: string | undefined;
        • The description for the option.

        property hide

        hide?: boolean | undefined;
        • A value indicating whether the option should be hidden from the help output.

        property storage

        storage?: Storage | undefined;
        • The storage to persist the option

        property type

        type: typeof Boolean | typeof String | typeof Number | ((opt: string) => any);
        • The type of the option.

        interface Priority

        interface Priority {}
        • Provides a priority-specification for a custom queue.

        property before

        before: string;
        • The name of the queue which this priority should be added before.

        property priorityName

        priorityName: string;
        • The name of the method to execute.

        property queueName

        queueName?: string | undefined;
        • The name for identifying the queue.

        interface QueueOptions

        interface QueueOptions {}
        • Provides options for queues.

        property once

        once?: boolean | undefined;
        • A value indicating whether the queue should be executed only once per namespace and task-name.

        property queueName

        queueName?: string | undefined;
        • The name of the queue.

        property run

        run?: boolean | undefined;
        • A value indicating whether the queue should be executed if not running yet.

        interface Task

        interface Task extends TaskOptions {}
        • Represents a task.

        property method

        method: (...args: any) => any;
        • The function to queue.

        property taskName

        taskName: string;
        • The name of the task.

        interface TaskOptions

        interface TaskOptions extends QueueOptions {}
        • Provides options for tasks.

        property reject

        reject?: Callback | undefined;
        • A method for handling errors.

        interface TemplateRenderOptions

        interface TemplateRenderOptions<T extends Generator<any>> {}
        • Provides settings for rendering a template.

        property copyOptions

        copyOptions?: CopyOptions | undefined;
        • The mem-fs-editor copy-options.

        property destination

        destination?: string | string[] | undefined;
        • The destination, absolute or relative to .

        property source

        source: string | string[];
        • The template file, absolute or relative to .

        property templateOptions

        templateOptions?: TemplateOptions | undefined;
        • The ejs options.

        property when

        when?: ((templateData: TemplateData, generator: T) => boolean) | undefined;
        • A method for determining whether the template should be rendered.

        Type Aliases

        type Answers

        type Answers = InquirerAnswers;
        • Represents an answer-hash.

        type Callback

        type Callback =
        /**
        * Handles a callback.
        *
        * @param err The error that occurred.
        */
        (err: any) => void;
        • Provides the functionality to handle callbacks.

        type GeneratorFeaturesUniqueBy

        type GeneratorFeaturesUniqueBy = 'argument' | 'namespacep';

          type Question

          type Question<T extends Answers = Answers> = DistinctQuestion<T> & {
          /**
          * A value indicating whether to store the user's previous answer.
          */
          store?: boolean | undefined;
          };
          • Represents a question.

          type QuestionRegistrationOptions

          type QuestionRegistrationOptions<T extends Answers = Answers> = Question<T> & {
          /**
          * The storage to store the answers.
          */
          storage?: Storage | undefined;
          /**
          * A value indicating whether an option should be exported for this question.
          */
          exportOption?: boolean | object | undefined;
          };
          • Provides options for registering a prompt.

          type Questions

          type Questions<A extends Answers = Answers> =
          | Question<A>
          | Array<Question<A>>
          | Observable<Question<A>>;
          • Provides a set of questions.

          Package Files (1)

          Dependencies (7)

          Dev Dependencies (0)

          No dev dependencies.

          Peer Dependencies (0)

          No peer dependencies.

          Badge

          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/yeoman-generator.

          • Markdown
            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/yeoman-generator)
          • HTML
            <a href="https://www.jsdocs.io/package/@types/yeoman-generator"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>