From ab82507fd2d31cc73219314556bbc8f48b2ca677 Mon Sep 17 00:00:00 2001 From: tecvan <84165678+Tecvan-fe@users.noreply.github.com> Date: Wed, 30 Jul 2025 17:50:44 +0800 Subject: [PATCH] chore: support idl files of cn2en script (#336) --- .../rush-commands/src/convert-comments/cli/config.ts | 2 +- .../src/convert-comments/modules/file-scan.ts | 4 +--- .../src/convert-comments/types/index.ts | 1 + .../src/convert-comments/utils/language.ts | 12 +++++++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/common/autoinstallers/rush-commands/src/convert-comments/cli/config.ts b/common/autoinstallers/rush-commands/src/convert-comments/cli/config.ts index 654ec1c7..7341b7a0 100644 --- a/common/autoinstallers/rush-commands/src/convert-comments/cli/config.ts +++ b/common/autoinstallers/rush-commands/src/convert-comments/cli/config.ts @@ -21,7 +21,7 @@ const DEFAULT_CONFIG: AppConfig = { 'yaml', 'yml', 'toml', 'ini', 'conf', 'config', 'sh', 'bash', 'zsh', 'fish', 'py', 'css', 'scss', 'sass', 'less', 'html', 'htm', 'xml', 'php', 'rb', 'rs', 'java', 'c', 'h', - 'cpp', 'cxx', 'cc', 'hpp', 'cs' + 'cpp', 'cxx', 'cc', 'hpp', 'cs', 'thrift' ], outputFormat: 'console' }, diff --git a/common/autoinstallers/rush-commands/src/convert-comments/modules/file-scan.ts b/common/autoinstallers/rush-commands/src/convert-comments/modules/file-scan.ts index 46c83742..d0d5091f 100644 --- a/common/autoinstallers/rush-commands/src/convert-comments/modules/file-scan.ts +++ b/common/autoinstallers/rush-commands/src/convert-comments/modules/file-scan.ts @@ -57,9 +57,7 @@ export const getSourceFiles = async (config: FileScanConfig): Promise 0) { - files = filterFilesByExtensions(files, extensions); - } + files = filterFilesByExtensions(files, extensions); return files; }); diff --git a/common/autoinstallers/rush-commands/src/convert-comments/types/index.ts b/common/autoinstallers/rush-commands/src/convert-comments/types/index.ts index df7db492..e717be51 100644 --- a/common/autoinstallers/rush-commands/src/convert-comments/types/index.ts +++ b/common/autoinstallers/rush-commands/src/convert-comments/types/index.ts @@ -23,6 +23,7 @@ export type SourceFileLanguage = | 'c' | 'cpp' | 'csharp' + | 'thrift' | 'other'; /** diff --git a/common/autoinstallers/rush-commands/src/convert-comments/utils/language.ts b/common/autoinstallers/rush-commands/src/convert-comments/utils/language.ts index 9236cb64..baf7987f 100644 --- a/common/autoinstallers/rush-commands/src/convert-comments/utils/language.ts +++ b/common/autoinstallers/rush-commands/src/convert-comments/utils/language.ts @@ -43,7 +43,8 @@ export const detectLanguage = (filePath: string): SourceFileLanguage => { 'cxx': 'cpp', 'cc': 'cpp', 'hpp': 'cpp', - 'cs': 'csharp' + 'cs': 'csharp', + 'thrift': 'thrift' }; return languageMap[ext || ''] || 'other'; @@ -63,7 +64,7 @@ export const filterFilesByExtensions = ( '.yaml', '.yml', '.toml', '.ini', '.conf', '.config', '.sh', '.bash', '.zsh', '.fish', '.py', '.css', '.scss', '.sass', '.less', '.html', '.htm', '.xml', '.php', '.rb', '.rs', '.java', '.c', '.h', - '.cpp', '.cxx', '.cc', '.hpp', '.cs' + '.cpp', '.cxx', '.cc', '.hpp', '.cs', '.thrift' ]; return files.filter(file => defaultExtensions.some(ext => file.toLowerCase().endsWith(ext)) @@ -191,6 +192,11 @@ export const getCommentPatterns = (language: SourceFileLanguage): CommentPattern multiStart: /\/\*/g, multiEnd: /\*\//g }, + thrift: { + single: /\/\/(.*)$/gm, + multiStart: /\/\*/g, + multiEnd: /\*\//g + }, other: { single: /\/\/(.*)$/gm, multiStart: /\/\*/g, @@ -218,7 +224,7 @@ export const isTextFile = (filePath: string): boolean => { '.css', '.scss', '.sass', '.less', '.html', '.htm', '.xml', '.yaml', '.yml', '.toml', '.ini', '.conf', '.config', '.sh', '.bash', '.zsh', '.fish', '.py', '.java', '.c', '.cpp', '.h', '.hpp', '.cs', - '.php', '.rb', '.rs', '.kt', '.swift', '.dart', '.scala' + '.php', '.rb', '.rs', '.kt', '.swift', '.dart', '.scala', '.thrift' ]; return textExtensions.some(ext =>