-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
ng update
migration schematic
- Loading branch information
1 parent
7c13e96
commit 5bb5dc7
Showing
8 changed files
with
2,739 additions
and
1,251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json", | ||
"schematics": { | ||
"migration-01": { | ||
"version": "2.0.0-beta.0", | ||
"description": "Updates Ignite UI for Angular project from 1.3", | ||
"factory": "./update-2" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import * as path from "path"; | ||
|
||
// tslint:disable:no-implicit-dependencies | ||
import { virtualFs } from "@angular-devkit/core"; | ||
import { EmptyTree } from "@angular-devkit/schematics"; | ||
// tslint:disable-next-line:no-submodule-imports | ||
import { SchematicTestRunner, UnitTestTree } from "@angular-devkit/schematics/testing"; | ||
|
||
describe("Update 2.0.0", () => { | ||
let appTree: UnitTestTree; | ||
const schematicRunner = new SchematicTestRunner("ig-migrate", path.join(__dirname, "../migration-collection.json")); | ||
|
||
beforeEach(() => { | ||
appTree = new UnitTestTree(new EmptyTree()); | ||
}); | ||
|
||
it("should update router event rxjs subscription", done => { | ||
appTree.create( | ||
"/src/app/app.component.ts", | ||
`import { Component, OnInit, ViewChild } from '@angular/core'; | ||
import { NavigationStart, Router } from '@angular/router'; | ||
import 'rxjs/add/operator/filter'; | ||
import { IgxNavigationDrawerComponent } from 'igniteui-angular'; | ||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.css'] | ||
}) | ||
export class AppComponent implements OnInit { | ||
@ViewChild(IgxNavigationDrawerComponent) public navdrawer: IgxNavigationDrawerComponent; | ||
constructor(private router: Router) {} | ||
public ngOnInit(): void { | ||
this.router.events | ||
.filter((x) => x instanceof NavigationStart) | ||
.subscribe((event: NavigationStart) => { | ||
if (event.url !== '/' && !this.navdrawer.pin) { | ||
this.navdrawer.close(); | ||
} | ||
}); | ||
} | ||
} | ||
` | ||
); | ||
|
||
const tree = schematicRunner.runSchematic("migration-01", {}, appTree); | ||
expect(tree.readContent("/src/app/app.component.ts")) | ||
.toEqual( | ||
`import { Component, OnInit, ViewChild } from '@angular/core'; | ||
import { NavigationStart, Router } from '@angular/router'; | ||
import { filter } from 'rxjs/operators'; | ||
import { IgxNavigationDrawerComponent } from 'igniteui-angular'; | ||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.css'] | ||
}) | ||
export class AppComponent implements OnInit { | ||
@ViewChild(IgxNavigationDrawerComponent) public navdrawer: IgxNavigationDrawerComponent; | ||
constructor(private router: Router) {} | ||
public ngOnInit(): void { | ||
this.router.events | ||
.pipe(filter((x) => x instanceof NavigationStart)) | ||
.subscribe((event: NavigationStart) => { | ||
if (event.url !== '/' && !this.navdrawer.pin) { | ||
this.navdrawer.close(); | ||
} | ||
}); | ||
} | ||
} | ||
` | ||
); | ||
done(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as path from "path"; | ||
import * as ts from "typescript"; | ||
|
||
// tslint:disable:no-implicit-dependencies | ||
import { Rule, SchematicContext, Tree } from "@angular-devkit/schematics"; | ||
|
||
export default function(): Rule { | ||
return (host: Tree, context: SchematicContext) => { | ||
context.logger.info("Updating project to Ignite UI CLI 2.0.0"); | ||
|
||
const appComponentPath = "src/app/app.component.ts"; | ||
|
||
if (host.exists(appComponentPath)) { | ||
let content = host.read(appComponentPath).toString(); | ||
if (content.indexOf("rxjs/add/operator") !== -1) { | ||
content = content.replace( | ||
`import 'rxjs/add/operator/filter';`, | ||
`import { filter } from 'rxjs/operators';` | ||
); | ||
content = content.replace( | ||
`.filter((x) => x instanceof NavigationStart)`, | ||
`.pipe(filter((x) => x instanceof NavigationStart))` | ||
); | ||
host.overwrite(appComponentPath, content); | ||
} | ||
} | ||
}; | ||
} |
Oops, something went wrong.