Skip to content

Commit 09b6482

Browse files
committed
refactor(prompt): drop duplicate start override for one log, cleanup
1 parent 26d958b commit 09b6482

1 file changed

Lines changed: 17 additions & 82 deletions

File tree

packages/cli/lib/PromptSession.ts

Lines changed: 17 additions & 82 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";
@@ -15,112 +15,47 @@ export class PromptSession extends BasePromptSession {
1515
super(templateManager);
1616
}
1717

18-
public static async chooseTerm() {
18+
public static async chooseTerm(): Promise<string> {
1919
const answer = await InquirerWrapper.input({
20-
default: null,
2120
message: "Enter a search term",
2221
});
2322
if (answer) {
2423
return answer;
2524
} else {
26-
const retProm = await this.chooseTerm();
27-
return retProm;
25+
return this.chooseTerm();
2826
}
2927
}
3028

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

98-
protected async completeAndRun(port?: number) {
38+
protected override async completeAndRun(port?: number) {
9939
await PackageManager.flushQueue(true);
10040
await start.start({ port });
10141
}
10242

103-
protected async upgradePackages() {
43+
protected override async upgradePackages() {
10444
upgrade.templateManager = this.templateManager as TemplateManager;
10545
await upgrade.upgrade({ skipInstall: true, _: ["upgrade"], $0: "upgrade" });
10646
}
10747

108-
protected async configureAI(): Promise<void> {
48+
protected override async configureAI(): Promise<void> {
10949
await aiConfigure();
11050
}
11151

112-
/**
113-
* Get user name and set template's extra configurations if any
114-
* @param projectLibrary to add component to
115-
* @param component to get template for
116-
*/
117-
protected templateSelectedTask(type: "component" | "view" = "component"): Task<PromptTaskContext> {
52+
protected override templateSelectedTask(type: "component" | "view" = "component"): Task<PromptTaskContext> {
11853
return async (_runner, context) => {
119-
const name = await this.chooseTemplateName(context.template, type);
120-
if (context.template.hasExtraConfiguration) {
121-
await this.customizeTemplateTask(context.template);
54+
const name = await this.chooseTemplateName(context.template!, type);
55+
if (context.template!.hasExtraConfiguration) {
56+
await this.customizeTemplateTask(context.template!);
12257
}
123-
const res = await add.addTemplate(name, context.template);
58+
const res = await add.addTemplate(name, context.template!);
12459
return res;
12560
};
12661
}

0 commit comments

Comments
 (0)