當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript BuilderContext.reportProgress方法代碼示例

本文整理匯總了TypeScript中@angular-devkit/architect.BuilderContext.reportProgress方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript BuilderContext.reportProgress方法的具體用法?TypeScript BuilderContext.reportProgress怎麽用?TypeScript BuilderContext.reportProgress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@angular-devkit/architect.BuilderContext的用法示例。


在下文中一共展示了BuilderContext.reportProgress方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: update

 function update(status: string) {
   context.reportProgress(
     modulesDone + hooksDone,
     modulesCount + Math.max(hooksDone, numberOfHooks),
     status,
   );
 }
開發者ID:angular,項目名稱:angular-cli,代碼行數:7,代碼來源:architect.ts

示例2: _run

async function _run(
  options: TslintBuilderOptions,
  context: BuilderContext,
): Promise<BuilderOutput> {
  const systemRoot = context.workspaceRoot;
  process.chdir(context.currentDirectory);
  const projectName = (context.target && context.target.project) || '<???>';

  // Print formatter output only for non human-readable formats.
  const printInfo =
    ['prose', 'verbose', 'stylish'].includes(options.format || '') && !options.silent;

  context.reportStatus(`Linting ${JSON.stringify(projectName)}...`);
  if (printInfo) {
    context.logger.info(`Linting ${JSON.stringify(projectName)}...`);
  }

  if (!options.tsConfig && options.typeCheck) {
    throw new Error('A "project" must be specified to enable type checking.');
  }

  const projectTslint = await _loadTslint();
  const tslintConfigPath = options.tslintConfig
    ? path.resolve(systemRoot, options.tslintConfig)
    : null;
  const Linter = projectTslint.Linter;

  let result: undefined | LintResult = undefined;
  if (options.tsConfig) {
    const tsConfigs = Array.isArray(options.tsConfig) ? options.tsConfig : [options.tsConfig];
    context.reportProgress(0, tsConfigs.length);
    const allPrograms = tsConfigs.map(tsConfig => {
      return Linter.createProgram(path.resolve(systemRoot, tsConfig));
    });

    let i = 0;
    for (const program of allPrograms) {
      const partial = await _lint(
        projectTslint,
        systemRoot,
        tslintConfigPath,
        options,
        program,
        allPrograms,
      );
      if (result === undefined) {
        result = partial;
      } else {
        result.failures = result.failures
          .filter(curr => {
            return !partial.failures.some(prev => curr.equals(prev));
          })
          .concat(partial.failures);

        // we are not doing much with 'errorCount' and 'warningCount'
        // apart from checking if they are greater than 0 thus no need to dedupe these.
        result.errorCount += partial.errorCount;
        result.warningCount += partial.warningCount;
        result.fileNames = [...new Set([...result.fileNames, ...partial.fileNames])];

        if (partial.fixes) {
          result.fixes = result.fixes ? result.fixes.concat(partial.fixes) : partial.fixes;
        }
      }

      context.reportProgress(++i, allPrograms.length);
    }
  } else {
    result = await _lint(projectTslint, systemRoot, tslintConfigPath, options);
  }

  if (result == undefined) {
    throw new Error('Invalid lint configuration. Nothing to lint.');
  }

  if (!options.silent) {
    const Formatter = projectTslint.findFormatter(options.format || '');
    if (!Formatter) {
      throw new Error(`Invalid lint format "${options.format}".`);
    }
    const formatter = new Formatter();

    const output = formatter.format(result.failures, result.fixes, result.fileNames);
    if (output.trim()) {
      context.logger.info(output);
    }
  }

  if (result.warningCount > 0 && printInfo) {
    context.logger.warn('Lint warnings found in the listed files.');
  }

  if (result.errorCount > 0 && printInfo) {
    context.logger.error('Lint errors found in the listed files.');
  }

  if (result.warningCount === 0 && result.errorCount === 0 && printInfo) {
    context.logger.info('All files pass linting.');
  }

//.........這裏部分代碼省略.........
開發者ID:angular,項目名稱:angular-cli,代碼行數:101,代碼來源:index.ts


注:本文中的@angular-devkit/architect.BuilderContext.reportProgress方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。