Skip to content

Commit 17d772a

Browse files
Merge pull request #10444 from IgniteUI/dmdimitrov/exporter-services-migration
feat(exporters): added migration comments and test
2 parents 461f2e9 + 00d4e9b commit 17d772a

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,73 @@ describe(`Update to ${version}`, () => {
200200
</div>
201201
`.replace(lineBreaksAndSpaceRegex, ''));
202202
});
203+
204+
it('should insert a comment when exporter services are present in module.ts files', async () => {
205+
appTree.create('/testSrc/appPrefix/component/app.module.ts',
206+
`import { NgModule } from "@angular/core";
207+
import { FormsModule } from "@angular/forms";
208+
import { BrowserModule } from "@angular/platform-browser";
209+
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
210+
import { AppComponent } from "./app.component";
211+
import { IgxCsvExporterService, IgxExcelExporterService } from "igniteui-angular";
212+
import { ExcelExportComponent } from "./services/export-excel/excel-export.component";
213+
214+
@NgModule({
215+
bootstrap: [AppComponent],
216+
declarations: [
217+
AppComponent,
218+
ExcelExportComponent
219+
],
220+
imports: [
221+
BrowserModule,
222+
BrowserAnimationsModule,
223+
FormsModule
224+
],
225+
providers: [
226+
IgxCsvExporterService,
227+
IgxExcelExporterService
228+
],
229+
entryComponents: [],
230+
schemas: []
231+
})
232+
export class AppModule {}
233+
`);
234+
235+
const tree = await schematicRunner
236+
.runSchematicAsync(migrationName, {}, appTree)
237+
.toPromise();
238+
239+
expect(
240+
tree.readContent('/testSrc/appPrefix/component/app.module.ts')
241+
).toEqual(
242+
`// IgxCsvExporterService and IgxExcelExporterService no longer need to be manually provided and can be safely removed.
243+
import { NgModule } from "@angular/core";
244+
import { FormsModule } from "@angular/forms";
245+
import { BrowserModule } from "@angular/platform-browser";
246+
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
247+
import { AppComponent } from "./app.component";
248+
import { IgxCsvExporterService, IgxExcelExporterService } from "igniteui-angular";
249+
import { ExcelExportComponent } from "./services/export-excel/excel-export.component";
250+
251+
@NgModule({
252+
bootstrap: [AppComponent],
253+
declarations: [
254+
AppComponent,
255+
ExcelExportComponent
256+
],
257+
imports: [
258+
BrowserModule,
259+
BrowserAnimationsModule,
260+
FormsModule
261+
],
262+
providers: [
263+
IgxCsvExporterService,
264+
IgxExcelExporterService
265+
],
266+
entryComponents: [],
267+
schemas: []
268+
})
269+
export class AppModule {}
270+
`);
271+
});
203272
});

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ 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'];
1920

2021
for (const path of update.templateFiles) {
2122
findElementNodes(parseFile(host, path), TAGS)
@@ -61,5 +62,29 @@ export default (): Rule => (host: Tree, context: SchematicContext) => {
6162
}
6263
});
6364
}
65+
66+
const moduleTsFiles = tsFiles.filter(x => x.endsWith('.module.ts'));
67+
for (const path of moduleTsFiles) {
68+
let content = host.read(path)?.toString();
69+
const servicesInFile = [];
70+
SERVICES.forEach(service => {
71+
if (content.indexOf(service) > -1) {
72+
servicesInFile.push(service);
73+
}
74+
});
75+
76+
if (servicesInFile.length > 0) {
77+
let newLine = '\n';
78+
if (content.indexOf('\r\n') > -1) {
79+
newLine = '\r\n';
80+
}
81+
82+
const comment =
83+
'// ' + servicesInFile.join(' and ') + ' no longer need to be manually provided and can be safely removed.' + newLine;
84+
content = comment + content;
85+
host.overwrite(path, content);
86+
}
87+
}
88+
6489
update.applyChanges();
6590
};

0 commit comments

Comments
 (0)