Skip to content

Commit

Permalink
chore: used-icons fix regexp, add some exclusions (#5022)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirpotekhin authored Aug 1, 2023
1 parent 9a0578f commit f92cc75
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 10 deletions.
39 changes: 35 additions & 4 deletions projects/cdk/constants/used-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ export const TUI_USED_ICONS = [
`tuiIconElectronMono`,
`tuiIconCloseLarge`,
`tuiIconChevronDownLarge`,
`tuiIconButton`,
`tuiIconMir`,
`tuiIconVisa`,
`tuiIconElectron`,
`tuiIconMastercard`,
`tuiIconMaestro`,
`tuiIconAmex`,
`tuiIconDinersClub`,
`tuiIconDiscover`,
`tuiIconHumo`,
`tuiIconJCB`,
`tuiIconRuPay`,
`tuiIconUnionPay`,
`tuiIconUzcard`,
`tuiIconVerve`,
`tuiIconLink`,
`tuiIconMenuLarge`,
`tuiIconCode`,
Expand All @@ -36,14 +49,32 @@ export const TUI_USED_ICONS = [
`tuiIconCheckLarge`,
`tuiIconChevronLeft`,
`tuiIconX`,
`tuiIconCheck`,
`tuiIconMinusLarge`,
`tuiIconChevronRightLarge`,
`tuiIconChevronUp`,
`tuiIconHelpCircle`,
`tuiIconCheck`,
`tuiIconInfo`,
`tuiIconCheckCircle`,
`tuiIconXCircle`,
`tuiIconAlertCircle`,
`tuiIconChevronDown`,
`tuiIconFileLarge`,
`tuiIconTrashLarge`,
`tuiIconAlertCircleLarge`,
`tuiIconCheckCircleLarge`,
`tuiIconAlertCircle`,
`tuiIconCopy`,
`tuiIconCopyLarge`,
`tuiIconEyeOffLarge`,
`tuiIconEyeLarge`,
`tuiIconClock`,
`tuiIconClockLarge`,
`tuiIconStarLarge`,
`tuiIconWarningLarge`,
`tuiIconChevronDown`,
`tuiIconToggleOff`,
`tuiIconToggleOffLarge`,
`tuiIconToggleOn`,
`tuiIconToggleOnLarge`,
`tuiIconCalendar`,
`tuiIconCalendarLarge`,
];
40 changes: 34 additions & 6 deletions scripts/generate-used-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,25 @@ import {basename, join} from 'path';
`icons`,
`schematics`,
];
const excludedFiles = [`deprecated-icons.ts`, `used-icons.ts`];
const excludedNames = [`tuiIconButton`];

generateUsedIcons(rootDirectory, excludedFolders);
generateUsedIcons(rootDirectory, {excludedFolders, excludedNames, excludedFiles});
})();

function generateUsedIcons(rootDirectory: string, excludedFolders: string[]): void {
const tuiIconNames = findTuiIconNames(rootDirectory, excludedFolders);
function generateUsedIcons(
rootDirectory: string,
{
excludedFolders,
excludedNames,
excludedFiles,
}: {excludedFolders: string[]; excludedNames: string[]; excludedFiles: string[]},
): void {
const tuiIconNames = findTuiIconNames(rootDirectory, {
excludedFolders,
excludedNames,
excludedFiles,
});

writeFileSync(
`./projects/cdk/constants/used-icons.ts`,
Expand All @@ -33,7 +46,14 @@ function generateUsedIcons(rootDirectory: string, excludedFolders: string[]): vo
);
}

function findTuiIconNames(rootDir: string, excludedFolders: string[]): string[] {
function findTuiIconNames(
rootDir: string,
{
excludedFolders,
excludedNames,
excludedFiles,
}: {excludedFolders: string[]; excludedNames: string[]; excludedFiles: string[]},
): string[] {
const tuiIconNames = new Set<string>();

function traverseDirectory(directory: string): void {
Expand All @@ -50,12 +70,20 @@ function findTuiIconNames(rootDir: string, excludedFolders: string[]): string[]
traverseDirectory(filePath);
}
} else if (stat.isFile()) {
const fileName = basename(filePath);

if (excludedFiles.includes(fileName)) {
return;
}

const fileContents = readFileSync(filePath, `utf-8`);
const tuiIconMatches = fileContents.match(/\btuiIcon\w+(?=\s|'|")/g);
const tuiIconMatches = fileContents.match(/\btuiIcon\w+(?=\s|'|"|`)/g);

if (tuiIconMatches) {
tuiIconMatches.forEach(match => {
tuiIconNames.add(match);
if (!excludedNames.includes(match)) {
tuiIconNames.add(match);
}
});
}
}
Expand Down

0 comments on commit f92cc75

Please sign in to comment.