diff --git a/.github/workflows/auto-update-icons.yml b/.github/workflows/auto-update-icons.yml index 5d5920032c24..437f13a68e5c 100644 --- a/.github/workflows/auto-update-icons.yml +++ b/.github/workflows/auto-update-icons.yml @@ -1,4 +1,4 @@ -name: 🤖 Auto update bundled icons +name: 🤖 Auto update bundled & used icons on: pull_request: workflow_dispatch: @@ -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: diff --git a/projects/cdk/constants/index.ts b/projects/cdk/constants/index.ts index a3c23699d15e..e5f7d5d69d38 100644 --- a/projects/cdk/constants/index.ts +++ b/projects/cdk/constants/index.ts @@ -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'; diff --git a/projects/cdk/constants/used-icons.ts b/projects/cdk/constants/used-icons.ts new file mode 100644 index 000000000000..5fc926be751c --- /dev/null +++ b/projects/cdk/constants/used-icons.ts @@ -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`, +]; diff --git a/scripts/generate-used-icons.ts b/scripts/generate-used-icons.ts new file mode 100644 index 000000000000..f347a2cab96f --- /dev/null +++ b/scripts/generate-used-icons.ts @@ -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(); + + 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); +}