Handles the lifecycle and bootstrapping of generators in a specific environment
npx @tessl/cli install tessl/npm-yeoman-environment@4.4.0Yeoman Environment is a TypeScript library that handles the lifecycle and bootstrapping of generators in a specific environment. It provides a high-level API to discover, create, and run generators with advanced configuration options for resolver behavior and runtime environment management. The package serves as the core infrastructure for Yeoman's scaffolding system, providing the runtime environment that coordinates between generators and the user's development workspace.
npm install yeoman-environmentimport Environment, {
createEnv,
EnvironmentBase,
YeomanCommand,
lookupGenerator,
addEnvironmentOptions,
prepareCommand,
prepareGeneratorCommand,
commitSharedFsTask,
packageManagerInstallTask,
removePropertiesWithNullishValues,
moduleLookupSync,
findPackagesIn,
getNpmPaths,
defaultExtensions,
UNKNOWN_NAMESPACE,
UNKNOWN_RESOLVED,
defaultQueues
} from "yeoman-environment";For CommonJS:
const Environment = require("yeoman-environment").default;
const {
createEnv,
EnvironmentBase,
YeomanCommand,
lookupGenerator,
addEnvironmentOptions,
prepareCommand,
prepareGeneratorCommand,
commitSharedFsTask,
packageManagerInstallTask,
removePropertiesWithNullishValues,
moduleLookupSync,
findPackagesIn,
getNpmPaths,
defaultExtensions,
UNKNOWN_NAMESPACE,
UNKNOWN_RESOLVED,
defaultQueues
} = require("yeoman-environment");import { createEnv } from "yeoman-environment";
// Create environment instance
const env = createEnv();
// Search for installed generators
await env.lookup();
// Run a generator
await env.run("angular", { skipInstall: true });
// Execute a specific generator with arguments
await env.execute("app:component", ["UserCard", "--style=css"]);Yeoman Environment is built around several key components:
Environment, EnvironmentBase)Core environment functionality for managing generator lifecycles, registration, and execution.
function createEnv(options?: EnvironmentOptions): Environment;
class Environment extends EnvironmentBase {
constructor(options?: EnvironmentOptions);
help(name?: string): string;
execute(generatorNamespace: string, args?: string[]): Promise<void>;
requireGenerator(namespace: string): Promise<BaseGeneratorConstructor | undefined>;
installLocalGenerators(packages: Record<string, string | undefined>): Promise<boolean>;
lookupLocalPackages(packagesToLookup?: string[]): Promise<void>;
run(args?: string[], options?: any): Promise<void>;
}
interface EnvironmentOptions extends BaseEnvironmentOptions {
adapter?: InputOutputAdapter;
logCwd?: string;
command?: YeomanCommand;
yeomanRepository?: string;
arboristRegistry?: string;
nodePackageManager?: string;
}Generator discovery and lookup system for finding installed generators across various locations.
function lookupGenerator(
namespace: string,
options?: ModuleLookupOptions & {
packagePath?: boolean;
generatorPath?: boolean;
}
): string | string[];
interface LookupOptions extends LookupOptionsApi {
lookups?: string[];
localOnly?: boolean;
packagePaths?: string | string[];
npmPaths?: string | string[];
filePatterns?: string | string[];
packagePatterns?: string | string[];
singleResult?: boolean;
}Registration, instantiation, and execution of generators with metadata management.
interface BaseEnvironment {
register(pathOrStub: unknown, meta?: Partial<BaseGeneratorMeta>): GeneratorMeta;
get<C>(namespaceOrPath: string | YeomanNamespace): Promise<C | undefined>;
create<G>(namespaceOrPath: string | GetGeneratorConstructor<G>, ...args: any[]): Promise<G>;
instantiate<G>(generator: GetGeneratorConstructor<G>, ...args: any[]): Promise<G>;
composeWith<G>(generator: string | GetGeneratorConstructor<G>, ...args: any[]): Promise<G>;
runGenerator(generator: BaseGenerator): Promise<void>;
queueGenerator<G>(generator: G, queueOptions?: { schedule?: boolean }): Promise<G>;
}CLI command creation and management with Commander.js integration for generator commands.
class YeomanCommand extends Command {
env?: BaseEnvironment;
createCommand(name?: string): YeomanCommand;
addOption(option: Option): YeomanCommand;
registerGenerator(generator: any): YeomanCommand;
addGeneratorArguments(generatorArgs: any[]): YeomanCommand;
addGeneratorOptions(options: Record<string, any>): YeomanCommand;
}
function addEnvironmentOptions(command?: YeomanCommand): YeomanCommand;
function prepareCommand(options: CommandPreparation): Promise<YeomanCommand>;
function prepareGeneratorCommand(options: CommandPreparation): Promise<YeomanCommand>;
interface CommandPreparation {
resolved?: string;
command?: YeomanCommand;
generator?: BaseGeneratorConstructor;
namespace?: string;
}Memory filesystem operations, conflict resolution, and file transforms for generator output.
function commitSharedFsTask(options: {
adapter: InputOutputAdapter;
conflicterOptions?: ConflicterOptions;
sharedFs: Store<MemFsEditorFile>;
}): Promise<void>;
function packageManagerInstallTask(options: PackageManagerInstallTaskOptions): Promise<boolean>;
interface PackageManagerInstallTaskOptions {
memFs: Store<MemFsEditorFile>;
packageJsonLocation: string;
adapter: InputOutputAdapter;
nodePackageManager?: string;
customInstallTask?: boolean | ((nodePackageManager: string | undefined, defaultTask: () => Promise<boolean>) => void | Promise<void>);
skipInstall?: boolean;
}Utility functions for data manipulation and environment operations.
function removePropertiesWithNullishValues(object: Record<string, any>): Record<string, any>;Module and package discovery utilities for finding generators in npm packages.
function moduleLookupSync(patterns: string | string[], options?: {
packageJson?: boolean;
singleResult?: boolean;
lookups?: string[];
npmPaths?: string | string[];
}): string | string[];
function findPackagesIn(
patterns: string | string[],
searchPaths: string[]
): string[];
function getNpmPaths(paths?: string | string[]): string[];Predefined constants used throughout the environment system.
const defaultExtensions: string[];
const UNKNOWN_NAMESPACE: string;
const UNKNOWN_RESOLVED: string;
const defaultQueues: string[];interface BaseGeneratorMeta {
namespace: string;
resolved?: string;
packagePath?: string;
}
interface GeneratorMeta extends BaseGeneratorMeta {
instantiate(...args: any[]): Promise<BaseGenerator>;
instantiateHelp(): Promise<BaseGenerator>;
}
interface EnvironmentLookupOptions extends LookupOptions {
registerToScope?: string;
customizeNamespace?: (ns?: string) => string | undefined;
}
type YeomanNamespace = {
packageNamespace: string;
generator?: string;
scope?: string;
instanceId?: string;
};
interface BaseEnvironmentOptions {
cwd?: string;
skipInstall?: boolean;
forceInstall?: boolean;
skipCache?: boolean;
skipLocalCache?: boolean;
skipParseOptions?: boolean;
localConfigOnly?: boolean;
askAnswered?: boolean;
}
interface LookupOptionsApi {
lookups?: string[];
localOnly?: boolean;
packagePaths?: string | string[];
npmPaths?: string | string[];
filePatterns?: string | string[];
packagePatterns?: string | string[];
singleResult?: boolean;
}
interface InputOutputAdapter {
log: {
write(message?: string): void;
writeln(message?: string): void;
ok(message?: string): void;
error(message?: string): void;
info(message?: string): void;
warning(message?: string): void;
};
prompt: (questions: any) => Promise<any>;
}
interface BaseGeneratorConstructor {
new (...args: any[]): BaseGenerator;
}
interface BaseGenerator {
arguments: string[];
options: Record<string, any>;
run(): Promise<void>;
}
interface Store<T> {
add(file: T): void;
get(path: string): T | undefined;
each(callback: (file: T, path: string) => void): void;
}
interface ConflicterOptions {
force?: boolean;
bail?: boolean;
ignoreWhitespace?: boolean;
regenerateFiles?: boolean;
}