Skip to content

Commit

Permalink
fix: some bugs on ignore path (#51)
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

* fix: readme file

* fix: build setup with vite

* fix: build setup with vite

* fix: build setup with vite

* fix: some bugs

* fix: add vite  (#47)

* fit: fix github workflow

* fit: fix github workflow

* fit: fix github workflow

* fix: replace color library by native color to console log

* fix: readme file

* fix: build setup with vite

* chore: release (#48)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix:  build setup with vite (#49)

* fit: fix github workflow

* fit: fix github workflow

* fit: fix github workflow

* fix: replace color library by native color to console log

* fix: readme file

* fix: build setup with vite

* fix: build setup with vite

* fix: build setup with vite

* chore: release (#50)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed May 31, 2024
1 parent 84d9d2f commit 6f1f435
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-years-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"unused-i18n": patch
---

Fix some bugs
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Simplifies managing and cleaning up unused translation keys in localization file
- Analyzes source files to identify used and unused translation keys.
- Supports multiple scoped translation functions.
- Can display or remove unused translation keys.
- Configurable through a JSON, JS, or TS config file.
- Configurable through a JSON, CJS, or JS config file.

## Installation

Expand All @@ -25,10 +25,8 @@ npm install -D unused-i18n

Create a unused-i18n.config.json or unused-i18n.config.js file in the root of your project. Here's an example configuration:

```ts
import type { Config } from 'unused-i18n'

const config = {
```cjs
module.exports = {
paths: [
{
srcPath: ['src/pages/products'],
Expand All @@ -40,9 +38,7 @@ const config = {
scopedNames: ['scopedT', 'scopedTOne'],
ignorePaths: ['src/pages/products/ignoreThisFolder'],
excludeKey: ['someKey'],
} satisfies Config

export default config
}
```

| Option | Type | Default | Required | Description |
Expand Down Expand Up @@ -118,6 +114,7 @@ Contributions are welcome! Please open an issue or submit a pull request if you

Acknowledgements

- [Rollup](https://rollupjs.org/) - Module bundler used in this project.
- [Vite](https://vitejs.dev/) - Next Generation Frontend Tooling.
- [TypeScript](https://www.typescriptlang.org/) - Typed JavaScript used in this project.
- [Vitest](https://vitest.dev/guide/cli) - Testing framework used in this project.
- [Commander](https://github.com/tj/commander.js#readme) - Node.js command-line interfaces.
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export const processTranslations = async ({
let pathUnusedLocalesCount = 0

srcPath.forEach((pathEntry) => {
if (config.ignorePaths && config.ignorePaths.includes(pathEntry)) return
const ignorePathExists = config.ignorePaths?.some(
(ignorePath) => ignorePath === pathEntry
)
if (ignorePathExists) return
const files = searchFilesRecursively({
excludePatterns,
regex: /use-i18n/,
Expand Down Expand Up @@ -83,8 +86,8 @@ export const processTranslations = async ({
.join('\n')

const message = missingTranslations.length
? `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`
? `Unused translations in \x1b[33m${localeFilePath}\x1b[0m : \x1b[31m${pathUnusedLocalesCount} \n${formattedMissingTranslations}\x1b[0m`
: `\x1b[32mNo unused translations in \x1b[33m${localeFilePath}\x1b[0m\x1b[0m`

unusedLocalesCountByPath.push({
path: localPath,
Expand Down
4 changes: 4 additions & 0 deletions src/utils/summary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SummaryArgs } from '../types'
import { exit } from 'process'

export const summary = ({
unusedLocalesCountByPath,
Expand All @@ -12,4 +13,7 @@ export const summary = ({
})

console.log(`Total unused locales: \x1b[33m${totalUnusedLocales}\x1b[0m`)
if (unusedLocalesCountByPath.length === 1) {
exit(1)
}
}
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const external = (id: string) => {
id.endsWith('fs') ||
id.endsWith('path') ||
id.endsWith('perf_hooks') ||
id.endsWith('process') ||
id.endsWith('commander')
) {
return true
Expand Down
12 changes: 0 additions & 12 deletions vitest.config.ts

This file was deleted.

0 comments on commit 6f1f435

Please sign in to comment.