We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There should be more information added to the CLI, and the pages.json, about which selectors are ultimately used/unused.
I wrote a separate js file for determining this, but it would be nice if this were a core feature.
This is what I wrote that generally works.
const fs = require('fs'); if (process.argv.length <= 2) { console.error('needed name of file'); process.exit(1); } const fileName = process.argv[2]; const outputFileName = fileName.replace('.pages.json', ''); function getResultsData(fileName) { if (!fileName) return null; try { const file = fs.readFileSync(fileName, 'utf8'); const fileData = JSON.parse(file); return fileData; } catch (fileError) { console.error(fileError); } } function filterUsedAndUnused(pagesWithSelector) { if (!pagesWithSelector) throw new Error('not an object'); const unusedSet = new Set(); const usedSet = new Set(); pagesWithSelector.forEach(page => { const { unusedSelectors, usedSelectors} = page; unusedSelectors.forEach(unusedSelector => unusedSet.add(unusedSelector)); usedSelectors.forEach(usedSelector => usedSet.add(usedSelector)); }); unusedSet.forEach((selector) => { if (usedSet.has(selector)) { unusedSet.delete(selector); } }); return {unusedSet, usedSet}; } function outputFile(data) { const json = JSON.stringify(data, null, 2); try { fs.writeFile(`${outputFileName}.filtered.json`, json, writeError => { if (writeError) { console.error(writeError) } }) } catch (outputErr) { console.error(outputErr); } } try { const searchResults = getResultsData(fileName); const { pagesWithSelector } = searchResults; const {unusedSet, usedSet} = filterUsedAndUnused(pagesWithSelector); const convertedUsed = [...usedSet]; const convertedUnused = [...unusedSet]; const totalUsedSize = convertedUsed.length; const totalUnusedSize = convertedUnused.length; const results = { totalUsed : totalUsedSize, totalUnused : totalUnusedSize, totalSelectors : totalUsedSize + totalUnusedSize, used: convertedUsed, unused: convertedUnused }; outputFile(results); console.log(`\n=====UNUSED: ${totalUnusedSize}=====`); console.log(unusedSet); console.log(`\n=====USED: ${totalUsedSize}=====`); console.log(usedSet); } catch (readErr) { console.error(readError); }
The text was updated successfully, but these errors were encountered:
Note: this could be a "report" flag, in case we wanted to add other summarizing / learning that comes after the pages.json is generated.
Reporting could include:
Sorry, something went wrong.
No branches or pull requests
There should be more information added to the CLI, and the pages.json, about which selectors are ultimately used/unused.
I wrote a separate js file for determining this, but it would be nice if this were a core feature.
This is what I wrote that generally works.
The text was updated successfully, but these errors were encountered: