Last active
March 10, 2020 10:34
-
-
Save FermiDirak/61c1623285df842e92e2f19c9aed14a8 to your computer and use it in GitHub Desktop.
This file contains 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
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