Skip to content

Commit 55edaec

Browse files
committed
migrations: migrate --igx-* to --ig-*
1 parent eb6b289 commit 55edaec

3 files changed

Lines changed: 140 additions & 0 deletions

File tree

projects/igniteui-angular/migrations/migration-collection.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@
265265
"factory": "./update-21_1_0_import-migration",
266266
"recommended": true,
267267
"optional": true
268+
},
269+
"migration-53": {
270+
"version": "21.1.0",
271+
"description": "Migrates --igx-* CSS variables to --ig-* for better consistency between component frameworks",
272+
"factory": "./update-21_1_0_css-migration",
273+
"recommended": true,
274+
"optional": true
268275
}
269276
}
270277
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import * as path from 'path';
2+
3+
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
4+
import { setupTestTree } from '../common/setup.spec';
5+
6+
const version = '21.1.0';
7+
8+
describe(`Update to ${version}`, () => {
9+
let appTree: UnitTestTree;
10+
const schematicRunner = new SchematicTestRunner('ig-migrate', path.join(__dirname, '../migration-collection.json'));
11+
12+
beforeEach(() => {
13+
appTree = setupTestTree();
14+
});
15+
16+
const migrationName = 'migration-53';
17+
18+
it('should replace CSS custom properties prefix from --igx to --ig', async () => {
19+
appTree.create(
20+
`/testSrc/appPrefix/component/test.component.scss`,
21+
`.custom-avatar {
22+
--igx-avatar-background: var(--ig-primary-500);
23+
}`
24+
);
25+
26+
const tree = await schematicRunner
27+
.runSchematic(migrationName, {}, appTree);
28+
29+
expect(
30+
tree.readContent('/testSrc/appPrefix/component/test.component.scss')
31+
).toEqual(
32+
`.custom-avatar {
33+
--ig-avatar-background: var(--ig-primary-500);
34+
}`
35+
);
36+
});
37+
38+
it('should replace multiple --igx- occurrences in a single file', async () => {
39+
appTree.create(
40+
`/testSrc/appPrefix/component/multi.component.scss`,
41+
`.theme {
42+
--igx-surface-500: var(--igx-primary-500);
43+
color: var(--igx-secondary-200);
44+
background: var(--igx-surface-100);
45+
}`
46+
);
47+
48+
const tree = await schematicRunner
49+
.runSchematic(migrationName, {}, appTree);
50+
51+
expect(
52+
tree.readContent('/testSrc/appPrefix/component/multi.component.scss')
53+
).toEqual(
54+
`.theme {
55+
--ig-surface-500: var(--ig-primary-500);
56+
color: var(--ig-secondary-200);
57+
background: var(--ig-surface-100);
58+
}`
59+
);
60+
});
61+
62+
it('should leave files without --igx- unchanged', async () => {
63+
const original = `.card {
64+
--ig-primary-500: #000;
65+
}`;
66+
67+
appTree.create(
68+
`/testSrc/appPrefix/component/no-change.component.scss`,
69+
original
70+
);
71+
72+
const tree = await schematicRunner
73+
.runSchematic(migrationName, {}, appTree);
74+
75+
expect(
76+
tree.readContent('/testSrc/appPrefix/component/no-change.component.scss')
77+
).toEqual(original);
78+
});
79+
80+
it('should update --igx- inside :root and comments', async () => {
81+
appTree.create(
82+
`/testSrc/appPrefix/component/root.component.scss`,
83+
`:root {
84+
--igx-radius-factor: 1.25;
85+
}
86+
87+
// --igx-elevation-1 is used for cards
88+
.card {
89+
box-shadow: var(--igx-elevation-1);
90+
}`
91+
);
92+
93+
const tree = await schematicRunner
94+
.runSchematic(migrationName, {}, appTree);
95+
96+
expect(
97+
tree.readContent('/testSrc/appPrefix/component/root.component.scss')
98+
).toEqual(
99+
`:root {
100+
--ig-radius-factor: 1.25;
101+
}
102+
103+
// --ig-elevation-1 is used for cards
104+
.card {
105+
box-shadow: var(--ig-elevation-1);
106+
}`
107+
);
108+
});
109+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type {
2+
Rule,
3+
SchematicContext,
4+
Tree
5+
} from '@angular-devkit/schematics';
6+
import { UpdateChanges } from '../common/UpdateChanges';
7+
8+
const version = '21.1.0';
9+
10+
export default (): Rule => async (host: Tree, context: SchematicContext) => {
11+
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version} - CSS custom properties migration`);
12+
13+
const update = new UpdateChanges(__dirname, host, context);
14+
update.applyChanges();
15+
16+
for (const entryPath of update.sassFiles) {
17+
let content = host.read(entryPath).toString();
18+
19+
if (content.includes('--igx-')) {
20+
content = content.replace(/--igx-/g, '--ig-');
21+
host.overwrite(entryPath, content);
22+
}
23+
}
24+
};

0 commit comments

Comments
 (0)