mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-28 17:57:48 +02:00
fix(cli): fix CLI write-translation bug (#11027)
* fix write-translation bug * fix write-translation bug
This commit is contained in:
parent
8881fd1a59
commit
37d8844506
2 changed files with 32 additions and 8 deletions
|
@ -9,8 +9,22 @@ import {
|
|||
GlobExcludeDefault,
|
||||
createMatcher,
|
||||
createAbsoluteFilePathMatcher,
|
||||
isTranslatableSourceFile,
|
||||
} from '../globUtils';
|
||||
|
||||
describe('isTranslatableSourceFile', () => {
|
||||
it('works', () => {
|
||||
expect(isTranslatableSourceFile('./xyz.ts')).toBe(true);
|
||||
expect(isTranslatableSourceFile('./xyz.tsx')).toBe(true);
|
||||
expect(isTranslatableSourceFile('./xyz.js')).toBe(true);
|
||||
expect(isTranslatableSourceFile('./xyz.jsx')).toBe(true);
|
||||
|
||||
expect(isTranslatableSourceFile('./xyz.md')).toBe(false);
|
||||
expect(isTranslatableSourceFile('./xyz.mdx')).toBe(false);
|
||||
expect(isTranslatableSourceFile('./xyz.d.ts')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createMatcher', () => {
|
||||
it('match default exclude MD/MDX partials correctly', () => {
|
||||
const matcher = createMatcher(GlobExcludeDefault);
|
||||
|
|
|
@ -104,11 +104,8 @@ export async function safeGlobby(
|
|||
return Globby(globPaths, options);
|
||||
}
|
||||
|
||||
// A bit weird to put this here, but it's used by core + theme-translations
|
||||
export async function globTranslatableSourceFiles(
|
||||
patterns: string[],
|
||||
): Promise<string[]> {
|
||||
// We only support extracting source code translations from these kind of files
|
||||
export const isTranslatableSourceFile: (filePath: string) => boolean = (() => {
|
||||
// We only support extracting source code translations from these extensions
|
||||
const extensionsAllowed = new Set([
|
||||
'.js',
|
||||
'.jsx',
|
||||
|
@ -120,8 +117,21 @@ export async function globTranslatableSourceFiles(
|
|||
// '.mdx',
|
||||
]);
|
||||
|
||||
const isBlacklistedFilePath = (filePath: string) => {
|
||||
// We usually extract from ts files, unless they are .d.ts files
|
||||
return filePath.endsWith('.d.ts');
|
||||
};
|
||||
|
||||
return (filePath): boolean => {
|
||||
const ext = path.extname(filePath);
|
||||
return extensionsAllowed.has(ext) && !isBlacklistedFilePath(filePath);
|
||||
};
|
||||
})();
|
||||
|
||||
// A bit weird to put this here, but it's used by core + theme-translations
|
||||
export async function globTranslatableSourceFiles(
|
||||
patterns: string[],
|
||||
): Promise<string[]> {
|
||||
const filePaths = await safeGlobby(patterns);
|
||||
return filePaths.filter((filePath) =>
|
||||
extensionsAllowed.has(path.extname(filePath)),
|
||||
);
|
||||
return filePaths.filter(isTranslatableSourceFile);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue