Skip to content

Commit

Permalink
chore: fix icons migration (#8213)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirpotekhin authored Jul 25, 2024
1 parent 0c8c49c commit e8b0210
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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();
Expand All @@ -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}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down

0 comments on commit e8b0210

Please sign in to comment.