本文整理匯總了TypeScript中findup.sync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript sync函數的具體用法?TypeScript sync怎麽用?TypeScript sync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了sync函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getGeneratorDescription
/**
* Get a description for the given generator. If this is an external generator,
* read the description from its package.json.
*/
function getGeneratorDescription(generator: YeomanEnvironment.GeneratorMeta, generatorName: string): GeneratorDescription {
let name = getDisplayName(generatorName);
let description = 'no description';
if (templateDescriptions.hasOwnProperty(name)) {
description = templateDescriptions[name];
} else if (generator.resolved && generator.resolved !== 'unknown') {
try {
let metapath = findup.sync(generator.resolved, 'package.json');
let meta = JSON.parse(fs.readFileSync(metapath, 'utf8'));
description = meta.description;
} catch (err) {
if (err.message === 'not found') {
logger.debug('no package.json found for generator');
} else {
logger.debug('problem reading/parsing package.json for generator', {
generator: generatorName,
err: err.message,
});
}
}
}
return {
name: `${name}: ${chalk.dim(description)}`,
value: generatorName,
// inquirer is broken and doesn't print descriptions :(
// keeping this so things work when it does
short: name,
};
}
示例2: getGulpfile
function getGulpfile(): any {
// TODO: Should we really be searching procses.cwd()? What about config.root?
let foundGulpfileDir = findup.sync(process.cwd(), 'gulpfile.js');
if (foundGulpfileDir) {
let gulpfulePath = path.join(foundGulpfileDir, 'gulpfile.js');
logger.debug('found gulpfile', { path: gulpfulePath });
return require(gulpfulePath);
}
logger.debug(`no gulpfile found (searched up from ${process.cwd()})`);
return null;
}