-
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.
Migrate projectType in cli config (#1180)
- Loading branch information
1 parent
e8335dd
commit 82e6574
Showing
14 changed files
with
285 additions
and
10 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,14 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"$id": "igniteui-cli", | ||
"title": "IgniteUI CLI schematic", | ||
"type": "object", | ||
"properties": { | ||
"applyMigrations": { | ||
"type": "boolean", | ||
"description": "We've updated our view templates to use Standalone Components. Those are compatible with your project and you can start using them now or remain with `NgModule` dependencies.", | ||
"default": true, | ||
"x-prompt": "Would you like to continue with Standalone Components for new views?" | ||
} | ||
} | ||
} |
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,73 @@ | ||
import * as path from "path"; | ||
// tslint:disable:no-implicit-dependencies | ||
import { EmptyTree } from "@angular-devkit/schematics"; | ||
// tslint:disable-next-line:no-submodule-imports | ||
import { SchematicTestRunner, UnitTestTree } from "@angular-devkit/schematics/testing"; | ||
|
||
describe("Update 13.1.0", () => { | ||
let appTree: UnitTestTree; | ||
const schematicRunner = new SchematicTestRunner("ig-migrate", path.join(__dirname, "../migration-collection.json")); | ||
|
||
beforeEach(() => { | ||
appTree = new UnitTestTree(new EmptyTree()); | ||
}); | ||
|
||
it("change projectType to legacy", async done => { | ||
appTree.create( | ||
"./ignite-ui-cli.json", | ||
`{ | ||
"igPackageRegistry": "https://packages.infragistics.com/npm/js-licensed/", | ||
"customTemplates": [], | ||
"skipGit": false, | ||
"skipAnalytic": false, | ||
"version": "13.0.1", | ||
"project": { | ||
"defaultPort": 4200, | ||
"framework": "angular", | ||
"projectType": "igx-ts", | ||
"projectTemplate": "side-nav", | ||
"theme": "Default", | ||
"themePath": "node_modules/igniteui-angular/styles/igniteui-angular.css", | ||
"isBundle": false, | ||
"bundleFilePath": "", | ||
"igniteuiSource": "", | ||
"components": [], | ||
"sourceFiles": [], | ||
"isShowcase": false, | ||
"version": "" | ||
}, | ||
"build": {} | ||
}` | ||
); | ||
|
||
const tree = await schematicRunner.runSchematicAsync("migration-07", { applyMigrations: true }, appTree).toPromise(); | ||
expect(tree.readContent("./ignite-ui-cli.json")) | ||
.toEqual( | ||
`{ | ||
"igPackageRegistry": "https://packages.infragistics.com/npm/js-licensed/", | ||
"customTemplates": [], | ||
"skipGit": false, | ||
"skipAnalytic": false, | ||
"version": "13.0.1", | ||
"project": { | ||
"defaultPort": 4200, | ||
"framework": "angular", | ||
"projectType": "igx-ts-legacy", | ||
"projectTemplate": "side-nav", | ||
"theme": "Default", | ||
"themePath": "node_modules/igniteui-angular/styles/igniteui-angular.css", | ||
"isBundle": false, | ||
"bundleFilePath": "", | ||
"igniteuiSource": "", | ||
"components": [], | ||
"sourceFiles": [], | ||
"isShowcase": false, | ||
"version": "" | ||
}, | ||
"build": {} | ||
}` | ||
); | ||
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,20 @@ | ||
// tslint:disable:no-implicit-dependencies | ||
import { Rule, SchematicContext, Tree } from "@angular-devkit/schematics"; | ||
|
||
export default function(options: any): Rule { | ||
return (host: Tree, context: SchematicContext) => { | ||
if (!options.applyMigrations) { return; } | ||
|
||
context.logger.info("We've updated your project type to `igx-ts-legacy` to continue using `NgModule`-s. You can always change back to `igx-ts` should you want to start using Standalone Components."); | ||
|
||
const igConfig = "./ignite-ui-cli.json"; | ||
|
||
if (host.exists(igConfig)) { | ||
const content = JSON.parse(host.read(igConfig)!.toString()); | ||
if (content?.project?.projectType === "igx-ts") { | ||
content.project.projectType = "igx-ts-legacy"; | ||
host.overwrite(igConfig, JSON.stringify(content, null, 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
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
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,4 @@ | ||
export interface Options { | ||
[key: string]: any; | ||
applyMigrations: boolean; | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/ng-schematics/src/migrations/migration-collection.json
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
{ | ||
"$schema": "../../../../node_modules/@angular-devkit/schematics/collection-schema.json", | ||
"schematics": { | ||
"migration-01": { | ||
"version": "17.1.0", | ||
"description": "Updates Ignite UI for Angular Schematics project from 17.0.x to 17.1.x", | ||
"factory": "./update-1", | ||
"schema": "./schema.json" | ||
} | ||
} | ||
} |
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,14 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"$id": "igniteui-angular--schematics", | ||
"title": "IgniteUI for Angular Schematics", | ||
"type": "object", | ||
"properties": { | ||
"applyMigrations": { | ||
"type": "boolean", | ||
"description": "We've updated our view templates to use Standalone Components. Those are compatible with your project and you can start using them now or remain with `NgModule` dependencies.", | ||
"default": true, | ||
"x-prompt": "Would you like to continue with Standalone Components for new views?" | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
packages/ng-schematics/src/migrations/update-1/index.spec.ts
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,72 @@ | ||
import * as path from "path"; | ||
import { EmptyTree } from "@angular-devkit/schematics"; | ||
import { SchematicTestRunner, UnitTestTree } from "@angular-devkit/schematics/testing"; | ||
|
||
describe("Update 17.1.0", () => { | ||
let appTree: UnitTestTree; | ||
const schematicRunner = new SchematicTestRunner("ig-migrate", path.join(__dirname, "../migration-collection.json")); | ||
|
||
beforeEach(() => { | ||
appTree = new UnitTestTree(new EmptyTree()); | ||
}); | ||
|
||
it("change projectType to legacy", async done => { | ||
appTree.create( | ||
"./ignite-ui-cli.json", | ||
`{ | ||
"igPackageRegistry": "https://packages.infragistics.com/npm/js-licensed/", | ||
"customTemplates": [], | ||
"skipGit": false, | ||
"skipAnalytic": false, | ||
"version": "13.0.1", | ||
"project": { | ||
"defaultPort": 4200, | ||
"framework": "angular", | ||
"projectType": "igx-ts", | ||
"projectTemplate": "side-nav", | ||
"theme": "Default", | ||
"themePath": "node_modules/igniteui-angular/styles/igniteui-angular.css", | ||
"isBundle": false, | ||
"bundleFilePath": "", | ||
"igniteuiSource": "", | ||
"components": [], | ||
"sourceFiles": [], | ||
"isShowcase": false, | ||
"version": "" | ||
}, | ||
"build": {} | ||
} | ||
` | ||
); | ||
|
||
const tree = await schematicRunner.runSchematicAsync("migration-01", { applyMigrations: true }, appTree).toPromise(); | ||
expect(tree.readContent("./ignite-ui-cli.json")) | ||
.toEqual( | ||
`{ | ||
"igPackageRegistry": "https://packages.infragistics.com/npm/js-licensed/", | ||
"customTemplates": [], | ||
"skipGit": false, | ||
"skipAnalytic": false, | ||
"version": "13.0.1", | ||
"project": { | ||
"defaultPort": 4200, | ||
"framework": "angular", | ||
"projectType": "igx-ts-legacy", | ||
"projectTemplate": "side-nav", | ||
"theme": "Default", | ||
"themePath": "node_modules/igniteui-angular/styles/igniteui-angular.css", | ||
"isBundle": false, | ||
"bundleFilePath": "", | ||
"igniteuiSource": "", | ||
"components": [], | ||
"sourceFiles": [], | ||
"isShowcase": false, | ||
"version": "" | ||
}, | ||
"build": {} | ||
}` | ||
); | ||
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,20 @@ | ||
import { Rule, SchematicContext, Tree } from "@angular-devkit/schematics"; | ||
import { Options } from "../interfaces/options"; | ||
|
||
export default function(options: Options): Rule { | ||
return (host: Tree, context: SchematicContext) => { | ||
if (!options.applyMigrations) { return; } | ||
|
||
context.logger.info("We've updated your project type to `igx-ts-legacy` to continue using `NgModule`-s. You can always change back to `igx-ts` should you want to start using Standalone Components."); | ||
|
||
const igConfig = "./ignite-ui-cli.json"; | ||
|
||
if (host.exists(igConfig)) { | ||
const content = JSON.parse(host.read(igConfig)!.toString()); | ||
if (content?.project?.projectType === "igx-ts") { | ||
content.project.projectType = "igx-ts-legacy"; | ||
host.overwrite(igConfig, JSON.stringify(content, null, 2)); | ||
} | ||
} | ||
}; | ||
} |