當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。