Skip to content

Commit

Permalink
Migrate projectType in cli config (#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofdiamond5 authored Dec 13, 2023
1 parent e8335dd commit 82e6574
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 10 deletions.
46 changes: 46 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,52 @@
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
},
{
"name": "Run migrations for CLI",
"request": "launch",
"type": "node",
"preLaunchTask": "build",
// "cwd": "<absolute directory of the project, having an old version of igniteui-angular, on which the migrations are applied>",
"cwd": "E:\\Temp\\TestCli",
"args": [
"-r",

// you need to install ts-node for the test project
"ts-node/register",

// "<path/to/ng>", "g",
"${env:AppData}/npm/node_modules/@angular/cli/bin/ng", "g",

// "<../../relative/path/from/cwd/to>/igniteui-angular/projects/igniteui-angular/migrations/migration-collection.json:migration-<number>
"../../Igniteui-Repos/igniteui-cli/packages/cli/migrations/migration-collection.json:migration-07"
],
"env": {
"TS_NODE_PROJECT": "${workspaceFolder}/tsconfig.json"
}
},
{
"name": "Run migrations for Angular Schematics",
"request": "launch",
"type": "node",
"preLaunchTask": "build",
// "cwd": "<absolute directory of the project, having an old version of igniteui-angular, on which the migrations are applied>",
"cwd": "E:\\Temp\\TestCli",
"args": [
"-r",

// you need to install ts-node for the test project
"ts-node/register",

// "<path/to/ng>", "g",
"${env:AppData}/npm/node_modules/@angular/cli/bin/ng", "g",

// "<../../relative/path/from/cwd/to>/igniteui-angular/projects/igniteui-angular/migrations/migration-collection.json:migration-<number>
"../../Igniteui-Repos/igniteui-cli/packages/ng-schematics/src/migrations/migration-collection.json:migration-01"
],
"env": {
"TS_NODE_PROJECT": "${workspaceFolder}/packages/ng-schematics/tsconfig.json"
}
},
{
"type": "node",
"request": "launch",
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/migrations/migration-collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
"version": "5.0.3",
"description": "Updates Ignite UI for Angular project from CLI 5.0.x to 5.0.3",
"factory": "./update-5_0_3"
}
},
"migration-07": {
"version": "13.1.0",
"description": "Updates Ignite UI for Angular Schematics project from 13.0.x to 13.1.x",
"factory": "./update-13_1_0",
"schema": "./schema.json"
}
}
}
14 changes: 14 additions & 0 deletions packages/cli/migrations/schema.json
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?"
}
}
}
73 changes: 73 additions & 0 deletions packages/cli/migrations/update-13_1_0/index.spec.ts
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();
});

});
20 changes: 20 additions & 0 deletions packages/cli/migrations/update-13_1_0/index.ts
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));
}
}
};
}
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "igniteui-cli",
"version": "13.1.0-beta.2",
"version": "13.1.0-beta.4",
"description": "CLI tool for creating Ignite UI projects",
"keywords": [
"CLI",
Expand Down Expand Up @@ -78,8 +78,8 @@
"all": true
},
"dependencies": {
"@igniteui/angular-templates": "~17.0.1310-beta.2",
"@igniteui/cli-core": "~13.1.0-beta.2",
"@igniteui/angular-templates": "~17.1.1310-beta.4",
"@igniteui/cli-core": "~13.1.0-beta.4",
"chalk": "^2.3.2",
"fs-extra": "^3.0.1",
"glob": "^7.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@igniteui/cli-core",
"version": "13.1.0-beta.2",
"version": "13.1.0-beta.4",
"description": "Base types and functionality for Ignite UI CLI",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions packages/igx-templates/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@igniteui/angular-templates",
"version": "17.0.1310-beta.2",
"version": "17.1.1310-beta.4",
"description": "Templates for Ignite UI for Angular projects and components",
"repository": {
"type": "git",
Expand All @@ -12,7 +12,7 @@
"author": "Infragistics",
"license": "MIT",
"dependencies": {
"@igniteui/cli-core": "~13.1.0-beta.2",
"@igniteui/cli-core": "~13.1.0-beta.4",
"typescript": "~4.7.2"
}
}
6 changes: 3 additions & 3 deletions packages/ng-schematics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@igniteui/angular-schematics",
"version": "17.0.1310-beta.2",
"version": "17.1.1310-beta.4",
"description": "Ignite UI for Angular Schematics for ng new and ng generate",
"repository": {
"type": "git",
Expand All @@ -20,8 +20,8 @@
"dependencies": {
"@angular-devkit/core": "~14.0.0",
"@angular-devkit/schematics": "~14.0.0",
"@igniteui/angular-templates": "~17.0.1310-beta.2",
"@igniteui/cli-core": "~13.1.0-beta.2",
"@igniteui/angular-templates": "~17.1.1310-beta.4",
"@igniteui/cli-core": "~13.1.0-beta.4",
"@schematics/angular": "~14.0.0",
"rxjs": "^6.6.3"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/ng-schematics/src/migrations/interfaces/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Options {
[key: string]: any;
applyMigrations: boolean;
}
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"
}
}
}
14 changes: 14 additions & 0 deletions packages/ng-schematics/src/migrations/schema.json
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 packages/ng-schematics/src/migrations/update-1/index.spec.ts
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();
});

});
20 changes: 20 additions & 0 deletions packages/ng-schematics/src/migrations/update-1/index.ts
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));
}
}
};
}

0 comments on commit 82e6574

Please sign in to comment.