@types/yeoman-environment

  • Version 2.10.11
  • Published
  • 35.9 kB
  • 11 dependencies
  • MIT license

Install

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

Overview

TypeScript definitions for yeoman-environment

Index

Classes

class Environment

class Environment<
TOptions extends Environment.Options = Environment.Options
> extends EventEmitter {}
  • Environment object is responsible of handling the lifecycle and bootstrap of generators in a specific environment (your app).

    It provides a high-level API to create and run generators, as well as further tuning where and how a generator is resolved.

    An environment is created using a list of arguments and a Hash of options. Usually, this is the list of arguments you get back from your CLI options parser.

    An optional adapter can be passed to provide interaction in non-CLI environment (e.g. IDE plugins), otherwise a TerminalAdapter is instantiated by default

constructor

constructor(
args?: string | string[],
opts?: Environment.Options,
adapter?: TerminalAdapter
);
  • Initializes a new instance of the Environment class.

    Parameter args

    The arguments to pass to the environment.

    Parameter opts

    The options for the environment.

    Parameter adapter

    A TerminalAdapter instance for handling input/output.

property adapter

adapter: TerminalAdapter;
  • The adapter of the environment.

property aliases

aliases: Environment.Alias[];
  • The alias-settings of the environment.

property arguments

arguments: string[];
  • The arguments passed to this environment.

property cwd

cwd: string;
  • The working-directory of the environment.

property lookups

lookups: string[];
  • The file-paths to look for generators (such as lib/generators/).

property options

options: Environment.Options;
  • The options of the environment.

property sharedFs

sharedFs: MemFsStore;
  • The file-system of the environment.

property store

store: Storage;
  • The config-storage of the environment.

property util

static util: typeof util;
  • The utilities of the module.

method alias

alias: { (name: string): string; (match: string | RegExp, value: string): void };
  • Gets the alias for the specified name.

  • Creates an alias.

    Alias allows the get() and lookup() methods to search in alternate filepath for a given namespaces. It's used for example to map generator-* npm package to their namespace equivalent (without the generator- prefix), or to default a single namespace like angular to angular:app or angular:all.

    If multiple aliases are defined, then the replacement is recursive, replacing each alias in reverse order.

    An alias can be a single String or a Regular Expression. The finding is done based on .match().

    Parameter match

    The name to match.

    Parameter value

    The replacement for the specified match.

    Example 1

    env.alias(/^([a-zA-Z0-9:*]+)$/, 'generator-$1'); env.alias(/^([^:]+)$/, '$1:app'); env.alias(/^([^:]+)$/, '$1:all'); env.alias('foo'); // => generator-foo:all

method applyTransforms

applyTransforms: (
transformStreams: Transform[],
stream?: NodeJS.ReadableStream
) => Promise<void>;
  • Applies the specified transform streams to the files in the sharedFs.

    Parameter transformStreams

    The transforms to apply.

    Parameter stream

    The file stream to apply the transforms on.

method commitSharedFs

commitSharedFs: (stream: Stream) => Promise<void>;
  • Commits the mem-fs to the disk.

    Parameter stream

    The files to commit.

method composeWith

composeWith: (
namespaceOrPath: string,
args: string[],
options: Generator.GeneratorOptions
) => Generator;
  • Composes with a generator.

    Parameter namespaceOrPath

    The namespace of the generator or the path to a generator.

    Parameter args

    The options to pass to the generator.

    Parameter options

    The options to pass to the generator.

    Returns

    The instantiated generator or a singleton instance.

method create

create: <TOptions extends Generator.GeneratorOptions>(
namespaceOrPath: string,
args: string[],
options?: Environment.InstantiateOptions<TOptions>
) => Generator<TOptions> | Error;
  • Creates a new generator.

    Parameter namespaceOrPath

    The namespace of the generator or the path to a generator.

    Parameter args

    The arguments to pass to the generator.

    Parameter options

    The options to pass to the generator.

    Returns

    Either the newly created generator or the error that occurred.

method createEnv

static createEnv: <TOptions extends Environment.Options = Environment.Options>(
args?: string | string[],
opts?: TOptions,
adapter?: Environment.Adapter
) => Environment<TOptions>;
  • Creates a new Environment instance.

    Parameter args

    The arguments to pass to the environment.

    Parameter opts

    The options for the environment.

    Parameter adapter

    A TerminalAdapter instance for handling input/output.

    Returns

    The newly created environment.

method createEnvWithVersion

static createEnvWithVersion: <TOptions extends Environment.Options>(
version: string,
args?: string | string[],
opts?: TOptions,
adapter?: Environment.Adapter
) => Environment<TOptions>;
  • Creates a new Environment instance with the specified version.

    Parameter version

    The version of the environment.

    Parameter args

    The arguments to pass to the environment.

    Parameter opts

    The options for the environment.

    Parameter adapter

    A TerminalAdapter instance for handling input/output.

    Returns

    The newly created environment.

