-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPromptSession.ts
More file actions
121 lines (108 loc) · 3.93 KB
/
PromptSession.ts
File metadata and controls
121 lines (108 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import {
BasePromptSession, GoogleAnalytics, InquirerWrapper, PackageManager, ProjectConfig,
ProjectLibrary, PromptTaskContext, Task, Util
} from "@igniteui/cli-core";
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 {
constructor(templateManager: TemplateManager) {
super(templateManager);
}
public static async chooseTerm() {
const answer = await InquirerWrapper.input({
default: null,
message: "Enter a search term",
});
if (answer) {
return answer;
} else {
const retProm = await this.chooseTerm();
return retProm;
}
}
/**
* Start questions session for project creation
*/
public async start() {
GoogleAnalytics.post({
t: "screenview",
cd: "Wizard"
});
let projLibrary: ProjectLibrary;
let theme: string;
add.templateManager = this.templateManager as TemplateManager;
this.config = ProjectConfig.getConfig();
const defaultProjName = "IG Project";
if (ProjectConfig.hasLocalConfig() && !this.config.project.isShowcase) {
projLibrary = this.templateManager.getProjectLibrary(this.config.project.framework, this.config.project.projectType);
theme = this.config.project.theme;
} else {
Util.log(""); /* new line */
const projectName = await this.getUserInput({
type: "input",
name: "projectName",
message: "Enter a name for your project:",
default: Util.getAvailableName(defaultProjName, true),
choices: null,
validate: this.nameIsValid
});
const frameRes: string = await this.getUserInput({
type: "list",
name: "framework",
message: "Choose framework:",
choices: this.getFrameworkNames(),
default: "jQuery"
});
const framework = this.templateManager.getFrameworkByName(frameRes);
// app name validation???
projLibrary = await this.getProjectLibrary(framework);
if (frameRes === "Angular" && projLibrary.projectType === "igx-ts") {
Util.log("Psst! Did you know you can also use our schematics package with Angular CLI to create and modify your projects?", "yellow");
Util.log("Read more at: https://www.infragistics.com/products/ignite-ui-angular/angular/components/general/cli-overview", "yellow");
}
const projTemplate = await this.getProjectTemplate(projLibrary);
// project options:
theme = await this.getTheme(projLibrary);
Util.log(" Generating project structure.");
const config = projTemplate.generateConfig(projectName, theme);
for (const templatePath of projTemplate.templatePaths) {
await Util.processTemplates(templatePath, path.join(process.cwd(), projectName),
config, projTemplate.delimiters, false);
}
Util.log(Util.greenCheck() + " Project structure generated.");
if (!this.config.skipGit) {
Util.gitInit(process.cwd(), projectName);
}
// move cwd to project folder
process.chdir(projectName);
}
await this.chooseActionLoop(projLibrary);
//TODO: restore cwd?
}
protected async completeAndRun(port?: number) {
await PackageManager.flushQueue(true);
await start.start({ port });
}
protected async upgradePackages() {
upgrade.templateManager = this.templateManager as TemplateManager;
await upgrade.upgrade({ skipInstall: true, _: ["upgrade"], $0: "upgrade" });
}
/**
* Get user name and set template's extra configurations if any
* @param projectLibrary to add component to
* @param component to get template for
*/
protected templateSelectedTask(type: "component" | "view" = "component"): Task<PromptTaskContext> {
return async (_runner, context) => {
const name = await this.chooseTemplateName(context.template, type);
if (context.template.hasExtraConfiguration) {
await this.customizeTemplateTask(context.template);
}
const res = await add.addTemplate(name, context.template);
return res;
};
}
}