本文整理匯總了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,
};
}