Skip to content

Commit 282d5fc

Browse files
committed
feat(exporters): added migration comments and test
1 parent 14921f6 commit 282d5fc

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

projects/igniteui-angular/migrations/common/UpdateChanges.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ export class UpdateChanges {
9898
return this._tsFiles;
9999
}
100100

101+
private _ModuletTsFiles: string[] = [];
102+
public get moduleTsFiles(): string[] {
103+
if (!this._ModuletTsFiles.length) {
104+
this.sourceDirsVisitor((fulPath, entry) => {
105+
if (fulPath.endsWith('.module.ts')) {
106+
this._ModuletTsFiles.push(entry.path);
107+
}
108+
});
109+
}
110+
return this._ModuletTsFiles;
111+
}
112+
101113
private _sassFiles: string[] = [];
102114
/** Sass (both .scss and .sass) files in the project being updated. */
103115
public get sassFiles(): string[] {

projects/igniteui-angular/migrations/update-13_0_0/index.spec.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,68 @@ describe(`Update to ${version}`, () => {
188188
</div>
189189
`.replace(lineBreaksAndSpaceRegex, ''));
190190
});
191+
192+
it('should remove exporter services from module.ts files', async () => {
193+
appTree.create('/testSrc/appPrefix/component/app.module.ts', `
194+
import { NgModule } from "@angular/core";
195+
import { FormsModule } from "@angular/forms";
196+
import { BrowserModule } from "@angular/platform-browser";
197+
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
198+
import { AppComponent } from "./app.component";
199+
import { IgxExcelExporterService } from "igniteui-angular";
200+
import { ExcelExportComponent } from "./services/export-excel/excel-export.component";
201+
202+
@NgModule({
203+
bootstrap: [AppComponent],
204+
declarations: [
205+
AppComponent,
206+
ExcelExportComponent
207+
],
208+
imports: [
209+
BrowserModule,
210+
BrowserAnimationsModule,
211+
FormsModule
212+
],
213+
providers: [IgxExcelExporterService],
214+
entryComponents: [],
215+
schemas: []
216+
})
217+
export class AppModule {}
218+
`);
219+
220+
const tree = await schematicRunner
221+
.runSchematicAsync(migrationName, {}, appTree)
222+
.toPromise();
223+
224+
expect(
225+
tree.readContent('/testSrc/appPrefix/component/app.module.ts')
226+
).toEqual( `
227+
import { NgModule } from "@angular/core";
228+
import { FormsModule } from "@angular/forms";
229+
import { BrowserModule } from "@angular/platform-browser";
230+
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
231+
import { AppComponent } from "./app.component";
232+
// IgxExcelExporterService has been removed. Exporter services can now be used without providing.
233+
import { /*IgxExcelExporterService*/ } from "igniteui-angular";
234+
import { ExcelExportComponent } from "./services/export-excel/excel-export.component";
235+
236+
@NgModule({
237+
bootstrap: [AppComponent],
238+
declarations: [
239+
AppComponent,
240+
ExcelExportComponent
241+
],
242+
imports: [
243+
BrowserModule,
244+
BrowserAnimationsModule,
245+
FormsModule
246+
],
247+
// IgxExcelExporterService has been removed. Exporter services can now be used without providing.
248+
providers: [/*IgxExcelExporterService*/],
249+
entryComponents: [],
250+
schemas: []
251+
})
252+
export class AppModule {}
253+
`);
254+
});
191255
});

projects/igniteui-angular/migrations/update-13_0_0/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export default (): Rule => (host: Tree, context: SchematicContext) => {
1616
const GRIDS = ['IgxGridComponent', 'IgxTreeGridComponent', 'IgxHierarchicalGridComponent'];
1717
const TAGS = ['igx-grid', 'igx-tree-grid', 'igx-hierarchical-grid'];
1818
const tsFiles = update.tsFiles;
19+
const SERVICES = ['IgxCsvExporterService', 'IgxExcelExporterService'];
20+
const moduleTsFiles = update.moduleTsFiles;
1921

2022
for (const path of update.templateFiles) {
2123
findElementNodes(parseFile(host, path), TAGS)
@@ -61,5 +63,32 @@ export default (): Rule => (host: Tree, context: SchematicContext) => {
6163
}
6264
});
6365
}
66+
67+
for (const path of moduleTsFiles) {
68+
let content = host.read(path)?.toString();
69+
SERVICES.forEach(service => {
70+
if (content.indexOf(service) > -1) {
71+
const commentedService = '/*' + service + '*/';
72+
content = content.replace(new RegExp(service, 'gi'), commentedService);
73+
const indexes = getIndicesOf(commentedService, content);
74+
indexes.reverse().forEach(index => {
75+
const preceedingContent = content.substring(0, index);
76+
const newLineIndex = preceedingContent.lastIndexOf('\n');
77+
const comment = '// ' + service + ' has been removed. Exporter services can now be used without providing.';
78+
if (newLineIndex > -1) {
79+
const newPreceedingContent =
80+
[preceedingContent.slice(0, newLineIndex), '\n' + comment, preceedingContent.slice(newLineIndex)].join('');
81+
content = content.replace(preceedingContent, newPreceedingContent);
82+
} else {
83+
// service is mentioned on the first row
84+
content = comment + '\n' + content;
85+
}
86+
});
87+
88+
host.overwrite(path, content);
89+
}
90+
});
91+
}
92+
6493
update.applyChanges();
6594
};

0 commit comments

Comments
 (0)