Last active
May 9, 2025 15:42
-
-
Save spacesuitdiver/7955cd351de53faf6feb2a6fdccb0856 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require("path"); | |
const { Project } = require("ts-morph"); | |
const cliProgress = require("cli-progress"); | |
// Initialize the TypeScript project | |
const project = new Project({ | |
tsConfigFilePath: "tsconfig.json", | |
skipAddingFilesFromTsConfig: true, | |
compilerOptions: { | |
allowJs: true, | |
checkJs: false | |
}, | |
skipFileDependencyResolution: true, | |
skipLoadingLibFiles: true | |
}); | |
// Load source files | |
project.addSourceFilesAtPaths([ | |
"js/**/*.{js,ts}", | |
"!**/node_modules/**", | |
"!**/*.test.*", | |
"!**/*.spec.*", | |
]); | |
const files = project.getSourceFiles(); | |
console.log(`Scanning ${files.length} files for Footer imports...\n`); | |
// Initialize progress bar | |
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic); | |
bar.start(files.length, 0); | |
const summary = new Map(); | |
for (const [i, file] of files.entries()) { | |
const importDecls = file.getImportDeclarations(); | |
for (const imp of importDecls) { | |
const specifier = imp.getModuleSpecifierValue(); | |
const namedImports = imp.getNamedImports(); | |
const defaultImport = imp.getDefaultImport(); | |
const footerNamed = namedImports.some(n => n.getName() === "Footer"); | |
const footerDefault = defaultImport?.getText() === "Footer"; | |
if (footerNamed || footerDefault) { | |
console.log(`${file.getFilePath()} imports Footer from '${specifier}'`); | |
summary.set(specifier, (summary.get(specifier) || 0) + 1); | |
} | |
} | |
bar.update(i + 1); | |
} | |
bar.stop(); | |
console.log("\n=== Summary of Footer imports by module ==="); | |
for (const [modulePath, count] of [...summary.entries()].sort((a, b) => b[1] - a[1])) { | |
console.log(`${count} × '${modulePath}'`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment