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: build only langs listed in .yfm config #618

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface YfmArgv extends YfmConfig {
addMapFile: boolean;
allowCustomResources: boolean;
staticContent: boolean;
langs: string[];
}

export interface DocPreset {
Expand Down
3 changes: 2 additions & 1 deletion src/steps/processServiceFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import log from '@diplodoc/transform/lib/log';

import {ArgvService, PresetService, TocService} from '../services';
import {logger} from '../utils';
import {filterByLang} from '../utils/filterByLang';
import {DocPreset} from '../models';
import shell from 'shelljs';

Expand Down Expand Up @@ -83,7 +84,7 @@ async function preparingTocFiles(
getFilePathsByGlobals: GetFilePathsByGlobalsFunction,
): Promise<void> {
try {
const tocFilePaths = getFilePathsByGlobals(['**/toc.yaml']);
const tocFilePaths = filterByLang(getFilePathsByGlobals(['**/toc.yaml']));

for (const path of tocFilePaths) {
logger.proc(path);
Expand Down
13 changes: 13 additions & 0 deletions src/utils/filterByLang.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {ArgvService} from '../services';

const filterByLang = (tocFilePaths: string[]): string[] => {
const {langs} = ArgvService.getConfig();
if (langs && langs.length) {
return tocFilePaths.filter((path) => langs.includes(path.split('/')[0]));
}
return tocFilePaths;
};

export {filterByLang};

export default {filterByLang};
46 changes: 46 additions & 0 deletions tests/units/utils/filterByLang.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {filterByLang} from 'utils/filterByLang';
import {ArgvService} from 'services/index';
import {YfmArgv} from 'models';

describe('test filtering paths of toc files by lang', () => {
afterEach(() => {
ArgvService.set(undefined as YfmArgv);
})

it('should remove toc from not included lang', () => {
ArgvService.set({
langs: ['ru']
} as YfmArgv);

const tocFilePaths = [
'ru/toc.yaml',
'en/toc.yaml'
];
const expected = [
'ru/toc.yaml',
];
expect(filterByLang(tocFilePaths)).toEqual(expected);
});

it('should remove tocs from not included lang and work with nested paths', () => {
ArgvService.set({
langs: ['ru', 'fr']
} as YfmArgv);

const tocFilePaths = [
'ru/toc.yaml',
'ru/xxx/yyy/toc.yaml',
'en/toc.yaml',
'en/aaa/bbb/toc.yaml',
'fr/toc.yaml',
'fr/111/222/toc.yaml'
];
const expected = [
'ru/toc.yaml',
'ru/xxx/yyy/toc.yaml',
'fr/toc.yaml',
'fr/111/222/toc.yaml'
];
expect(filterByLang(tocFilePaths)).toEqual(expected);
});
});