Skip to content

Instantly share code, notes, and snippets.

@FermiDirak
Last active March 10, 2020 10:34
Show Gist options
  • Save FermiDirak/61c1623285df842e92e2f19c9aed14a8 to your computer and use it in GitHub Desktop.
Save FermiDirak/61c1623285df842e92e2f19c9aed14a8 to your computer and use it in GitHub Desktop.
import iconNames from "latitude/iconNamesEnum";
import {getSourceFilesIterator} from "react-codestats";
const sourceFileIterator = getSourceFilesIterator("~/flexport/javascripts", {
extensions: ["js", "jsx"],
withParser: "flow",
});
const iconUsageCounts = iconNames.reduce((acc, iconName) => {
acc.set(iconName, 0);
return acc;
});
sourceFileIterator(({fileName, path, ast}, i) => {
ast
.findComponent({
defaultExport: true,
sourcePath: "latitude/TextInput",
})
.withProp({ name: "iconName" });
.forEach(component => {
const iconNames = component.props().iconName.extractLiterals();
iconNames.forEach(iconName => {
const currCount = iconUsageCounts.get(iconName);
iconUsageCounts.set(iconName, currCount + 1);
});
});
console.log(`${i} file(s) parsed.`);
});
console.log("finished!", iconUsageCounts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment