Options
All
  • Public
  • Public/Protected
  • All
Menu

Abstract generator from which others are based

extends

Yeoman

Type parameters

Hierarchy

  • Generator
    • BaseGenerator

Index

Constructors

constructor

  • new BaseGenerator(args?: string | string[], options?: any): BaseGenerator
  • Parameters

    • Optional args: string | string[]
    • Optional options: any

    Returns BaseGenerator

Properties

Protected _templateNameStrip

_templateNameStrip: string | RegExp = /^__/

strips a pattern from the source template name to its final name. Useful when templates include behavioral configuration files such as: package.json and .gitignore. In such cases, use __package.json or __.gitignore as the template name instead.

appname

appname: string

args

args: __type

arguments

arguments: K

config

config: Yeoman.Storage

description

description: string

env

env: object

Type declaration

fs

fs: Yeoman.MemFsEditor

options

options: T

resolved

resolved: string

user

user: object

Type declaration

Static defaultMaxListeners

defaultMaxListeners: number

Methods

Protected _commonTemplateVars

  • _commonTemplateVars(): any
  • Implementation to support common variables when any template is written with the _writeTemplates method.

    Returns any

Protected _destinationFileName

  • _destinationFileName(filename: string, vars: object): string
  • perform filename interpolation by replacing {key} with respective values and /^__/ automatically be applied.

    Parameters

    • filename: string

      relative name of file.

    • vars: object

      interpolation variables

    Returns string

Protected Optional _templateFilter

  • _templateFilter(src: string): boolean
  • filter templates scanned from the template directory

    Parameters

    • src: string

      the template source relative to sourceRoot

    Returns boolean

    false will omit the path

Protected _writeTemplates

  • _writeTemplates(src: string, vars?: any, recursive?: boolean): void
  • Write templates into destination

    Parameters

    • src: string

      source directory to scan

    • Default value vars: any = {}

      interpolation object properties

    • Default value recursive: boolean = true

      flag to write recursively

    Returns void

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

argument

  • Specify arguments for the generator. Generally preferred in the constructor. Arguments are assigned by name to the this.options hash. See documentation for more information.

    Parameters

    • name: string

      Argument name

    • config: IGeneratorArgument

      Argument configuration

      this.argument('prefix', {
        type: String,
        description: 'A prefix for the generated code',
        required: false,
        default: '',
      });
      
      // read the argument
      const prefix = this.options.prefix;

    Returns this

argumentsHelp

  • argumentsHelp(): string
  • Returns string

bowerInstall

  • bowerInstall(component?: string | string[], options?: object, spawnOptions?: object): Promise<void>
  • Receives a list of components and an options object to install through bower.

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

    Parameters

    • Optional component: string | string[]

      Components to install

    • Optional options: object

      Options to pass to dargs as arguments

    • Optional spawnOptions: object

      Options to pass child_process.spawn.

    Returns Promise<void>

    Resolved if install successful, rejected otherwise

composeWith

  • Add a subgenerator run loop. Methods will be executed in parallel following the standard yeoman run loop. Note that options.parent will be automatically assigned as the generator from which the method is called. Options are also inherited from the parent generator.

    Parameters

    • name: string

      subgenerator name registered in the GeneratorEnv

    • Default value options: SubGeneratorOptions = {}

      options passed to the subgenerator instance

    Returns this

desc

  • desc(description: string): this
  • Parameters

    • description: string

    Returns this

destinationPath

  • destinationPath(...path: string[]): string
  • Parameters

    • Rest ...path: string[]

    Returns string

destinationRoot

  • destinationRoot(rootPath?: string): string
  • Parameters

    • Optional rootPath: string

    Returns string

determineAppname

  • determineAppname(): string
  • Returns string

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number
  • Returns number

help

  • help(): string
  • Returns string

installDependencies

  • installDependencies(options?: InstallOptions): Promise<void>
  • Runs npm and bower, in sequence, in the generated directory and prints a message to let the user know.

    example

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

    example

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

    Parameters

    • Optional options: InstallOptions

    Returns Promise<void>

    Resolved if install successful, rejected otherwise

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

log

  • log(message?: string, context?: any): void
  • Parameters

    • Optional message: string
    • Optional context: any

    Returns void

npmInstall

  • npmInstall(pkgs?: string | string[], options?: object, spawnOptions?: object): Promise<void>
  • Receives a list of packages and an options object to install through npm.

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

    Parameters

    • Optional pkgs: string | string[]

      Packages to install

    • Optional options: object

      Options to pass to dargs as arguments

    • Optional spawnOptions: object

      Options to pass child_process.spawn.

    Returns Promise<void>

    Resolved if install successful, rejected otherwise

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

option

  • Specify options for the generator. Generally preferred in teh constructor. Options are assigned by camelCase name to the this.options hash. See documentation for more information.

    Parameters

    • name: string

      Option name

    • config: IGeneratorOption

      Option configuration

      this.option('language', {
        alias: 'l',
        type: String,
        description: 'specify output language',
        default: 'JavaScript',
      });
      
      // read the option
      const language = this.options.language;

    Returns this

optionsHelp

  • optionsHelp(): string
  • Returns string

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prompt

  • prompt(prompts: Yeoman.Questions): Promise<Yeoman.Answers>
  • Prompt for user input based on inquirer

    Parameters

    • prompts: Yeoman.Questions

      prompt question configurations

    Returns Promise<Yeoman.Answers>

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

registerTransformStream

  • registerTransformStream(stream: __type | Array<__type>): this
  • Parameters

    • stream: __type | Array<__type>

    Returns this

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rootGeneratorName

  • rootGeneratorName(): string
  • Returns string

rootGeneratorVersion

  • rootGeneratorVersion(): string
  • Returns string

run

  • run(cb?: Callback): this
  • Parameters

    • Optional cb: Callback

    Returns this

runInstall

  • runInstall(installer: string, paths?: string | string[], options?: object, spawnOptions?: object): Promise<void>
  • 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. This means you can use Promise.then to log information, but don't return it or mix it with this.async as it'll dead lock the process.

    Parameters

    Returns Promise<void>

    Resolved if install successful, rejected otherwise

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

sourceRoot

  • sourceRoot(rootPath?: string): string
  • Parameters

    • Optional rootPath: string

    Returns string

spawnCommand

  • spawnCommand(command: string, args: string[], opt?: __type): any
  • Parameters

    • command: string
    • args: string[]
    • Optional opt: __type

    Returns any

spawnCommandSync

  • spawnCommandSync(command: string, args: string[], opt?: __type): any
  • Parameters

    • command: string
    • args: string[]
    • Optional opt: __type

    Returns any

templatePath

  • templatePath(...path: string[]): string
  • Parameters

    • Rest ...path: string[]

    Returns string

usage

  • usage(): string
  • Returns string

yarnInstall

  • yarnInstall(pkgs?: string | string[], options?: object, spawnOptions?: object): Promise<void>
  • Receives a list of packages and an options object to install through npm.

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

    Parameters

    • Optional pkgs: string | string[]

      Packages to install

    • Optional options: object

      Options to pass to dargs as arguments

    • Optional spawnOptions: object

      Options to pass child_process.spawn.

    Returns Promise<void>

    Resolved if install successful, rejected otherwise

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number