Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add 'silent' configuration option #180

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
✨ add 'silent' configuration option
thierrymichel committed Oct 29, 2021
commit 17d3b6075eb57b554bc5c1beb63704c5d0d29879
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -75,6 +75,10 @@ This will print out a table of missing keys in your language files, as well as u
// Boolean
// Use if you want to remove unused keys from your language files.

--silent
// Boolean
// Use if you want to remove `console.table` logs

--ci
// Boolean
// The process will exit with exitCode=1 if at least one translation key is missing or unused (useful if it is part of a CI pipeline).
4 changes: 4 additions & 0 deletions bin/vue-i18n-extract.js
Original file line number Diff line number Diff line change
@@ -27,6 +27,10 @@ cli
'--remove',
'[boolean] Use if you want to remove unused keys from your json language files.',
)
.option(
'--silent',
'[boolean] Use if you want to remove `console.table` logs.',
)
.option(
'--ci',
'[boolean] The process will exit with exitCode=1 if at least one translation-key is missing (useful expecially if it is part of a CI pipeline).',
1 change: 1 addition & 0 deletions dist/config-file/vue-i18n-extract.config.d.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ declare const _default: {
output: boolean;
add: boolean;
remove: boolean;
silent: boolean;
ci: boolean;
separator: string;
};
1 change: 1 addition & 0 deletions dist/types.d.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ export declare type ReportOptions = {
output?: string;
add?: boolean;
remove?: boolean;
silent?: boolean;
ci?: boolean;
separator?: string;
};
18 changes: 12 additions & 6 deletions dist/vue-i18n-extract.modern.js

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

2 changes: 1 addition & 1 deletion dist/vue-i18n-extract.modern.js.map

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions dist/vue-i18n-extract.umd.js

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

2 changes: 1 addition & 1 deletion dist/vue-i18n-extract.umd.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/config-file/vue-i18n-extract.config.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ export default {
output: false,
add: false,
remove: false,
silent: false,
ci: false,
separator: '.'
};
9 changes: 6 additions & 3 deletions src/create-report/index.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ export async function createI18NReport (options: ReportOptions): Promise<I18NRep
output,
add,
remove,
silent,
ci,
separator
} = options;
@@ -28,9 +29,11 @@ export async function createI18NReport (options: ReportOptions): Promise<I18NRep

const report = extractI18NReport(I18NItems, I18NLanguage);

if (report.missingKeys.length) console.info('\nMissing Keys'), console.table(report.missingKeys);
if (report.unusedKeys.length) console.info('\nUnused Keys'), console.table(report.unusedKeys);
if (report.maybeDynamicKeys.length) console.warn('\nSuspected Dynamic Keys Found\nvue-i18n-extract does not compile Vue templates and therefore can not infer the correct key for the following keys.'), console.table(report.maybeDynamicKeys);
if (!silent) {
if (report.missingKeys.length) console.info('\nMissing Keys'), console.table(report.missingKeys);
if (report.unusedKeys.length) console.info('\nUnused Keys'), console.table(report.unusedKeys);
if (report.maybeDynamicKeys.length) console.warn('\nSuspected Dynamic Keys Found\nvue-i18n-extract does not compile Vue templates and therefore can not infer the correct key for the following keys.'), console.table(report.maybeDynamicKeys);
}

if (output) {
await writeReportToFile(report, path.resolve(process.cwd(), output));
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ export type ReportOptions = {
output?: string;
add?: boolean;
remove?: boolean;
silent?: boolean;
ci?: boolean;
separator?: string;
}
4 changes: 4 additions & 0 deletions tests/unit/create-report/index.spec.ts
Original file line number Diff line number Diff line change
@@ -34,6 +34,10 @@ describe('file: create-report/index', () => {
expect(consoleTableSpy).toHaveBeenCalledTimes(3);
expect(consoleTableSpy.mock.calls[0][0]).toEqual(expectedI18NReport.missingKeys);
expect(consoleTableSpy.mock.calls[1][0]).toEqual(expectedI18NReport.unusedKeys);

await createI18NReport({ ...options, silent: true });

expect(consoleTableSpy).toHaveBeenCalledTimes(3);
});

it('Write report to file at output path', async () => {