Skip to content

Commit

Permalink
fix: replace color library by native color to console log (#43)
Browse files Browse the repository at this point in the history
* fit: fix github workflow

* fit: fix github workflow

* fit: fix github workflow

* fix: replace color library by native color to console log
  • Loading branch information
Lawndlwd authored May 26, 2024
1 parent e3bf03f commit f7ee4b5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-carrots-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"unused-i18n": patch
---

fix dist folder not encluded
5 changes: 5 additions & 0 deletions .changeset/great-walls-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"unused-i18n": patch
---

fix bug on release
5 changes: 5 additions & 0 deletions .changeset/silver-wombats-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"unused-i18n": patch
---

replace color library by native color to console log
5 changes: 5 additions & 0 deletions .changeset/stupid-ears-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"unused-i18n": patch
---

fix changeset
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"coverage": "vitest run --coverage"
},
"dependencies": {
"ansi-colors": "^4.1.3",
"commander": "^12.1.0"
},
"devDependencies": {
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from 'fs'
import { loadConfig } from './utils/loadConfig'
import c from 'ansi-colors'
import { getMissingTranslations } from './utils/missingTranslations'
import { summary } from './utils/summary'
import { searchFilesRecursively } from './lib/search'
Expand Down Expand Up @@ -80,14 +79,13 @@ export const processTranslations = async ({
totalUnusedLocales += pathUnusedLocalesCount

const formattedMissingTranslations = missingTranslations
.map((translation) => c.red(` ${translation}`))
.map((translation) => `\x1b[31m${translation}\x1b[0m`)
.join('\n')

const message = missingTranslations.length
? `Missing translations for ${c.yellow(localeFilePath)}: ${c.red(
`${pathUnusedLocalesCount}`
)} \n${formattedMissingTranslations}`
: c.green(`No missing translations for ${c.yellow(localeFilePath)}`)
? `Missing translations for \x1b[33m${localeFilePath}\x1b[0m : \x1b[31m${pathUnusedLocalesCount} \n${formattedMissingTranslations}\x1b[0m`
: `\x1b[32mNo missing translations for \x1b[33m${localeFilePath}\x1b[0m\x1b[0m`

unusedLocalesCountByPath.push({
path: localPath,
messages: message,
Expand All @@ -101,7 +99,7 @@ export const processTranslations = async ({
})
: null
} else {
const warningMessage = c.red(`Locale file not found: ${localeFilePath}`)
const warningMessage = `\x1b[31mLocale file not found: ${localeFilePath}\x1b[0m`

unusedLocalesCountByPath.push({
path: localPath,
Expand All @@ -111,5 +109,9 @@ export const processTranslations = async ({
})
const endTime = performance.now()
summary({ unusedLocalesCountByPath, totalUnusedLocales })
console.log(c.dim(`Duration : ${(endTime - startTime).toFixed(0)}ms`))
console.log(
`\x1b[38;2;128;128;128mDuration : ${(endTime - startTime).toFixed(
0
)}ms\x1b[0m`
)
}
3 changes: 1 addition & 2 deletions src/utils/summary.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SummaryArgs } from '../types/types'
import c from 'ansi-colors'

export const summary = ({
unusedLocalesCountByPath,
Expand All @@ -12,5 +11,5 @@ export const summary = ({
}
})

console.log(`Total unused locales: ${c.yellow(`${totalUnusedLocales}`)}`)
console.log(`Total unused locales: \x1b[33m${totalUnusedLocales}\x1b[0m`)
}

0 comments on commit f7ee4b5

Please sign in to comment.