From e8b02109d3d32aaa88abe7f4be37832d49e5cac9 Mon Sep 17 00:00:00 2001 From: Vladimir Potekhin <46284632+vladimirpotekhin@users.noreply.github.com> Date: Thu, 25 Jul 2024 17:02:18 +0300 Subject: [PATCH] chore: fix icons migration (#8213) --- .../ng-update/v4/migrate-icons/rename-icons.ts | 10 +++++----- .../v4/tests/schematic-migrate-icons.spec.ts | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/projects/cdk/schematics/ng-update/v4/migrate-icons/rename-icons.ts b/projects/cdk/schematics/ng-update/v4/migrate-icons/rename-icons.ts index cffa764fbba7..2b5e87742463 100644 --- a/projects/cdk/schematics/ng-update/v4/migrate-icons/rename-icons.ts +++ b/projects/cdk/schematics/ng-update/v4/migrate-icons/rename-icons.ts @@ -33,13 +33,13 @@ export function renameIcons(pattern = ALL_FILES): void { let text = file.getFullText(); CHANGED_ICONS.map(({from, to}) => ({ - from: new RegExp(`\\b${from}\\b`, 'g'), + from: new RegExp(`["'\`]${from}["'\`]`, 'g'), to, })).forEach(({from, to}) => { - text = text.replaceAll(from, to); + text = text.replaceAll(from, `"${to}"`); }); - const regex = /\btuiIcon(?!Button\b)[A-Z][a-zA-Z0-9]*\b/g; + const regex = /['"`]tuiIcon(?!Button\b)[A-Z][a-zA-Z0-9]*\b/g; text = text.replaceAll(regex, (match) => convertString(match)); @@ -49,7 +49,7 @@ export function renameIcons(pattern = ALL_FILES): void { function convertString(input: string): string { let result = input - .replace(/^tuiIcon/, '') + .replace(/["'`]tuiIcon/, '') .replace(/Large$/, '') .replaceAll(/([A-Z0-9])/g, '-$1') .toLowerCase(); @@ -61,5 +61,5 @@ function convertString(input: string): string { result = `circle${result}`; } - return `@tui.${result.startsWith('-') ? result.slice(1) : result}`; + return `${input.slice(0, 1)}@tui.${result.startsWith('-') ? result.slice(1) : result}`; } diff --git a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-icons.spec.ts b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-icons.spec.ts index e09a2389ece9..9f6425f92202 100644 --- a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-icons.spec.ts +++ b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-icons.spec.ts @@ -14,23 +14,35 @@ import { const collectionPath = join(__dirname, '../../../migration.json'); const COMPONENT_BEFORE = `import { Component } from "@angular/core"; +import { iconsName } from "some-path"; + +const iconsMap = { + tuiIconStar: 'tuiIconStar' +} @Component({ standalone: true, templateUrl: './test.template.html', }) export class Test { - icons = ['tuiIconMailLarge', 'tuiIconStar', 'tuiIconArrowDown'] + icons = ['tuiIconMailLarge', 'tuiIconStar', 'tuiIconArrowDown']; + icon = iconsName.tuiIconStart; }`; const COMPONENT_AFTER = `import { Component } from "@angular/core"; +import { iconsName } from "some-path"; + +const iconsMap = { + tuiIconStar: '@tui.star' +} @Component({ standalone: true, templateUrl: './test.template.html', }) export class Test { - icons = ['@tui.mail', '@tui.star', '@tui.arrow-down'] + icons = ['@tui.mail', '@tui.star', '@tui.arrow-down']; + icon = iconsName.tuiIconStart; }`; const TEMPLATE_BEFORE = `