Skip to content

Commit

Permalink
feat(wizard): finalize calling to upgrade command, #724
Browse files Browse the repository at this point in the history
Test if upgrade command is called in prompt session test.
Update prompt questions.
Add skipInstall to new schematics.

Co-authored-by: Damyan Petev <damyan.petev@gmail.com>
  • Loading branch information
wnvko and damyanpetev committed May 26, 2020
1 parent a5633e3 commit 41e1665
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 19 deletions.
6 changes: 4 additions & 2 deletions packages/cli/lib/PromptSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as inquirer from "inquirer";
import * as path from "path";
import { default as add } from "./commands/add";
import { default as start } from "./commands/start";
import { default as upgrade } from "./commands/upgrade";
import { TemplateManager } from "./TemplateManager";

export class PromptSession extends BasePromptSession {
Expand Down Expand Up @@ -101,8 +102,9 @@ export class PromptSession extends BasePromptSession {
}
}

protected upgradePackages() {
// TODO: call update command
protected async upgradePackages() {
upgrade.templateManager = this.templateManager as TemplateManager;
await upgrade.upgrade({ skipInstall: true });
}

/**
Expand Down
20 changes: 12 additions & 8 deletions packages/core/prompt/BasePromptSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export abstract class BasePromptSession {
/** Install packages and run project */
protected abstract async completeAndRun(port?: number);

/** Upgrade packages to paid subscription bla bla bla */
protected abstract upgradePackages();
/** Upgrade packages to use private Infragistics feed */
protected abstract async upgradePackages();

/**
* Get user name and set template's extra configurations if any
Expand Down Expand Up @@ -373,18 +373,22 @@ export abstract class BasePromptSession {
case "Complete & Run":
const config = ProjectConfig.localConfig();

if (config.project.framework === "angular" && !config.packagesInstalled) {
if (config.project.framework === "angular" &&
config.project.projectType === "igx-ts" &&
!config.packagesInstalled) {
// TODO: should we add check if there are paid components at all
const usePaidAngular = await this.getUserInput({
Util.log("The project will be created using a Trial version of Ignite UI for Angular.");
Util.log("You can always run the upgrade-packages command.");
const shouldUpgrade = await this.getUserInput({
type: "list",
name: "usePaidAngular",
message: "Do you have paid subscription:",
name: "shouldUpgrade",
message: "Would you like to upgrade to the licensed feed now (requires active subscription)?",
choices: [ "yes", "no" ],
default: "yes"
});

if (usePaidAngular === "yes") {
this.upgradePackages();
if (shouldUpgrade === "yes") {
await this.upgradePackages();
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ng-schematics/src/ng-new/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export function newProject(options: OptionsSchema): Rule {
const installChain: TaskId[] = [];
if (prompt.userAnswers && prompt.userAnswers.get("upgradePackages")) {
const upgradeTaskId = context.addTask(
new RunSchematicTask("upgrade-packages", {}));
new RunSchematicTask("upgrade-packages", { skipInstall: true }));
installChain.push(upgradeTaskId);
}
if (!options.skipInstall) {
Expand Down
4 changes: 2 additions & 2 deletions packages/ng-schematics/src/ng-new/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("Schematics ng-new", () => {
const expectedUpgrade = {
collection: null,
name: "upgrade-packages",
options: {}
options: { skipInstall: true }
};
const expectedInstall: NodePackageTaskOptions = {
command: "install",
Expand Down Expand Up @@ -128,7 +128,7 @@ describe("Schematics ng-new", () => {
const expectedUpgrade = {
collection: null,
name: "upgrade-packages",
options: {}
options: { skipInstall: true }
};
const expectedInstall: NodePackageTaskOptions = {
command: "install",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class SchematicsPromptSession extends BasePromptSession {
// TODO?
}

protected upgradePackages() {
protected async upgradePackages() {
this.userAnswers.set("upgradePackages", true);
}

Expand Down
6 changes: 5 additions & 1 deletion packages/ng-schematics/src/upgrade-packages/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ describe("Schematics upgrade-packages", () => {
expect(runner.tasks).toEqual([]);

upgradeSpy.and.returnValue(Promise.resolve(true));
await runner.runSchematicAsync(schematicName, { }, appTree).toPromise();
await runner.runSchematicAsync(schematicName, { skipInstall: true }, appTree).toPromise();
expect(upgradeSpy).toHaveBeenCalledTimes(2);
expect(runner.tasks).toEqual([]);

await runner.runSchematicAsync(schematicName, { }, appTree).toPromise();
expect(upgradeSpy).toHaveBeenCalledTimes(3);
const installTaskOptions = new NodePackageInstallTask().toConfiguration();
expect(runner.tasks).toContain(jasmine.objectContaining(installTaskOptions));

Expand Down
8 changes: 6 additions & 2 deletions packages/ng-schematics/src/upgrade-packages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { defer } from "rxjs";
import { SchematicsTemplateManager } from "../SchematicsTemplateManager";
import { setVirtual } from "../utils/NgFileSystem";

export default function(_options: any): Rule {
interface UpgradeOptions {
skipInstall?: boolean;
}

export default function(options: UpgradeOptions): Rule {
return (tree: Tree, context: SchematicContext) => {
App.initialize("angular-cli");
GoogleAnalytics.post({
Expand All @@ -19,7 +23,7 @@ export default function(_options: any): Rule {
setVirtual(tree);
return defer(async () => {
const success = await project.upgradeIgniteUIPackages("", "");
if (success) {
if (success && !options.skipInstall) {
context.addTask(new NodePackageInstallTask());
}
return tree;
Expand Down
14 changes: 14 additions & 0 deletions packages/ng-schematics/src/upgrade-packages/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/schema",
"id": "SchematicsAngularNgNew",
"title": "Ignite UI for Angular Upgrade packages Options Schema",
"type": "object",
"properties": {
"skipInstall": {
"description": "Do not automatically install packages.",
"type": "boolean",
"default": false,
"alias": "si"
}
}
}
9 changes: 7 additions & 2 deletions spec/unit/PromptSession-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as inquirer from "inquirer";
import * as path from "path";
import { default as add } from "../../packages/cli/lib/commands/add";
import { default as start } from "../../packages/cli/lib/commands/start";
import { default as upgrade } from "../../packages/cli/lib/commands/upgrade";
import { PromptSession } from "../../packages/cli/lib/PromptSession";
import { TemplateManager } from "../../packages/cli/lib/TemplateManager";

Expand Down Expand Up @@ -452,7 +453,7 @@ describe("Unit - PromptSession", () => {
await mockSession.chooseActionLoop(mockProjectLibrary);
expect(mockSession.chooseActionLoop).toHaveBeenCalledTimes(1);
expect(inquirer.prompt).toHaveBeenCalledTimes(8);
expect(Util.log).toHaveBeenCalledTimes(3);
expect(Util.log).toHaveBeenCalledTimes(5);
expect(PackageManager.flushQueue).toHaveBeenCalledWith(true);
expect(start.start).toHaveBeenCalledTimes(1);
expect(Util.getAvailableName).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -662,9 +663,13 @@ describe("Unit - PromptSession", () => {
Promise.resolve(4200)
);
spyOn(mockSession as any, "completeAndRun").and.returnValues(Promise.resolve());
spyOn(upgrade, "upgrade").and.returnValue(Promise.resolve());

await mockSession.chooseActionLoop({} as any);

// TODO: check if upgrade command was called
expect(upgrade.upgrade).toHaveBeenCalledTimes(1);
expect(upgrade.upgrade).toHaveBeenCalledWith({ skipInstall: true });

done();
});
it("start - Should fire correctly with Angular Custom theme selected", async done => {
Expand Down

0 comments on commit 41e1665

Please sign in to comment.