Skip to content

Commit

Permalink
feat: use ansis instead of chalk
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed May 28, 2024
1 parent 6287829 commit f709b80
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 11 additions & 11 deletions src/commands/schema/compare.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -88,25 +88,25 @@ 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
}

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
}

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
}
Expand All @@ -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}`)
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/commands/schema/generate.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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.`,
)
Expand Down
16 changes: 7 additions & 9 deletions src/commands/snapshot/compare.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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[] = []
Expand All @@ -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}`))
}

Expand All @@ -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}
Expand Down

0 comments on commit f709b80

Please sign in to comment.