本文整理汇总了TypeScript中yeoman-environment.getGeneratorsMeta函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getGeneratorsMeta函数的具体用法?TypeScript getGeneratorsMeta怎么用?TypeScript getGeneratorsMeta使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getGeneratorsMeta函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: runGenerator
export async function runGenerator(
generatorName: string, options: {[name: string]: any} = {}): Promise<void> {
const templateName = options['templateName'] || generatorName;
const env: YeomanEnvironment =
await (options['env'] || createYeomanEnvironment());
logger.info(`Running template ${templateName}...`);
logger.debug(`Running generator ${generatorName}...`);
const generators = env.getGeneratorsMeta();
const generator = generators[generatorName];
if (!generator) {
logger.error(`Template ${templateName} not found`);
throw new Error(`Template ${templateName} not found`);
}
return new Promise<void>((resolve, reject) => {
env.run(generatorName, {}, (error: any) => {
if (error) {
reject(error);
return;
}
resolve();
});
});
}
示例2: createSelectPrompt
/**
* Create the prompt used for selecting which template to run. Generate
* the list of available generators by filtering relevent ones out from
* the environment list.
*/
function createSelectPrompt(env: YeomanEnvironment) {
const generators = env.getGeneratorsMeta();
const allGeneratorNames = Object.keys(generators).filter((k) => {
return k.startsWith('polymer-init') && k !== 'polymer-init:app';
});
const choices = allGeneratorNames.map((generatorName: string) => {
const generator = generators[generatorName];
return getGeneratorDescription(generator, generatorName);
});
return {
message: 'Which starter template would you like to use?',
choices: choices,
};
}
示例3: createSelectPrompt
/**
* Create the prompt used for selecting which template to run. Generate
* the list of available generators by filtering relevent ones out from
* the environment list.
*/
function createSelectPrompt(env: YeomanEnvironment): InquirerQuestion {
const generators = env.getGeneratorsMeta();
const allGeneratorNames = Object.keys(generators).filter((k) => {
return k.startsWith('polymer-init') && k !== 'polymer-init:app';
});
const choices = allGeneratorNames.map((generatorName: string) => {
const generator = generators[generatorName];
return getGeneratorDescription(generator, generatorName);
});
// Some windows emulators (mingw) don't handle arrows correctly
// https://github.com/SBoudrias/Inquirer.js/issues/266
// Fall back to rawlist and use number input
// Credit to
// https://gist.github.com/geddski/c42feb364f3c671d22b6390d82b8af8f
const isMinGW = checkIsMinGW();
return {
type: isMinGW ? 'rawlist' : 'list',
name: 'generatorName',
message: 'Which starter template would you like to use?',
choices: choices,
};
}