本文整理汇总了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;
}