super-productivity/scripts/remove-unused-log-imports.ts
Johannes Millan 581d41cc0c refactor: complete migration from console.* to Log methods
- Replaced remaining 100 console.* calls across 100 files
- Fixed all console.log, console.error, console.warn calls
- Removed unused Log imports from 18 files
- Created force migration script to handle all edge cases
- All non-test files now use centralized Log class

Benefits:
- All application logs are now recorded for export
- Consistent log level filtering
- Better debugging with log history
- Centralized logging configuration
2025-07-10 14:25:02 +02:00

82 lines
3.2 KiB
TypeScript

#!/usr/bin/env ts-node
import * as fs from 'fs';
import * as path from 'path';
const filesToFix = [
'src/app/core-ui/drop-list/drop-list.service.ts',
'src/app/core-ui/side-nav/side-nav.component.ts',
'src/app/core/banner/banner.service.ts',
'src/app/features/config/form-cfgs/domina-mode-form.const.ts',
'src/app/features/focus-mode/focus-mode.service.ts',
'src/app/features/schedule/create-task-placeholder/create-task-placeholder.component.ts',
'src/app/features/schedule/map-schedule-data/create-blocked-blocks-by-day-map.ts',
'src/app/features/schedule/map-schedule-data/create-view-entries-for-day.ts',
'src/app/features/schedule/map-schedule-data/insert-blocked-blocks-view-entries-for-schedule.ts',
'src/app/features/schedule/map-schedule-data/map-to-schedule-days.ts',
'src/app/features/task-repeat-cfg/sort-repeatable-task-cfg.ts',
'src/app/features/tasks/dialog-task-detail-panel/dialog-task-detail-panel.component.ts',
'src/app/features/work-context/store/work-context-meta.helper.ts',
'src/app/root-store/index.ts',
'src/app/ui/duration/input-duration-formly/input-duration-formly.component.ts',
'src/app/ui/inline-markdown/inline-markdown.component.ts',
'src/app/util/is-touch-only.ts',
'src/app/util/watch-object.ts',
];
function removeUnusedLogImport(filePath: string): void {
try {
const fullPath = path.join(process.cwd(), filePath);
let content = fs.readFileSync(fullPath, 'utf8');
// Check if Log is actually used in the file (excluding import statement and comments)
const importRegex = /import\s+{[^}]*\bLog\b[^}]*}\s+from\s+['"][^'"]+['"]/g;
let contentWithoutImports = content.replace(importRegex, '');
// Remove single line comments
contentWithoutImports = contentWithoutImports.replace(/\/\/.*$/gm, '');
// Remove multi-line comments
contentWithoutImports = contentWithoutImports.replace(/\/\*[\s\S]*?\*\//g, '');
const isLogUsed = /\bLog\./g.test(contentWithoutImports);
if (!isLogUsed) {
// Remove Log from imports
content = content.replace(
/import\s+{([^}]*)\bLog\b([^}]*)}\s+from\s+(['"][^'"]+['"])/g,
(match, before, after, path) => {
// Clean up the remaining imports
const remainingImports = (before + after)
.split(',')
.map((s) => s.trim())
.filter((s) => s && s !== 'Log')
.join(', ');
if (remainingImports) {
return `import { ${remainingImports} } from ${path}`;
} else {
// If Log was the only import, remove the entire import line
return '';
}
},
);
// Clean up any empty lines left by removed imports
content = content.replace(/^\s*;\s*$/gm, ''); // Remove standalone semicolons
content = content.replace(/\n\n+/g, '\n\n'); // Replace multiple newlines with double newline
fs.writeFileSync(fullPath, content, 'utf8');
console.log(`Fixed: ${filePath}`);
} else {
console.log(`Skipped (Log is used): ${filePath}`);
}
} catch (error) {
console.error(`Error processing ${filePath}:`, error);
}
}
console.log('Removing unused Log imports...\n');
filesToFix.forEach(removeUnusedLogImport);
console.log('\nDone!');