chalk#red TypeScript Examples

The following examples show how to use chalk#red. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: push.ts    From cli with Apache License 2.0 6 votes vote down vote up
private async applySnapshot(snapshot: Snapshot) {
    CliUx.ux.action.start('Applying snapshot');
    const cfg = this.configuration.get();
    const {flags} = await this.parse(Push);
    const {waitUntilDone} = await this.getOptions();
    const reporter = await snapshot.apply(
      flags.deleteMissingResources,
      waitUntilDone
    );
    await reporter
      .setReportHandler(SnapshotReportStatus.ERROR, async () => {
        await handleReportWithErrors(snapshot, cfg, this.projectPath);
        CliUx.ux.action.stop(red.bold('!'));
      })
      .setReportHandler(SnapshotReportStatus.SUCCESS, () => {
        CliUx.ux.action.stop(green('✔'));
      })
      .handleReport();
  }
Example #2
Source File: APIError.ts    From cli with Apache License 2.0 6 votes vote down vote up
public constructor(
    error: APIErrorResponse | AxiosErrorFromAPI,
    tagLine?: string
  ) {
    super(SeverityLevel.Error);
    let errorCode: string;
    let message: string;
    let status: number | undefined;
    if (this.isFromAxios(error)) {
      errorCode = error.response.data.errorCode;
      message = error.response.data.message;
      status = error.response.status;
    } else {
      errorCode = error.errorCode;
      message = error.message;
    }

    this.name = `APIError - ${errorCode}`;
    this.message = dedent`
    ${tagLine}
    ${status ? `Status code: ${status}\n` : ''}
    Error code: ${red(errorCode)}
    Message: ${red(message)}
    `;
  }
Example #3
Source File: reportPreviewer.ts    From cli with Apache License 2.0 6 votes vote down vote up
private logResourceErrors(
    resourceSnapshotType: string,
    errorOfThisResourceType: Set<string>
  ) {
    CliUx.ux.log(`\n ${this.prettyPrintResourceName(resourceSnapshotType)}`);
    ReportViewer.printAbridgedMessages(
      Array.from(errorOfThisResourceType),
      ReportViewer.errorPlurable,
      red
    );
  }
Example #4
Source File: snapshotCommon.ts    From cli with Apache License 2.0 6 votes vote down vote up
async function internalDryRun(
  project: Project,
  snapshot: Snapshot,
  cfg: Configuration,
  options: DryRunOptions
) {
  let reporter = await snapshot.validate(
    options.deleteMissingResources,
    options.waitUntilDone
  );

  await reporter
    .setReportHandler(SnapshotReportStatus.SUCCESS, () => {
      CliUx.ux.action.stop(green('✔'));
    })
    .setReportHandler(SnapshotReportStatus.ERROR, async () => {
      if (!options.shouldAutoSync) {
        CliUx.ux.action.stop(red.bold('!'));
        return;
      }
      CliUx.ux.warn('Unsynchronized resource detected');
      await tryAutomaticSynchronization(snapshot, cfg, options);

      CliUx.ux.action.start('Validating synchronized snapshot');
      reporter = await internalDryRun(project, snapshot, cfg, {
        ...options,
        shouldAutoSync: false,
      });
    })
    .handleReport();
  return reporter;
}
Example #5
Source File: snapshotCommon.ts    From cli with Apache License 2.0 6 votes vote down vote up
export function handleSnapshotError(err?: Error & {exitCode?: number}) {
  let message = red.bold('!');
  if (CliUx.ux.action.running && typeof err?.name === 'string') {
    message += ` ${err?.name}`;
  }
  CliUx.ux.action.stop(message);

  if (err instanceof PrintableError) {
    err.print();
  } else {
    throw err;
  }
}
Example #6
Source File: log.ts    From yfm-transform with MIT License 6 votes vote down vote up
function createLogger(type: LogLevels) {
    const formatter: Record<string, (v: string) => string> = {
        [LogLevels.INFO]: (msg) => `${green('INFO')} ${msg}`,
        [LogLevels.WARN]: (msg) => `${yellow('WARN')} ${msg}`,
        [LogLevels.ERROR]: (msg) => `${red('ERR ')} ${msg}`,
    };

    return function log(msg: string) {
        const problem = formatter[type](msg);

        if (!problems[type].includes(problem)) {
            problems[type].push(problem);
        }
    };
}
Example #7
Source File: index.ts    From nestjs-proto-gen-ts with MIT License 5 votes vote down vote up
cli = usage('Extract and merge locale files.\nUsage: $0 [options]')
    /* eslint-disable @typescript-eslint/no-var-requires */
    .version(require(`${__dirname}/../../package.json`).version)
    /* eslint-enable @typescript-eslint/no-var-requires */
    .alias('version', 'v')
    .help('help')
    .alias('help', 'h')
    .option('path', {
        alias: 'p',
        describe: 'Path to root directory',
        type: 'array',
        normalize: true
    })
    .option('output', {
        alias: 'o',
        describe: 'Path to output directory',
        type: 'string',
        normalize: true
    })
    .option('template', {
        describe: "Handlebar's template for output",
        type: 'string'
    })
    .option('target', {
        alias: 't',
        describe: 'Proto files',
        default: options.target,
        type: 'array'
    })
    .option('ignore', {
        alias: 'i',
        describe: 'Ignore file or directories',
        default: options.ignore,
        type: 'array'
    })
    .option('comments', {
        alias: 'c',
        describe: 'Add comments from proto',
        default: options.comments,
        type: 'boolean'
    })
    .option('verbose', {
        describe: 'Log all output to console',
        default: options.verbose,
        type: 'boolean'
    })
    .demandOption(['path'], red.bold('Please provide both run and [path] argument to work with this tool'))
    .exitProcess(true)
    .parse(process.argv)
Example #8
Source File: delete.ts    From cli with Apache License 2.0 5 votes vote down vote up
private errorMessageOnDeletion(toDelete: string, e: unknown) {
    return errorMessage(
      this,
      `Error while trying to delete document: ${red(toDelete)}.`,
      e
    );
  }
Example #9
Source File: transferFromOrganization.ts    From cli with Apache License 2.0 5 votes vote down vote up
export async function tryTransferFromOrganization({
  reporter,
  snapshot,
  projectPath,
}: VaultTransferFunctionsParam) {
  if (!projectPath) {
    return false;
  }

  const originOrgId = new Project(projectPath).getResourceManifest()?.orgId;
  if (!originOrgId) {
    return false;
  }

  const shouldTransfer = await CliUx.ux.confirm(
    `\nWould you like to try transfering the vault entries from ${bold.cyan(
      originOrgId
    )} to the destination organization ${bold.cyan(snapshot.targetId)}? (y/n)`
  );
  if (!shouldTransfer) {
    return false;
  }

  const authenticatedClient = new AuthenticatedClient();
  if (!(await authenticatedClient.getUserHasAccessToOrg(originOrgId))) {
    CliUx.ux.warn(dedent`
        We mapped this snapshot to ${bold.cyan(originOrgId)}.
        If you want to transfer the vault entries from ${bold.cyan(
          originOrgId
        )} to ${bold.cyan(snapshot.targetId)},
        authenticate with an account that has access to both organizations and then try again.
      `);
    return false;
  }

  const originOrgVaultEntries = await getAllVaultEntriesFrom(originOrgId);
  const missingEntriesFromOrigin = getEntriesMissingFromOrigin(
    originOrgVaultEntries,
    reporter.missingVaultEntries
  );

  if (missingEntriesFromOrigin.length > 0) {
    CliUx.ux.warn(
      new SnapshotMissingVaultEntriesFromOriginError(
        originOrgId,
        snapshot.targetId,
        missingEntriesFromOrigin
      )
    );
    return false;
  }

  const platformClient = await authenticatedClient.getClient({
    organization: snapshot.targetId,
  });

  try {
    CliUx.ux.action.start('Transfering vault entries');
    await platformClient.vault.import(
      snapshot.id,
      originOrgId,
      VaultFetchStrategy.onlyMissing
    );
    CliUx.ux.action.stop(green('✔'));
    return true;
  } catch (error) {
    CliUx.ux.action.stop(red.bold('!'));
    CliUx.ux.warn('Error encountered while transfering vault entries`');
    CliUx.ux.warn(typeof error === 'string' ? error : JSON.stringify(error));
    return false;
  }
}
Example #10
Source File: logger.ts    From react-performance-testing with MIT License 5 votes vote down vote up
logError = (msg: Error | string) =>
  console.error(red('Error: '), msg)