From f709b805205dc1bd70623d338541bafaaa06f843 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Tue, 28 May 2024 09:29:23 -0600 Subject: [PATCH] feat: use ansis instead of chalk --- package.json | 2 +- src/commands/schema/compare.ts | 22 +++++++++++----------- src/commands/schema/generate.ts | 4 ++-- src/commands/snapshot/compare.ts | 16 +++++++--------- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 50edbd88..b89e78c3 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dependencies": { "@oclif/core": "^4.0.0-beta.13", "@types/lodash.difference": "^4.5.9", - "chalk": "^5.3.0", + "ansis": "^3.2.0", "globby": "^14.0.1", "just-diff": "^5.2.0", "lodash.difference": "^4.5.0", diff --git a/src/commands/schema/compare.ts b/src/commands/schema/compare.ts index 7f77647e..96089172 100644 --- a/src/commands/schema/compare.ts +++ b/src/commands/schema/compare.ts @@ -1,9 +1,9 @@ import {Flags, toConfiguredId} from '@oclif/core' -import chalk from 'chalk' +import {bold, cyan, underline} from 'ansis' import {Operation, diff} from 'just-diff' import get from 'lodash.get' -import * as fs from 'node:fs' -import * as path from 'node:path' +import fs from 'node:fs' +import path from 'node:path' import * as semver from 'semver' import {Schema} from 'ts-json-schema-generator' @@ -88,7 +88,7 @@ export default class SchemaCompare extends SnapshotCommand { switch (change.op) { case 'replace': { humanReadableChanges[commandId].push( - `${chalk.underline(readablePath)} was changed from ${chalk.cyan(existing)} to ${chalk.cyan(latest)}`, + `${underline(readablePath)} was changed from ${cyan(existing)} to ${cyan(latest)}`, ) break } @@ -96,8 +96,8 @@ export default class SchemaCompare extends SnapshotCommand { case 'add': { humanReadableChanges[commandId].push( lastElementIsNum - ? `Array item at ${chalk.underline(basePath)} was ${chalk.cyan('added')} to latest schema` - : `${chalk.underline(readablePath)} was ${chalk.cyan('added')} to latest schema`, + ? `Array item at ${underline(basePath)} was ${cyan('added')} to latest schema` + : `${underline(readablePath)} was ${cyan('added')} to latest schema`, ) break } @@ -105,8 +105,8 @@ export default class SchemaCompare extends SnapshotCommand { case 'remove': { humanReadableChanges[commandId].push( lastElementIsNum - ? `Array item at ${chalk.underline(basePath)} was ${chalk.cyan('not found')} in latest schema` - : `${chalk.underline(readablePath)} was ${chalk.cyan('not found')} in latest schema`, + ? `Array item at ${underline(basePath)} was ${cyan('not found')} in latest schema` + : `${underline(readablePath)} was ${cyan('not found')} in latest schema`, ) break } @@ -123,10 +123,10 @@ export default class SchemaCompare extends SnapshotCommand { } this.log() - this.log(chalk.bold.red('Found the following schema changes:')) + this.log(bold.red('Found the following schema changes:')) for (const [commandId, changes] of Object.entries(humanReadableChanges)) { this.log() - this.log(chalk.bold(commandId)) + this.log(bold(commandId)) for (const change of changes) { this.log(` - ${change}`) } @@ -136,7 +136,7 @@ export default class SchemaCompare extends SnapshotCommand { const bin = process.platform === 'win32' ? 'bin\\dev.cmd' : 'bin/dev.js' this.log( 'If intended, please update the schema file(s) and run again:', - chalk.bold(`${bin} ${toConfiguredId('schema:generate', this.config)}`), + bold(`${bin} ${toConfiguredId('schema:generate', this.config)}`), ) process.exitCode = 1 return changes diff --git a/src/commands/schema/generate.ts b/src/commands/schema/generate.ts index 31bafd21..a4c5f842 100644 --- a/src/commands/schema/generate.ts +++ b/src/commands/schema/generate.ts @@ -1,5 +1,5 @@ import {Flags, ux} from '@oclif/core' -import chalk from 'chalk' +import {red} from 'ansis' import {globbySync} from 'globby' import fs from 'node:fs' import path from 'node:path' @@ -84,7 +84,7 @@ export class SchemaGenerator { if (error instanceof Error) { const error_ = error.message.toLowerCase().includes('no root type') ? new Error( - `Schema generator could not find the ${chalk.red(returnType)} type. Please make sure that ${chalk.red( + `Schema generator could not find the ${red(returnType)} type. Please make sure that ${red( returnType, )} is exported.`, ) diff --git a/src/commands/snapshot/compare.ts b/src/commands/snapshot/compare.ts index 865bb7fe..3107d073 100644 --- a/src/commands/snapshot/compare.ts +++ b/src/commands/snapshot/compare.ts @@ -1,7 +1,7 @@ import {Flags} from '@oclif/core' -import chalk from 'chalk' +import {green, red} from 'ansis' import difference from 'lodash.difference' -import * as fs from 'node:fs' +import fs from 'node:fs' import {EOL} from 'node:os' import SnapshotCommand, {SnapshotEntry} from '../../snapshot-command.js' @@ -108,16 +108,14 @@ export default class Compare extends SnapshotCommand { // Fail the process since there are changes to the snapshot file process.exitCode = 1 - this.log( - `The following commands and flags have modified: (${chalk.green('+')} added, ${chalk.red('-')} removed)${EOL}`, - ) + this.log(`The following commands and flags have modified: (${green('+')} added, ${red('-')} removed)${EOL}`) for (const command of removedCommands) { - this.log(chalk.red(`\t-${command}`)) + this.log(red(`\t-${command}`)) } for (const command of addedCommands) { - this.log(chalk.green(`\t+${command}`)) + this.log(green(`\t+${command}`)) } const removedProperties: string[] = [] @@ -126,7 +124,7 @@ export default class Compare extends SnapshotCommand { if (properties.some((prop) => prop.added || prop.removed)) this.log(`\t ${propertyName}:`) for (const prop of properties) { if (prop.added || prop.removed) { - const color = prop.added ? chalk.green : chalk.red + const color = prop.added ? green : red this.log(color(`\t\t${prop.added ? '+' : '-'}${prop.name}`)) } @@ -147,7 +145,7 @@ export default class Compare extends SnapshotCommand { // Check if existent commands, or properties (flags, aliases) have been deleted if (removedCommands.length > 0 || removedProperties.length > 0) { - this.log(chalk.red(`${EOL}Since there are deletions, a major version bump is required.`)) + this.log(red(`${EOL}Since there are deletions, a major version bump is required.`)) } return {addedCommands, diffCommands, removedCommands, removedFlags: removedCommands}