Skip to content

Commit

Permalink
feat(cdk): add array of icons, used in taiga components (#5005)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirpotekhin authored Jul 31, 2023
1 parent 42b5676 commit c989f60
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 2 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/auto-update-icons.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 🤖 Auto update bundled icons
name: 🤖 Auto update bundled & used icons
on:
pull_request:
workflow_dispatch:
Expand All @@ -24,7 +24,11 @@ jobs:
npx nx prebuild icons
npx nx build icons
- name: Auto update bundled icons
npx ts-node ./scripts/generate-used-icons.ts
npx eslint ./projects/cdk/constants/used-icons.ts --fix
npx prettier ./projects/cdk/constants/used-icons.ts --write
- name: Auto update bundled & used icons
if: env.SUPPORT_AUTO_PUSH == 'true'
uses: ./.github/actions/auto-push
with:
Expand Down
1 change: 1 addition & 0 deletions projects/cdk/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export * from './polling-time';
export * from './stringify';
export * from './svg-node-filter';
export * from './unicode-chars';
export * from './used-icons';
export * from './version';
49 changes: 49 additions & 0 deletions projects/cdk/constants/used-icons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @description:
* AUTOGENERATED
*
* Array of icons used in taiga-ui components
*/
export const TUI_USED_ICONS = [
`tuiIconMirMono`,
`tuiIconVisaMono`,
`tuiIconElectronMono`,
`tuiIconCloseLarge`,
`tuiIconChevronDownLarge`,
`tuiIconButton`,
`tuiIconLink`,
`tuiIconMenuLarge`,
`tuiIconCode`,
`tuiIconSun`,
`tuiIconMoon`,
`tuiIconSearch`,
`tuiIconChevronRight`,
`tuiIconChevronLeftLarge`,
`tuiIconXLarge`,
`tuiIconClose`,
`tuiIconArrowLeft`,
`tuiIconArrowRight`,
`tuiIconRotate`,
`tuiIconMinus`,
`tuiIconPlus`,
`tuiIconMinimize`,
`tuiIconEye`,
`tuiIconEyeOff`,
`tuiIconDrag`,
`tuiIconSortDescending`,
`tuiIconSortAscending`,
`tuiIconSortOff`,
`tuiIconCheckLarge`,
`tuiIconChevronLeft`,
`tuiIconX`,
`tuiIconChevronRightLarge`,
`tuiIconHelpCircle`,
`tuiIconCheck`,
`tuiIconFileLarge`,
`tuiIconTrashLarge`,
`tuiIconAlertCircleLarge`,
`tuiIconCheckCircleLarge`,
`tuiIconAlertCircle`,
`tuiIconWarningLarge`,
`tuiIconChevronDown`,
];
68 changes: 68 additions & 0 deletions scripts/generate-used-icons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {readdirSync, readFileSync, statSync, writeFileSync} from 'fs';
import {basename, join} from 'path';

(function main(): void {
const rootDirectory = process.env.ROOT_FOLDER || `./projects`;
const excludedFolders = [
`demo`,
`demo-integrations`,
`eslint-plugin`,
`taiga-schematics`,
`testing`,
`test`,
`i18n`,
`icons`,
`schematics`,
];

generateUsedIcons(rootDirectory, excludedFolders);
})();

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

writeFileSync(
`./projects/cdk/constants/used-icons.ts`,
`/**
* @description:
* AUTOGENERATED
*
* Array of icons used in taiga-ui components
*/
export const TUI_USED_ICONS = ${JSON.stringify(tuiIconNames)}`,
);
}

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

function traverseDirectory(directory: string): void {
const files = readdirSync(directory);

for (const file of files) {
const filePath = join(directory, file);
const stat = statSync(filePath);

if (stat.isDirectory()) {
const folderName = basename(filePath);

if (!excludedFolders.includes(folderName)) {
traverseDirectory(filePath);
}
} else if (stat.isFile()) {
const fileContents = readFileSync(filePath, `utf-8`);
const tuiIconMatches = fileContents.match(/\btuiIcon\w+(?=\s|'|")/g);

if (tuiIconMatches) {
tuiIconMatches.forEach(match => {
tuiIconNames.add(match);
});
}
}
}
}

traverseDirectory(rootDir);

return Array.from(tuiIconNames);
}

0 comments on commit c989f60

Please sign in to comment.