-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The new script file is `check-items` which checks `items.json` for duplicates and unused icon entries. Add feature to check for unused icon entries. Return error code on warnings.
- Loading branch information
1 parent
c8380db
commit 27fd3a7
Showing
3 changed files
with
88 additions
and
40 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const items = require('./src/items.json'); | ||
|
||
const skipUnusedIcons = ['file', 'folder']; | ||
|
||
function main() { | ||
const warnings = getWarnings(); | ||
|
||
if (warnings.length > 0) { | ||
for (const warning of warnings) { | ||
console.log(warning); | ||
} | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
function getWarnings() { | ||
const duplicates = getDuplicates(); | ||
const unusedIcons = getUnusedIcons(); | ||
|
||
const warnings = []; | ||
|
||
for (const [ext, type] of duplicates) { | ||
warnings.push(`Duplicate "${ext}" in "${type}" section`); | ||
} | ||
|
||
for (const iconName of unusedIcons) { | ||
warnings.push(`Unused icon: ${iconName}`); | ||
} | ||
|
||
return warnings; | ||
} | ||
|
||
function getUnusedIcons() { | ||
const { iconDefinitions, fileExtensions, fileNames } = items; | ||
const unusedIcons = []; | ||
|
||
const usedIcons = [ | ||
...Object.keys(fileNames), | ||
...Object.keys(fileExtensions), | ||
]; | ||
|
||
for (const iconName in iconDefinitions) { | ||
if (skipUnusedIcons.includes(iconName)) { | ||
continue; | ||
} | ||
|
||
if (!usedIcons.includes(iconName)) { | ||
unusedIcons.push(iconName); | ||
} | ||
} | ||
|
||
return unusedIcons; | ||
} | ||
|
||
function getDuplicates() { | ||
const { fileExtensions, fileNames } = items; | ||
|
||
const duplicates = [ | ||
...getDuplicatesInProps(fileNames), | ||
...getDuplicatesInProps(fileExtensions), | ||
]; | ||
|
||
return duplicates; | ||
} | ||
|
||
function getDuplicatesInProps(props) { | ||
const checkedItems = []; | ||
const duplicates = []; | ||
|
||
for (const type in props) { | ||
const extensions = props[type]; | ||
|
||
for (const ext of extensions) { | ||
if (checkedItems.includes(ext)) { | ||
duplicates.push([ext, type]); | ||
} else { | ||
checkedItems.push(ext); | ||
} | ||
} | ||
} | ||
|
||
return duplicates; | ||
} | ||
|
||
process.exit(main()); |
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