method enforceUpdate

static enforceUpdate: <TEnv extends Environment<Environment.Options>>(
env: TEnv
) => TEnv;
  • Makes sure the Environment present expected methods if an old version is passed to a Generator.

    Parameter env

    The environment to update.

    Returns

    The updated env.

method error

error: (error: Error | object) => Error;
  • Handles the specified error.

    The error-event is emitted with the specified error object. If no error listener is registered, the error is thrown.

    Parameter error

    An object representing the error.

method findGeneratorsIn

findGeneratorsIn: (
list: string[],
options?: Environment.GeneratorsInOptions
) => string[];
  • Searches npm for every available generator. Generators are npm-packages whose name starts with generator- and that are placed in the top level node_module path. They can be installed globally or locally.

    Parameter list

    The paths to search for generators.

    Parameter options

    The options for looking for generators.

    Deprecated

method get

get: (namespaceOrPath: string) => typeof Generator | undefined;
  • Gets a single constructor of a generator from the registered list of generators.

    The lookup is based on generator's namespace, "walking up" the namespaces until a matching is found. Eg. if an angular:common namespace is registered, and we try to get angular:common:all, then we get angular:common as a fallback (unless an angular:common:all generator is registered).

    Parameter namespaceOrPath

    The namespace of the generator or the path to a generator.

    Returns

    The constructor of the generator registered under the namespace.

method getByPath

getByPath: (path: string) => typeof Generator | undefined;
  • Gets a constructor of a generator by the path instead of the namespace.

    Parameter path

    The path to the generator.

    Returns

    The constructor of the generator found at the location.

method getGeneratorNames

getGeneratorNames: () => string[];
  • Gets the names of the registered generators.

method getGeneratorsMeta

getGeneratorsMeta: () => Record<string, Environment.GeneratorMeta>;
  • Gets metadata of the registered generators.

method getNpmPaths

getNpmPaths: (options?: Environment.NpmPathsOptions) => string[];
  • Gets paths to directories to look for npm-packages (such as ./node_modules).

    Deprecated

method getPackagePath

getPackagePath: (namespace: string) => string;
  • Gets the most recent path to the generator by its namespace.

    Parameter namespace

    The namespace of the generator.

method getPackagePaths

getPackagePaths: (namespace: string) => string[];
  • Gets all paths which have been populated for a generator by its namespace.

    Parameter namespace

    The namespace of the generator.

method getRegisteredPackages

getRegisteredPackages: () => string[];
  • Gets the namespaces of all registered generators.

method getVersion

getVersion: { (): string; (dependency: string): string };
  • Gets the version of this Environment object.

  • Gets the version of the specified dependency.

    Parameter dependency

    The name of the dependency.

method help

