Skip to content

Commit fd59d39

Browse files
committed
chore(paginator): add migration paginator #6091
1 parent 94f4971 commit fd59d39

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
"version": "8.2.3",
5656
"description": "Updates Ignite UI for Angular from v8.2.0 to v8.2.3",
5757
"factory": "./update-8_2_3"
58+
},
59+
"migration-12": {
60+
"version": "8.2.6",
61+
"description": "Updates Ignite UI for Angular from v8.2.3 to v8.2.6",
62+
"factory": "./update-8_2_6"
5863
}
5964
}
6065
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import * as path from 'path';
2+
3+
// tslint:disable:no-implicit-dependencies
4+
import { EmptyTree } from '@angular-devkit/schematics';
5+
// tslint:disable-next-line:no-submodule-imports
6+
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
7+
8+
describe('Update 8.2.6', () => {
9+
let appTree: UnitTestTree;
10+
const schematicRunner = new SchematicTestRunner('ig-migrate', path.join(__dirname, '../migration-collection.json'));
11+
const configJson = {
12+
defaultProject: 'testProj',
13+
projects: {
14+
testProj: {
15+
sourceRoot: '/testSrc'
16+
}
17+
},
18+
schematics: {
19+
'@schematics/angular:component': {
20+
prefix: 'appPrefix'
21+
}
22+
}
23+
};
24+
25+
beforeEach(() => {
26+
appTree = new UnitTestTree(new EmptyTree());
27+
appTree.create('/angular.json', JSON.stringify(configJson));
28+
});
29+
30+
it('should update igx-grid-paginator-theme', done => {
31+
appTree.create(
32+
'/testSrc/appPrefix/component/test.component.scss',
33+
`$dark-grid-paginator: igx-grid-paginator-theme($color: black);
34+
@include igx-grid-paginator($dark-grid-paginator);
35+
.igx-grid-paginator__pager {
36+
@include igx-button($dark-button);
37+
}
38+
$dark-grid-paginator-schema: extend($_dark-grid-pagination,());`
39+
);
40+
const tree = schematicRunner.runSchematic('migration-12', {}, appTree);
41+
expect(tree.readContent('/testSrc/appPrefix/component/test.component.scss'))
42+
.toEqual(
43+
`$dark-grid-paginator: igx-paginator-theme($color: black);
44+
@include igx-paginator($dark-grid-paginator);
45+
.igx-grid-paginator__pager {
46+
@include igx-button($dark-button);
47+
}
48+
$dark-grid-paginator-schema: extend($_dark-pagination,());`
49+
);
50+
done();
51+
});
52+
});
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import {
2+
Rule,
3+
SchematicContext,
4+
Tree
5+
} from '@angular-devkit/schematics';
6+
import { getProjects, getWorkspace } from '../common/util';
7+
import { UpdateChanges } from '../common/UpdateChanges';
8+
9+
const version = '8.2.6';
10+
11+
export default function(): Rule {
12+
return (host: Tree, context: SchematicContext) => {
13+
const themes = ['$_base-dark-grid-pagination',
14+
'$_dark-grid-pagination',
15+
'$_dark-fluent-grid-pagination',
16+
'$_light-grid-pagination',
17+
'$_fluent-grid-pagination',
18+
'$_round-shape-grid-pagination',
19+
'$_default-shape-grid-pagination',
20+
'$_square-shape-grid-pagination'];
21+
22+
const newThemes = ['$_base-dark-pagination',
23+
'$_dark-pagination',
24+
'$_dark-fluent-pagination',
25+
'$_light-pagination',
26+
'$_fluent-pagination',
27+
'$_round-shape-pagination',
28+
'$_default-shape-pagination',
29+
'$_square-shape-pagination'];
30+
31+
let globalStyleExt: string;
32+
const config = getWorkspace(host);
33+
const projects = getProjects(config);
34+
35+
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
36+
37+
if (config.schematics && config.schematics['@schematics/angular:component']) {
38+
// updated projects have global prefix rather than per-project:
39+
globalStyleExt = config.schematics['@schematics/angular:component'].styleext;
40+
}
41+
42+
for (const proj of projects) {
43+
const dir = host.getDir(proj.sourceRoot);
44+
let ext = globalStyleExt || 'scss';
45+
if (proj.schematics && proj.schematics['@schematics/angular:component']) {
46+
ext = proj.schematics['@schematics/angular:component'].styleext || ext;
47+
}
48+
dir.visit((path, entry) => {
49+
if (path.endsWith('.' + ext)) {
50+
let content = entry.content.toString();
51+
if (content.match(/\bigx-grid-paginator\b/g)) {
52+
content = content.replace(/\bigx-grid-paginator\b/g, 'igx-paginator');
53+
}
54+
themes.forEach((n, i) => {
55+
if (content.indexOf(n) !== -1) {
56+
content = content.split(n).join(newThemes[i]);
57+
}
58+
});
59+
host.overwrite(path, content);
60+
}
61+
});
62+
}
63+
64+
const update = new UpdateChanges(__dirname, host, context);
65+
update.applyChanges();
66+
};
67+
}

0 commit comments

Comments
 (0)