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


TypeScript chalk.Chalk类代码示例

本文整理汇总了TypeScript中chalk.Chalk的典型用法代码示例。如果您正苦于以下问题:TypeScript Chalk类的具体用法?TypeScript Chalk怎么用?TypeScript Chalk使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Chalk类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: catch

    ws.on('message', data => {
      let msg;

      try {
        data = data.toString();
        msg = JSON.parse(data);
      } catch (e) {
        process.stderr.write(`Error parsing JSON message from dev server: "${data}" ${chalk.red(e.stack ? e.stack : e)}\n`);
        return;
      }

      if (!isDevServerMessage(msg)) {
        const m = util.inspect(msg, { colors: chalk.enabled });
        process.stderr.write(`Bad format in dev server message: ${m}\n`);
        return;
      }

      if (msg.category === 'console') {
        let status: Chalk | undefined; // unknown levels are normal color

        if (msg.type === 'info' || msg.type === 'log') {
          status = chalk.reset;
        } else if (msg.type === 'error') {
          status = chalk.red;
        } else if (msg.type === 'warn') {
          status = chalk.yellow;
        }

        if (status) {
          process.stdout.write(`[${status('console.' + msg.type)}]: ${msg.data.join(' ')}\n`);
        } else {
          process.stdout.write(`[console]: ${msg.data.join(' ')}\n`);
        }
      }
    });
开发者ID:driftyco,项目名称:ionic-cli,代码行数:35,代码来源:dev-server.ts

示例2: highlightTrailingSpaces

const highlightLeadingTrailingSpaces = (line: string, bgColor: Chalk): string =>
  // If line consists of ALL spaces: highlight all of them.
  highlightTrailingSpaces(line, bgColor).replace(
    // If line has an ODD length of leading spaces: highlight only the LAST.
    /^(\s\s)*(\s)(?=[^\s])/,
    '$1' + bgColor('$2'),
  );
开发者ID:elliottsj,项目名称:jest,代码行数:7,代码来源:diffStrings.ts

示例3: defaultErrorFormatter

/**
 * The default error formatter.
 */
function defaultErrorFormatter(error: ErrorInfo, colors: Chalk) {
  const messageColor =
    error.severity === 'warning' ? colors.bold.yellow : colors.bold.red;

  return (
    colors.grey('[tsl] ') +
    messageColor(error.severity.toUpperCase()) +
    (error.file === ''
      ? ''
      : messageColor(' in ') +
        colors.bold.cyan(`${error.file}(${error.line},${error.character})`)) +
    constants.EOL +
    messageColor(`      TS${error.code}: ${error.content}`)
  );
}
开发者ID:johnnyreilly,项目名称:ts-loader,代码行数:18,代码来源:utils.ts

示例4: bgColor

const highlightTrailingSpaces = (line: string, bgColor: Chalk): string =>
  line.replace(/\s+$/, bgColor('$&'));
开发者ID:elliottsj,项目名称:jest,代码行数:2,代码来源:diffStrings.ts

示例5: successfulTypeScriptInstance

function successfulTypeScriptInstance(
  loaderOptions: LoaderOptions,
  loader: Webpack,
  log: logger.Logger,
  colors: Chalk,
  compiler: typeof typescript,
  compilerCompatible: boolean,
  compilerDetailsLogMessage: string
) {
  const configFileAndPath = getConfigFile(
    compiler,
    colors,
    loader,
    loaderOptions,
    compilerCompatible,
    log,
    compilerDetailsLogMessage!
  );

  if (configFileAndPath.configFileError !== undefined) {
    const { message, file } = configFileAndPath.configFileError;
    return {
      error: makeError(
        colors.red('error while reading tsconfig.json:' + EOL + message),
        file
      )
    };
  }

  const { configFilePath, configFile } = configFileAndPath;
  const basePath = loaderOptions.context || path.dirname(configFilePath || '');
  const configParseResult = getConfigParseResult(
    compiler,
    configFile,
    basePath
  );

  if (configParseResult.errors.length > 0 && !loaderOptions.happyPackMode) {
    const errors = formatErrors(
      configParseResult.errors,
      loaderOptions,
      colors,
      compiler,
      { file: configFilePath },
      loader.context
    );

    loader._module.errors.push(...errors);

    return {
      error: makeError(
        colors.red('error while parsing tsconfig.json'),
        configFilePath
      )
    };
  }

  const compilerOptions = getCompilerOptions(configParseResult);
  const files: TSFiles = new Map<string, TSFile>();
  const otherFiles: TSFiles = new Map<string, TSFile>();

  // same strategy as https://github.com/s-panferov/awesome-typescript-loader/pull/531/files
  let { getCustomTransformers: customerTransformers } = loaderOptions;
  let getCustomTransformers = Function.prototype;

  if (typeof customerTransformers === 'function') {
    getCustomTransformers = customerTransformers;
  } else if (typeof customerTransformers === 'string') {
    try {
      customerTransformers = require(customerTransformers);
    } catch (err) {
      throw new Error(
        `Failed to load customTransformers from "${
          loaderOptions.getCustomTransformers
        }": ${err.message}`
      );
    }

    if (typeof customerTransformers !== 'function') {
      throw new Error(
        `Custom transformers in "${
          loaderOptions.getCustomTransformers
        }" should export a function, got ${typeof getCustomTransformers}`
      );
    }
    getCustomTransformers = customerTransformers;
  }

  if (loaderOptions.transpileOnly) {
    // quick return for transpiling
    // we do need to check for any issues with TS options though
    const program =
      configParseResult.projectReferences !== undefined
        ? compiler!.createProgram({
            rootNames: configParseResult.fileNames,
            options: configParseResult.options,
            projectReferences: configParseResult.projectReferences
          })
        : compiler!.createProgram([], compilerOptions);

//.........这里部分代码省略.........
开发者ID:johnnyreilly,项目名称:ts-loader,代码行数:101,代码来源:instances.ts

示例6: color

 return content.replace(regex, (item, pos, originalText) => {
     return color(this.applyBinding(item, model, 2));
 });
开发者ID:dotnetprofessional,项目名称:LiveDoc,代码行数:3,代码来源:LiveDocReporter.ts

示例7: logger

 ? (message: string) => logger(stderrConsole, yellow(message))
开发者ID:stoneChen,项目名称:ts-loader,代码行数:1,代码来源:logger.ts


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