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

fix: not reading exclude option from config file #167

Merged
merged 2 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion dist/config-file/vue-i18n-extract.config.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
declare const _default: {
vueFiles: string;
languageFiles: string;
excludedKeys: never[];
exclude: never[];
output: boolean;
add: boolean;
remove: boolean;
Expand Down
15 changes: 9 additions & 6 deletions src/config-file/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@ export function initCommand(): void {

export function resolveConfig (): Record<string, string> {
const argvOptions = cac().parse(process.argv, { run: false }).options;
const excluded = argvOptions.exclude;

argvOptions.exclude = !Array.isArray(excluded) ? [excluded] : excluded
let options;

try {
const pathToConfigFile = path.resolve(process.cwd(), './vue-i18n-extract.config.js');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const configFile = require(pathToConfigFile);
const configOptions = require(pathToConfigFile);

console.info(`\nUsing config file found at ${pathToConfigFile}`);

return {
...configFile,
options = {
...configOptions,
...argvOptions
};
} catch {
return argvOptions;
options = argvOptions;
}

options.exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude];

return options;
}
2 changes: 1 addition & 1 deletion src/config-file/vue-i18n-extract.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default {
// Options documented in vue-i18n-extract readme.
vueFiles: './src/**/*.?(js|vue)',
languageFiles: './lang/**/*.?(json|yaml|yml|js)',
excludedKeys: [],
exclude: [],
output: false,
add: false,
remove: false,
Expand Down
27 changes: 25 additions & 2 deletions tests/unit/config-file/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
import { initCommand, resolveConfig } from '@/config-file';
import { initCommand, resolveConfig } from '@/config-file';
import defaultConfig from '@/config-file/vue-i18n-extract.config';
import rimraf from 'rimraf';

describe('file: config-file/index', () => {
it('Init and Read the config file.', (done) => {
it('Init default config and read it.', (done) => {
initCommand();

const config = resolveConfig();

expect(config).toEqual(expect.objectContaining({
exclude: defaultConfig.exclude,
vueFiles: defaultConfig.vueFiles,
languageFiles: defaultConfig.languageFiles,
}));

rimraf('./vue-i18n-extract.config.js', () => {
done();
});
});

it('Read non-default config.', (done) => {
jest.doMock('@/config-file/vue-i18n-extract.config', () => ({
vueFiles: './src/**/*.?(js|vue)',
languageFiles: './lang/**/*.?(json|yaml|yml|js)',
exclude: ['test', 'hello']
}));

initCommand();

const config = resolveConfig();

expect(config).toEqual(expect.objectContaining({
exclude: defaultConfig.exclude,
vueFiles: defaultConfig.vueFiles,
languageFiles: defaultConfig.languageFiles,
}));
Expand Down