new Environment(args, opts, adaperopt)
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
String | Array | ||||||||||||||||||||||||||||||
opts |
Object |
Properties
|
|||||||||||||||||||||||||||||
adaper |
TerminalAdapter | <optional> |
A TerminalAdapter instance or another object implementing this adapter interface. This is how you'd interface Yeoman with a GUI or an editor. |
- Mixes In:
Members
-
static util
-
Expose the utilities on the module
- See:
-
- env/util
Methods
-
static createEnv() → {Environment}
-
Factory method to create an environment instance. Take same parameters as the Environment constructor.
- See:
-
- This method take the same arguments as Environment constructor
-
static createEnvWithVersion(version, …args) → {Environment}
-
Factory method to create an environment instance. Take same parameters as the Environment constructor.
Parameters:
Name Type Attributes Description versionString Version of the Environment
argsany <repeatable> Same arguments as Environment constructor.
-
static enforceUpdate(env) → {Environment}
-
Make sure the Environment present expected methods if an old version is passed to a Generator.
Parameters:
Name Type Description envEnvironment -
static lookupGenerator(namespace, optionsopt) → {String}
-
Lookup for a specific generator.
Parameters:
Name Type Attributes Description namespaceString optionsObject <optional> Properties
Name Type Attributes Default Description localOnlyBoolean <optional> false Set true to skip lookups of globally-installed generators.
packagePathBoolean <optional> false Set true to return the package path instead of generators file.
singleResultBoolean <optional> true Set false to return multiple values.
Returns:
String -generator
-
static namespaceToName(namespace) → {String}
-
Convert a generators namespace to its name
Parameters:
Name Type Description namespaceString Returns:
String -
alias(match, value)
-
Get or create an alias.
Alias allows the
get()andlookup()methods to search in alternate filepath for a given namespaces. It's used for example to mapgenerator-*npm package to their namespace equivalent (without the generator- prefix), or to default a single namespace likeangulartoangular:apporangular:all.Given a single argument, this method acts as a getter. When both name and value are provided, acts as a setter and registers that new alias.
If multiple alias 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().
Parameters:
Name Type Description matchString | RegExp valueString - Mixes In:
Example
env.alias(/^([a-zA-Z0-9:\*]+)$/, 'generator-$1'); env.alias(/^([^:]+)$/, '$1:app'); env.alias(/^([^:]+)$/, '$1:all'); env.alias('foo'); // => generator-foo:all -
create(namespaceOrPath, options)
-
Create is the Generator factory. It takes a namespace to lookup and optional hash of options, that lets you define
argumentsandoptionsto instantiate the generator with.An error is raised on invalid namespace.
Parameters:
Name Type Description namespaceOrPathString optionsObject -
error(err, verifyListeneropt) → {Error}
-
Error handler taking
errinstance of Error.The
errorevent is emitted with the error object, if noerrorlistener is registered, then we throw the error.Parameters:
Name Type Attributes Description errObject verifyListenerBoolean <optional> Only emit error if a listener is registered.
Returns:
Error -err
-
findGeneratorsIn(List, optionsopt) → {Array}
-
Search npm for every available generators. Generators are npm packages who's name start with
generator-and who're placed in the top levelnode_modulepath. They can be installed globally or locally.Parameters:
Name Type Attributes Description ListArray of search paths
optionsObject <optional> Properties
Name Type Attributes Default Description packagePatternsboolean <optional> 'generator-*' Pattern pattern.
Returns:
Array -List of the generator modules path
- Mixes In:
- Deprecated:
-
- Yes
-
get(namespaceOrPath) → {Generator|null}
-
Get a single 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:commonnamespace is registered, and we try to getangular:common:allthen we getangular:commonas a fallback (unless anangular:common:allgenerator is registered).Parameters:
Name Type Description namespaceOrPathString Returns:
Generator | null -- the generator registered under the namespace
-
getByPath(path) → {Generator|null}
-
Get a generator by path instead of namespace.
Parameters:
Name Type Description pathString Returns:
Generator | null -- the generator found at the location
-
getGeneratorNames() → {Array}
-
Get registered generators names
Returns:
Array -
getGeneratorsMeta() → {Object}
-
Returns stored generators meta
Returns:
Object -
getNpmPaths(optionsopt) → {Array}
-
Get the npm lookup directories (
node_modules/)Parameters:
Name Type Attributes Description optionsboolean | Object <optional> Properties
Name Type Attributes Default Description localOnlyboolean <optional> false Set true to skip lookups of globally-installed generators.
filterPathsboolean <optional> false Remove paths that don't ends with a supported path (don't touch at NODE_PATH paths).
Returns:
Array -lookup paths
- Mixes In:
- Deprecated:
-
- Yes
-
getPackagePath(namespace) → {String}
-
Get last added path for a namespace
Parameters:
Name Type Description namespaceString namespace
Returns:
String -- path of the package
-
getPackagePaths(namespace) → {Array}
-
Get paths for a namespace
Parameters:
Name Type Description namespaceString namespace
Returns:
Array -- array of paths.
-
getRegisteredPackages() → {Array}
-
Get all registered packages namespaces.
Returns:
Array -- array of namespaces.
-
getVersion(packageName) → {String}
-
Returns the environment or dependency version.
Parameters:
Name Type Description packageNameString Module to get version.
Returns:
String -Environment version.
-
help(name)
-
Outputs the general help and usage. Optionally, if generators have been registered, the list of available generators is also displayed.
Parameters:
Name Type Description nameString -
installLocalGenerators(packages) → {Boolean}
-
Install generators at the custom local repository and register.
Parameters:
Name Type Description packagesObject packages to install key(packageName): value(versionRange).
Returns:
Boolean -- true if the install succeeded.
- Mixes In:
-
instantiate(generator, optionsopt)
-
Instantiate a Generator with metadatas
Parameters:
Name Type Attributes Description generatorClass.<Generator> Generator class
optionsObject <optional> Properties
Name Type Attributes Description argumentsArray | String <optional> Arguments to pass the instance
optionsObject <optional> Options to pass the instance
-
isPackageRegistered(packageNSopt) → {boolean}
-
Verify if a package namespace already have been registered.
Parameters:
Name Type Attributes Description packageNSString <optional> namespace of the package.
Returns:
boolean -- true if any generator of the package has been registered
-
lookup(optionsopt, cb) → {Array.<Object>}
-
Search for generators and their sub generators.
A generator is a
:lookup/:name/index.jsfile placed inside an npm package.Defaults lookups are:
- ./
- generators/
- lib/generators/
So this index file
node_modules/generator-dummy/lib/generators/yo/index.jswould be registered asdummy:yogenerator.Parameters:
Name Type Attributes Description optionsboolean | Object <optional> Properties
Name Type Attributes Default Description localOnlyboolean <optional> false Set true to skip lookups of globally-installed generators.
packagePathsstring | Array <optional> Paths to look for generators.
npmPathsstring | Array <optional> Repository paths to look for generators packages.
filePatternsstring | Array <optional> '*\/index.js' File pattern to look for.
packagePatternsstring | Array <optional> 'generator-*' Package pattern to look for.
singleResultboolean <optional> false Set true to stop lookup on the first match.
globbyDeepNumber <optional> Deep option to be passed to globby.
cbfunction Callback called once the lookup is done. Take err as first parameter.
Returns:
Array.<Object> -List of generators
- Mixes In:
-
lookupLocalPackages(packagesToLookupopt)
-
Lookup and register generators from the custom local repository.
Parameters:
Name Type Attributes Default Description packagesToLookupArray.<String> <optional> 'generator-*' packages to lookup.
- Mixes In:
-
namespace(filepath, lookups)
-
Given a String
filepath, tries to figure out the relative namespace.Examples:
this.namespace('backbone/all/index.js'); // => backbone:all this.namespace('generator-backbone/model'); // => backbone:model this.namespace('backbone.js'); // => backbone this.namespace('generator-mocha/backbone/model/index.js'); // => mocha:backbone:modelParameters:
Name Type Description filepathString lookupsArray paths
-
namespaces() → {Array}
-
Returns the list of registered namespace.
Returns:
Array -
register(name, namespace, packagePath) → {Object}
-
Registers a specific
generatorto this environment. This generator is stored under provided namespace, or a default namespace format if none if available.Parameters:
Name Type Description nameString Filepath to the a generator or a npm package name
namespaceString Namespace under which register the generator (optional)
packagePathString PackagePath to the generator npm package (optional)
Returns:
Object -environment - This environment
-
registerStub(Generator, namespace, resolvedopt, packagePathopt) → {this}
-
Register a stubbed generator to this environment. This method allow to register raw functions under the provided namespace.
registerStubwill enforce the function passed to extend the Base generator automatically.Parameters:
Name Type Attributes Description Generatorfunction A Generator constructor or a simple function
namespaceString Namespace under which register the generator
resolvedString <optional> The file path to the generator
packagePathString <optional> The generator's package path
Returns:
this -
resolveModulePath(moduleId) → {String}
-
Resolve a module path
Parameters:
Name Type Description moduleIdString Filepath or module name
Returns:
String -- The resolved path leading to the module
-
rootGenerator() → {Generator}
-
Get the first generator that was queued to run in this environment.
Returns:
Generator -generator queued to run in this environment.
-
run(args, optionsopt, doneopt)
-
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.
Parameters:
Name Type Attributes Description argsString | Array optionsObject <optional> donefunction <optional> -
runGenerator(generator, doneopt)
-
Convenience method to run the generator with callbackWrapper. See https://github.com/yeoman/environment/pull/101
Parameters:
Name Type Attributes Description generatorObject donefunction <optional>