Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(schematics): replace whole icon name instead of substring #5334

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/cdk/schematics/ng-update/utils/replace-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {getSourceFiles} from 'ng-morph';
import {ALL_FILES} from '../../constants';

export function replaceText(
replaceable: Array<{from: string; to: string}>,
replaceable: Array<{from: RegExp | string; to: string}>,
pattern = ALL_FILES,
): void {
const sourceFiles = getSourceFiles(pattern);
Expand Down
12 changes: 12 additions & 0 deletions projects/cdk/schematics/ng-update/v3-35/constants/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,10 @@ export const ICONS: Array<{from: string; to: string}> = [
to: `tuiIconTdsEyeSmallPragmatic`,
from: `tuiIconShow`,
},
{
to: `tuiIconTdsEyeMediumPragmatic`,
from: `tuiIconShowLarge`,
},
{
to: `tuiIconTdsEyeSmallPragmatic`,
from: `tuiIconEye`,
Expand All @@ -751,6 +755,10 @@ export const ICONS: Array<{from: string; to: string}> = [
to: `tuiIconTdsEyeOffSmallPragmatic`,
from: `tuiIconHide`,
},
{
to: `tuiIconTdsEyeOffMediumPragmatic`,
from: `tuiIconHideLarge`,
},
{
to: `tuiIconTdsEyeOffSmallPragmatic`,
from: `tuiIconEyeOff`,
Expand Down Expand Up @@ -1683,6 +1691,10 @@ export const ICONS: Array<{from: string; to: string}> = [
to: `tuiIconTdsArrowsLeftRightSmallPragmatic`,
from: `tuiIconRefresh`,
},
{
to: `tuiIconTdsArrowsLeftRightMediumPragmatic`,
from: `tuiIconRefreshLarge`,
},
{
to: `tuiIconTdsArrowsLeftRightSmallPragmatic`,
from: `tuiIconRefreshCw`,
Expand Down
4 changes: 3 additions & 1 deletion projects/cdk/schematics/ng-update/v3-35/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export function updateToV3_35(options: TuiSchema): Rule {

!options[`skip-logs`] &&
infoLog(`${SMALL_TAB_SYMBOL}${REPLACE_SYMBOL} replacing strings...`);
replaceText(ICONS);
replaceText(
ICONS.map(({from, to}) => ({from: new RegExp(`\\b${from}\\b`, `g`), to})),
);

fileSystem.commitEdits();
saveActiveProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,43 @@ import {createAngularJson} from '../../../utils/create-angular-json';
const collectionPath = join(__dirname, `../../../migration.json`);

const COMPONENT_BEFORE = `
import { tuiIconAlertCircleOutline, tuiIconAlertLarge } from '@taiga-ui/proprietary-icons';
import { tuiIconAlertCircleOutline, tuiIconAlertLarge, tuiIconViewListLarge, tuiIconLinkedLarge } from '@taiga-ui/proprietary-icons';

@Component({templateUrl: './test.template.html'})
export class TestComponent {
account = {
icon: 'tuiIconAlertLarge',
icon2: 'tuiIconViewListLarge',
icon3: tuiIconLinkedLarge,
color: 'white',
background: 'var(--tui-support-12)',
};

icon = tuiIconAlertCircleOutline;
icon2 = tuiIconAlertLarge;
}`;
icon3 = tuiIconViewListLarge;
}
`;

const COMPONENT_AFTER = `import { tuiIconTdsAlertSmallPragmatic, tuiIconTdsExclamationMediumPragmatic } from "@taiga-ui/proprietary-tds-icons";

import { tuiIconViewListLarge, tuiIconLinkedLarge } from '@taiga-ui/proprietary-icons';

@Component({templateUrl: './test.template.html'})
export class TestComponent {
account = {
icon: 'tuiIconTdsExclamationMediumPragmatic',
icon2: 'tuiIconViewListLarge',
icon3: tuiIconLinkedLarge,
color: 'white',
background: 'var(--tui-support-12)',
};

icon = tuiIconTdsAlertSmallPragmatic;
icon2 = tuiIconTdsExclamationMediumPragmatic;
}`;
icon3 = tuiIconViewListLarge;
}
`;

const TEMPLATE_BEFORE = `
<tui-marker-icon
Expand All @@ -52,6 +62,8 @@ const TEMPLATE_BEFORE = `
[size]="iconSize"
></tui-marker-icon>
<custom-component [customAttr]="tuiIconArrowDown"></custom-component>
<tui-svg src='tuiIconViewListLarge' />
<tui-svg src="tuiIconLinkedLarge" />
`;

const TEMPLATE_AFTER = `
Expand All @@ -62,6 +74,8 @@ const TEMPLATE_AFTER = `
[size]="iconSize"
></tui-marker-icon>
<custom-component [customAttr]="tuiIconTdsArrowDownSmallPragmatic"></custom-component>
<tui-svg src='tuiIconViewListLarge' />
<tui-svg src="tuiIconLinkedLarge" />
`;

describe(`ng-update`, () => {
Expand Down