help: (command?: string) => string;
  • Outputs general help and usage for the specified command. Optionally, if generators have been registered, a list of available generators is displayed.

    Parameter command

    `The name of the command to get help for.

method installLocalGenerators

installLocalGenerators: (packages: Record<string, string>) => boolean;
  • Installs generators at the custom local repository and registers them.

    Parameter packages

    The package-names with the corresponding versions to install.

method instantiate

instantiate: (
generator: Generator.GeneratorConstructor,
args: string[],
options: Environment.InstantiateOptions
) => Generator;
  • Instantiates a generator.

    Parameter generator

    The constructor of the generator.

    Parameter args

    The arguments to pass to the generator.

    Parameter options

    The options to pass to the generator.

method isPackageRegistered

isPackageRegistered: (packageNamespace?: string) => boolean;
  • Checks whether a package with the specified packageNamespace has been registered.

    Parameter packageNamespace

    The package-namespace to check.

    Returns

    A value indicating whether a package with the specified packageNamespace has been registered.

method loadEnvironmentOptions

loadEnvironmentOptions: (options: Environment.Options) => Environment.Options;
  • Applies the specified options to the environment.

    Parameter options

    The options to load.

    Returns

    The new options of the environment.

method loadSharedOptions

loadSharedOptions: (
options: Generator.GeneratorOptions
) => Generator.GeneratorOptions;
  • Loads the specified options into the environment for passing to the generators.

    Parameter options

    The options to load. the new shared options of the environment.

method lookup

lookup: (
options?: Environment.LookupOptions
) => Environment.LookupGeneratorMeta[];
  • Searches for generators and their sub-generators.

    A generator is a :lookup/:name/index.js file placed inside an npm package.

    Default lookups are: - ./ - ./generators/ - ./lib/generators/

    So the index file node_modules/generator-dummy/lib/generators/yo/index.js would be registered as dummy:yo generator.

    Parameter options

    The options for the lookup.

    Returns

    A list of generators.

method lookupGenerator

static lookupGenerator: {
(
namespace: string,
options?: Environment.ArrayGeneratorLookupOptions
): string[];
(
namespace: string,
options?: Environment.SingleGeneratorLookupOptions
): string;
};
  • Invokes a lookup for a specific generator.

    Parameter namespace

    The namespace of the generator to search.

    Parameter options

    Options for searching the generator.

    Returns

    The paths to the generators which were found.

  • Invokes a lookup for a specific generator.

    Parameter namespace

    The namespace of the generator to search.

    Parameter options

    Options for searching the generator.

    Returns

    The path to the generator which was found.

method lookupLocalPackages

lookupLocalPackages: (
packagesToLookup?: string[]
) => Environment.LookupGeneratorMeta[];
  • Searches and registers generators inside the custom local repository.

    Parameter packagesToLookup

    The patterns of the packages to lookup.

method namespace

namespace: (filePath: string, lookups?: string[]) => string;
  • Converts the specified filePath to a namespace.

    Parameter filePath

    The path to convert.

    Parameter lookups

    The path-part to exclude (such as lib/generators).

method namespaces

namespaces: () => string[];
  • Gets a list of all registered namespaces.

method namespaceToName

static namespaceToName: (namespace: string) => string;
  • Converts a generator namespace to its name.

    Parameter namespace

    The generator namespace.

method prepareCommand

static prepareCommand: (
generatorClass: Generator.GeneratorConstructor
) => Command;
  • Prepares a command for cli support.

    Parameter generatorClass

    The generator class to create a command for.

    Returns

    The prepared command.

method prepareGeneratorCommand

static prepareGeneratorCommand: (
command: Command,
generatorClass: Generator.GeneratorConstructor
) => Command;
  • Prepares a command for cli support.

    Parameter command

    The command to prepare.

    Parameter generatorClass

    The constructor of the generator to prepare the command for.

    Returns

    The prepared command.

method queueConflicter

queueConflicter: () => void;
  • Queue's the environment's commit task.

method queueGenerator

queueGenerator: (generator: Generator, schedule?: boolean) => Generator;
  • Queues the specified generator.

    Parameter generator

    The generator to queue.

    Parameter schedule

    A value indicating whether the execution of the generator should be scheduled.

    Returns

    The queued generator.

method queuePackageManagerInstall

queuePackageManagerInstall: () => void;
  • Queues the package manager installation task.

method register

register: (name: string, namespace?: string, packagePath?: string) => this;
  • Registers a specific generator to this environment. This generator is stored under the provided namespace or, if not specified, a default namespace format.

    Parameter name

    The filepath to the generator or an npm package name.

    Parameter namespace

    The namespace under which the generator should be registered.

    Parameter packagePath

    The path to the npm package of the generator.

method registerStub

registerStub: (
generator: Generator.GeneratorConstructor,
namespace: string,
resolved?: string,
packagePath?: string
) => this;
  • Registers a stubbed generator to this environment.

    Parameter generator

    The generator constructor.

    Parameter namespace

    The namespace under which the generator should be registered.

    Parameter resolved

    The file-path to the generator.

    Parameter packagePath

    The path to the npm package of the generator.

method resolveModulePath

resolveModulePath: (moduleId: string) => string;
  • Resolves the path of the specified module.

    Parameter moduleId

    The name of the module.

    Returns

    The resolved path to the module.

method resolvePackage

resolvePackage: (
packageName: string,
packageVersion: string
) => [string, string];
  • Resolves a package name with a specific version.

    Parameter packageName

    The name of the package to resolve.

    Parameter packageVersion

    The version or the version range of the package to resolve.

method rootGenerator

rootGenerator: () => Generator;
  • Gets the first generator that was queued to run in this environment.

method run

run: (
args: string | [string, ...string[]],
options?: Generator.GeneratorOptions
) => Promise<void>;
  • Tries to locate and run a specific generator. The lookup is done depending on the provided arguments, options and the list of registered generators.

    When the environment was unable to resolve a generator, an error is raised.

    Parameter args

    The arguments to pass to the generator.

    Parameter options

    The options to pass to the generator.

method runGenerator

runGenerator: (generator: Generator) => Promise<void>;
  • Runs the specified generator.

    See [#101](https://github.com/yeoman/environment/pull/101) for more info.

    Parameter generator

    The generator to run.

method spawnCommand

spawnCommand: (
command: string,
args: string[],
options: Options
) => ExecaChildProcess;
  • Spawns a command asynchronously.

    Parameter command

    The command to execute.

    Parameter args

    The arguments to pass to the program.

    Parameter options

    The options to use for running the command.

method spawnCommandSync

spawnCommandSync: (
command: string,
args: string[],
options: SyncOptions
) => ExecaSyncReturnValue;
  • Spawns a command synchronously.

    Parameter command

    The command to execute.

    Parameter args

    The arguments to pass to the program.

    Parameter options

    The options to use for running the command.

method start

start: (options: Conflicter.ConflicterOptions) => Promise<void>;
  • Starts the environment queue.

    Parameter options

    The conflicter options.

Interfaces

interface Alias

interface Alias {}
  • Represents an alias.

property match

match: RegExp;
  • The pattern to match.

property value

value: string;
  • The replacement of the match.

interface ArrayGeneratorLookupOptions

interface ArrayGeneratorLookupOptions extends GeneratorLookupOptions {}
  • Provides options array generator lookups.

property singleResult

singleResult?: false | undefined;

interface GeneratorLookupOptions

interface GeneratorLookupOptions extends LookupOptionBase {}
  • Provides options for generator-lookups.

property packagePath

packagePath?: boolean | undefined;
  • A value indicating whether the path to the package should be returned instead of the path to the generator.

property singleResult

singleResult?: boolean | undefined;
  • A value indicating whether only one result should be returned.

interface GeneratorMeta

interface GeneratorMeta {}
  • Provides information about a generator.

property namespace

namespace: string;
  • The namespace of the generator.

property packagePath

packagePath: string;
  • The path to the package containing the generator.

property resolved

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

interface GeneratorsInOptions

interface GeneratorsInOptions {}
  • Provides options for the findGeneratorsIn method.

property packagePatterns

packagePatterns?: string[] | undefined;
  • The package-patterns to look for.

interface InstantiateOptions

interface InstantiateOptions<
TOptions extends Generator.GeneratorOptions = Generator.GeneratorOptions
> {}
  • Provides options for instantiating a generator.

property arguments

arguments?: string | string[] | undefined;
  • The arguments to pass to the generator.

property options

options?: TOptions | undefined;
  • The options for creating the generator.

interface LookupGeneratorMeta

interface LookupGeneratorMeta extends GeneratorMeta {}
  • Provides information about a generator.

property registered

registered: boolean;
  • A value indicating whether the generator could be registered.

interface LookupOptionBase

interface LookupOptionBase {}
  • Provides options for lookups.

property localOnly

localOnly?: boolean | undefined;
  • A value indicating whether globally installed packages should be ignored.

interface LookupOptions

interface LookupOptions extends LookupOptionBase {}
  • Provides options for the lookup method.

property filePatterns

filePatterns?: string[] | undefined;
  • The file-patterns to look for.

property globbyDeep

globbyDeep?: number | undefined;
  • The deep option to pass to globby.

property npmPaths

npmPaths?: string[] | undefined;
  • The repüository paths to look for generator packages.

property packagePaths

packagePaths?: string[] | undefined;
  • The paths to look for generators.

property packagePatterns

packagePatterns?: string[] | undefined;
  • The package patterns to look for.

property singleResult

singleResult?: boolean | undefined;
  • A value indicating whether the lookup should be stopped after finding the first result.

interface NpmPathsOptions

interface NpmPathsOptions extends LookupOptionBase {}
  • Provides options for the getNpmPaths method.

property filterPaths

filterPaths?: boolean | undefined;
  • A value indicating whether paths which don't end with a supported directory-name should be filtered (unless they are part of NODE_PATH).

interface Options

interface Options {}
  • Represents options for an Environment.

property console

console?: Console;
  • A console instance for logging messages.

property cwd

cwd?: string | undefined;
  • The working-directory of the environment.

property experimental

experimental?: boolean;
  • A value indicating whether the experimental features should be enabled.

property sharedOptions

sharedOptions?: Generator.GeneratorOptions;
  • The options to pass to generators.

property stderr

stderr?: Stream;
  • A stream to write error messages to.

property stdin

stdin?: Stream;
  • A stream for receiving data from.

property stdout

stdout?: Stream;
  • A stream to write normal messages to.

index signature

[key: string]: any;
  • Additional options.

interface SingleGeneratorLookupOptions

interface SingleGeneratorLookupOptions extends GeneratorLookupOptions {}
  • Provides options for single generator lookups.

property singleResult

singleResult: true;

Type Aliases

type Adapter

type Adapter = TerminalAdapter;
  • Represents an adapter.

type Answers

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

type Callback

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

type Logger

type Logger = LoggerBase;
  • Represents a component for logging messages.

type Question

type Question<T extends inquirer.Answers> = inquirer.DistinctQuestion<T>;
  • Represents a question.

type Questions

type Questions<T extends inquirer.Answers> = inquirer.QuestionCollection<T>;
  • Represents a collection of questions.

Package Files (1)

Dependencies (11)

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-environment.

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