Skip to content

Commit

Permalink
Merge pull request #167 from kleinfreund/164-fix-exclude-option-not-w…
Browse files Browse the repository at this point in the history
…orking-in-config-file

fix: not reading exclude option from config file
  • Loading branch information
Spittal authored May 26, 2022
2 parents a12162d + 68138ad commit e743a59
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
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

0 comments on commit e743a59

Please sign in to comment.