Skip to content

Commit b8b19c2

Browse files
committed
refactor(prompt): drop duplicate start override for one log, cleanup
1 parent ebdbcb3 commit b8b19c2

1 file changed

Lines changed: 17 additions & 81 deletions

File tree

packages/cli/lib/PromptSession.ts

Lines changed: 17 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
BasePromptSession, GoogleAnalytics, InquirerWrapper, PackageManager, ProjectConfig,
2+
BasePromptSession, Framework, InquirerWrapper, PackageManager,
33
ProjectLibrary, PromptTaskContext, Task, Util
44
} from "@igniteui/cli-core";
55
import * as path from "path";
@@ -10,110 +10,46 @@ import { default as upgrade } from "./commands/upgrade";
1010

1111
export class PromptSession extends BasePromptSession {
1212

13-
public static async chooseTerm() {
13+
public static async chooseTerm(): Promise<string> {
1414
const answer = await InquirerWrapper.input({
15-
default: null,
1615
message: "Enter a search term",
1716
});
1817
if (answer) {
1918
return answer;
2019
} else {
21-
const retProm = await this.chooseTerm();
22-
return retProm;
20+
return this.chooseTerm();
2321
}
2422
}
2523

26-
/**
27-
* Start questions session for project creation
28-
*/
29-
public async start() {
30-
GoogleAnalytics.post({
31-
t: "screenview",
32-
cd: "Wizard"
33-
});
34-
35-
let projLibrary: ProjectLibrary;
36-
let theme: string;
37-
this.config = ProjectConfig.getConfig();
38-
const defaultProjName = "IG Project";
39-
40-
if (ProjectConfig.hasLocalConfig() && !this.config.project.isShowcase) {
41-
projLibrary = this.templateManager.getProjectLibrary(this.config.project.framework, this.config.project.projectType);
42-
theme = this.config.project.theme;
43-
} else {
44-
Util.log(""); /* new line */
45-
const projectName = await this.getUserInput({
46-
type: "input",
47-
name: "projectName",
48-
message: "Enter a name for your project:",
49-
default: Util.getAvailableName(defaultProjName, true),
50-
choices: null,
51-
validate: this.nameIsValid
52-
});
53-
54-
const frameRes: string = await this.getUserInput({
55-
type: "list",
56-
name: "framework",
57-
message: "Choose framework:",
58-
choices: this.getFrameworkNames(),
59-
default: "Angular"
60-
});
61-
62-
const framework = this.templateManager.getFrameworkByName(frameRes);
63-
// app name validation???
64-
projLibrary = await this.getProjectLibrary(framework);
65-
if (frameRes === "Angular" && projLibrary.projectType === "igx-ts") {
66-
Util.log("Psst! Did you know you can also use our schematics package with Angular CLI to create and modify your projects?", "yellow");
67-
Util.log("Read more at: https://www.infragistics.com/products/ignite-ui-angular/angular/components/general/cli-overview", "yellow");
68-
}
69-
const projTemplate = await this.getProjectTemplate(projLibrary);
70-
// project options:
71-
theme = await this.getTheme(projLibrary);
72-
73-
Util.log(" Generating project structure.");
74-
const config = projTemplate.generateConfig(projectName, theme);
75-
for (const templatePath of projTemplate.templatePaths) {
76-
await Util.processTemplates(templatePath, path.join(process.cwd(), projectName),
77-
config, projTemplate.delimiters, false);
78-
}
79-
80-
Util.log(Util.greenCheck() + " Project structure generated.");
81-
if (!this.config.skipGit) {
82-
Util.gitInit(process.cwd(), projectName);
83-
}
84-
// move cwd to project folder
85-
process.chdir(projectName);
86-
await this.configureAI();
24+
protected override async getProjectLibrary(framework: Framework): Promise<ProjectLibrary> {
25+
const result = await super.getProjectLibrary(framework);
26+
if (framework.name === "Angular" && result.projectType === "igx-ts") {
27+
Util.log("Psst! Did you know you can also use our schematics package with Angular CLI to create and modify your projects?", "yellow");
28+
Util.log("Read more at: https://www.infragistics.com/products/ignite-ui-angular/angular/components/general/cli-overview", "yellow");
8729
}
88-
await this.chooseActionLoop(projLibrary);
89-
//TODO: restore cwd?
30+
return result;
9031
}
9132

92-
protected async completeAndRun(port?: number) {
33+
protected override async completeAndRun(port?: number) {
9334
await PackageManager.flushQueue(true);
9435
await start.start({ port });
9536
}
9637

97-
protected async upgradePackages() {
38+
protected override async upgradePackages() {
9839
await upgrade.upgrade({ skipInstall: true, _: ["upgrade"], $0: "upgrade" });
9940
}
10041

101-
protected async configureAI(): Promise<void> {
42+
protected override async configureAI(): Promise<void> {
10243
await aiConfigure();
10344
}
10445

105-
/**
106-
* Get user name and set template's extra configurations if any
107-
* @param projectLibrary to add component to
108-
* @param component to get template for
109-
*/
110-
protected templateSelectedTask(type: "component" | "view" = "component"): Task<PromptTaskContext> {
46+
protected override templateSelectedTask(type: "component" | "view" = "component"): Task<PromptTaskContext> {
11147
return async (_runner, context) => {
112-
const name = await this.chooseTemplateName(context.template, type);
113-
if (context.template.hasExtraConfiguration) {
114-
await this.customizeTemplateTask(context.template);
48+
const name = await this.chooseTemplateName(context.template!, type);
49+
if (context.template!.hasExtraConfiguration) {
50+
await this.customizeTemplateTask(context.template!);
11551
}
116-
const res = await add.addTemplate(name, context.template);
52+
const res = await add.addTemplate(name, context.template!);
11753
return res;
11854
};
11955
}

0 commit comments

Comments
 (0)