import selectorsLibrary from '../selectorsLibrary' ; import cssVariablesLibrary from '../cssVariablesLibrary' ; import keyframesLibrary from '../keyframesLibrary' ; interface Stat { appearanceCount : number ; } export interface UsageCount { [ s ] : number ; } export interface Statistic { unused : string [ ] ; usageCount : UsageCount ; } const generate = ( ) => { const classSelector = selectorsLibrary . getClassSelector ( ) ; const idSelector = selectorsLibrary . getIdSelector ( ) ; const cssVariables = Object . entries ( cssVariablesLibrary . meta ) ; const keyframes = Object . entries ( keyframesLibrary . meta ) ; const getUnused = ( obj ) : string [ ] => ( obj . filter ( ( entry ) => entry [ 1 ] . appearanceCount === 0 ) . map ( ( [ name ] ) => name ) ) ; const unusedCssVariables = getUnused ( cssVariables ) ; const unusedKeyframes = getUnused ( keyframes ) ; const unusedClasses = getUnused ( Object . entries ( classSelector . meta ) ) ; const unusedIds = getUnused ( Object . entries ( idSelector . meta ) ) ; const classUsageCount = { } ; const idUsageCount = { } ; const cssVariablesUsageCount = { } ; const keyframesUsageCount = { } ; Object . keys ( classSelector . values ) . forEach ( ( v ) => { classUsageCount [ v ] = classSelector . meta [ v ] . appearanceCount ; } ) ; Object . keys ( idSelector . values ) . forEach ( ( v ) => { idUsageCount [ v ] = idSelector . meta [ v ] . appearanceCount ; } ) ; cssVariables . forEach ( ( [ name , meta ] ) => { cssVariablesUsageCount [ name ] = meta . appearanceCount ; } ) ; keyframes . forEach ( ( [ name , meta ] ) => { keyframesUsageCount [ name ] = meta . appearanceCount ; } ) ; return { ids : { unused : unusedIds , usageCount : idUsageCount , } , classes : { unused : unusedClasses , usageCount : classUsageCount , } , cssVariables : { unused : unusedCssVariables , usageCount : cssVariablesUsageCount , } , keyframes : { unused : unusedKeyframes , usageCount : keyframesUsageCount , } , } ; } ; export default generate ;