当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript findup.sync函数代码示例

本文整理汇总了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,
  };
}
开发者ID:akc42,项目名称:polymer-cli,代码行数:35,代码来源:init.ts

示例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;
}
开发者ID:augint,项目名称:polymer-cli,代码行数:12,代码来源:build.ts


注:本文中的findup.sync函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。