55 */
66import * as dotenv from 'dotenv' ;
77import fs from 'fs' ;
8+ // eslint-disable-next-line you-dont-need-lodash-underscore/get
9+ import get from 'lodash/get' ;
810import path from 'path' ;
911import type { TemplateExpression } from 'typescript' ;
1012import ts from 'typescript' ;
@@ -14,6 +16,7 @@ import dedent from '@libs/StringUtils/dedent';
1416import hashStr from '@libs/StringUtils/hash' ;
1517import { isTranslationTargetLocale , LOCALES , TRANSLATION_TARGET_LOCALES } from '@src/CONST/LOCALES' ;
1618import type { Locale , TranslationTargetLocale } from '@src/CONST/LOCALES' ;
19+ import en from '@src/languages/en' ;
1720import type { TranslationPaths } from '@src/languages/types' ;
1821import CLI from './utils/CLI' ;
1922import Prettier from './utils/Prettier' ;
@@ -584,6 +587,9 @@ class TranslationGenerator {
584587 * The main function mostly contains CLI and file I/O logic, while TS parsing and translation logic is encapsulated in TranslationGenerator.
585588 */
586589async function main ( ) : Promise < void > {
590+ const languagesDir = process . env . LANGUAGES_DIR ?? path . join ( __dirname , '../src/languages' ) ;
591+ const enSourceFile = path . join ( languagesDir , 'en.ts' ) ;
592+
587593 /* eslint-disable @typescript-eslint/naming-convention */
588594 const cli = new CLI ( {
589595 flags : {
@@ -621,8 +627,25 @@ async function main(): Promise<void> {
621627 parse : ( val : string ) : TranslationPaths [ ] => {
622628 const rawPaths = val . split ( ',' ) . map ( ( translationPath ) => translationPath . trim ( ) ) ;
623629 const validatedPaths : TranslationPaths [ ] = [ ] ;
630+ const invalidPaths : string [ ] = [ ] ;
631+
632+ // We disable eslint here and do a dynamic require because tests mock the en.ts file using fs, and normal imports can't be mocked by jest
633+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
634+ // const en = require(enSourceFile).default;
635+
636+ for ( const rawPath of rawPaths ) {
637+ if ( get ( en , rawPath ) ) {
638+ validatedPaths . push ( rawPath as TranslationPaths ) ;
639+ } else {
640+ invalidPaths . push ( rawPath ) ;
641+ }
642+ }
643+
644+ if ( invalidPaths . length > 0 ) {
645+ throw new Error ( `⚠️ Warning: --paths contains the following invalid paths: ${ invalidPaths . join ( ', ' ) } ` ) ;
646+ }
624647
625- // TODO: validate paths
648+ return validatedPaths ;
626649 } ,
627650 supersedes : [ 'compare-ref' ] ,
628651 required : false ,
@@ -647,9 +670,6 @@ async function main(): Promise<void> {
647670 translator = new ChatGPTTranslator ( process . env . OPENAI_API_KEY ) ;
648671 }
649672
650- const languagesDir = process . env . LANGUAGES_DIR ?? path . join ( __dirname , '../src/languages' ) ;
651- const enSourceFile = path . join ( languagesDir , 'en.ts' ) ;
652-
653673 const generator = new TranslationGenerator ( {
654674 targetLanguages : cli . namedArgs . locales ,
655675 languagesDir,
0 commit comments