diff --git a/scripts/fix-duplicate-imports.ts b/scripts/fix-duplicate-imports.ts new file mode 100755 index 000000000..9ed311038 --- /dev/null +++ b/scripts/fix-duplicate-imports.ts @@ -0,0 +1,92 @@ +#!/usr/bin/env ts-node + +import * as fs from 'fs'; +import * as path from 'path'; +import * as glob from 'glob'; + +// Pattern to find duplicate imports +const findDuplicateImports = (content: string): string[] => { + const importRegex = /^import\s+.*?;$/gm; + const imports = content.match(importRegex) || []; + const seen = new Set(); + const duplicates: string[] = []; + + for (const imp of imports) { + const normalized = imp.trim(); + if (seen.has(normalized)) { + duplicates.push(normalized); + } else { + seen.add(normalized); + } + } + + return duplicates; +}; + +// Remove duplicate imports from content +const removeDuplicateImports = (content: string): string => { + const lines = content.split('\n'); + const seenImports = new Set(); + const resultLines: string[] = []; + + for (const line of lines) { + const trimmedLine = line.trim(); + + // Check if it's an import statement + if (trimmedLine.startsWith('import ') && trimmedLine.endsWith(';')) { + if (seenImports.has(trimmedLine)) { + // Skip duplicate import + continue; + } + seenImports.add(trimmedLine); + } + + resultLines.push(line); + } + + return resultLines.join('\n'); +}; + +function processFile(filePath: string): boolean { + try { + const content = fs.readFileSync(filePath, 'utf8'); + const duplicates = findDuplicateImports(content); + + if (duplicates.length > 0) { + console.log( + `Found ${duplicates.length} duplicate imports in ${path.relative(process.cwd(), filePath)}:`, + ); + duplicates.forEach((dup) => console.log(` - ${dup}`)); + + const fixedContent = removeDuplicateImports(content); + fs.writeFileSync(filePath, fixedContent, 'utf8'); + return true; + } + + return false; + } catch (error) { + console.error(`Error processing ${filePath}:`, error); + return false; + } +} + +function main() { + console.log('Searching for duplicate imports...\n'); + + const files = glob.sync('src/**/*.ts', { + ignore: ['**/node_modules/**', '**/dist/**', '**/build/**'], + absolute: true, + }); + + let fixedCount = 0; + + for (const file of files) { + if (processFile(file)) { + fixedCount++; + } + } + + console.log(`\nFixed duplicate imports in ${fixedCount} files.`); +} + +main(); diff --git a/src/app/core/language/language.service.ts b/src/app/core/language/language.service.ts index 59a86b88c..d6d32e48f 100644 --- a/src/app/core/language/language.service.ts +++ b/src/app/core/language/language.service.ts @@ -12,7 +12,6 @@ import { GlobalConfigService } from 'src/app/features/config/global-config.servi import { map, startWith } from 'rxjs/operators'; import { DEFAULT_GLOBAL_CONFIG } from 'src/app/features/config/default-global-config.const'; import { Log } from '../log'; -import { Log } from '../log'; @Injectable({ providedIn: 'root' }) export class LanguageService { diff --git a/src/app/core/persistence/indexed-db-adapter.service.ts b/src/app/core/persistence/indexed-db-adapter.service.ts index 6a1467eac..94e740fb9 100644 --- a/src/app/core/persistence/indexed-db-adapter.service.ts +++ b/src/app/core/persistence/indexed-db-adapter.service.ts @@ -5,7 +5,6 @@ import { filter, shareReplay, take } from 'rxjs/operators'; import { DBSchema, openDB } from 'idb'; import { DBAdapter } from './db-adapter.model'; import { Log } from '../log'; -import { Log } from '../log'; const DB_NAME = 'SUP'; const DB_MAIN_NAME = 'SUP_STORE'; diff --git a/src/app/core/theme/global-theme.service.ts b/src/app/core/theme/global-theme.service.ts index 1958820cf..65901a8af 100644 --- a/src/app/core/theme/global-theme.service.ts +++ b/src/app/core/theme/global-theme.service.ts @@ -30,7 +30,6 @@ import { HttpClient } from '@angular/common/http'; import { LS } from '../persistence/storage-keys.const'; import { CustomThemeService } from './custom-theme.service'; import { Log } from '../log'; -import { Log } from '../log'; export type DarkModeCfg = 'dark' | 'light' | 'system';