Skip to content

Commit

Permalink
Merge pull request #10444 from IgniteUI/dmdimitrov/exporter-services-…
Browse files Browse the repository at this point in the history
…migration

feat(exporters): added migration comments and test
  • Loading branch information
DiyanDimitrov authored Nov 16, 2021
2 parents 461f2e9 + 00d4e9b commit 17d772a
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
69 changes: 69 additions & 0 deletions projects/igniteui-angular/migrations/update-13_0_0/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,73 @@ describe(`Update to ${version}`, () => {
</div>
`.replace(lineBreaksAndSpaceRegex, ''));
});

it('should insert a comment when exporter services are present in module.ts files', async () => {
appTree.create('/testSrc/appPrefix/component/app.module.ts',
`import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { IgxCsvExporterService, IgxExcelExporterService } from "igniteui-angular";
import { ExcelExportComponent } from "./services/export-excel/excel-export.component";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
ExcelExportComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule
],
providers: [
IgxCsvExporterService,
IgxExcelExporterService
],
entryComponents: [],
schemas: []
})
export class AppModule {}
`);

const tree = await schematicRunner
.runSchematicAsync(migrationName, {}, appTree)
.toPromise();

expect(
tree.readContent('/testSrc/appPrefix/component/app.module.ts')
).toEqual(
`// IgxCsvExporterService and IgxExcelExporterService no longer need to be manually provided and can be safely removed.
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { IgxCsvExporterService, IgxExcelExporterService } from "igniteui-angular";
import { ExcelExportComponent } from "./services/export-excel/excel-export.component";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
ExcelExportComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule
],
providers: [
IgxCsvExporterService,
IgxExcelExporterService
],
entryComponents: [],
schemas: []
})
export class AppModule {}
`);
});
});
25 changes: 25 additions & 0 deletions projects/igniteui-angular/migrations/update-13_0_0/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default (): Rule => (host: Tree, context: SchematicContext) => {
const GRIDS = ['IgxGridComponent', 'IgxTreeGridComponent', 'IgxHierarchicalGridComponent'];
const TAGS = ['igx-grid', 'igx-tree-grid', 'igx-hierarchical-grid'];
const tsFiles = update.tsFiles;
const SERVICES = ['IgxCsvExporterService', 'IgxExcelExporterService'];

for (const path of update.templateFiles) {
findElementNodes(parseFile(host, path), TAGS)
Expand Down Expand Up @@ -61,5 +62,29 @@ export default (): Rule => (host: Tree, context: SchematicContext) => {
}
});
}

const moduleTsFiles = tsFiles.filter(x => x.endsWith('.module.ts'));
for (const path of moduleTsFiles) {
let content = host.read(path)?.toString();
const servicesInFile = [];
SERVICES.forEach(service => {
if (content.indexOf(service) > -1) {
servicesInFile.push(service);
}
});

if (servicesInFile.length > 0) {
let newLine = '\n';
if (content.indexOf('\r\n') > -1) {
newLine = '\r\n';
}

const comment =
'// ' + servicesInFile.join(' and ') + ' no longer need to be manually provided and can be safely removed.' + newLine;
content = comment + content;
host.overwrite(path, content);
}
}

update.applyChanges();
};

0 comments on commit 17d772a

Please sign in to comment.