-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainProj.ts
70 lines (61 loc) · 1.95 KB
/
mainProj.ts
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
import { BaseProj } from "./baseProj";
import { Questions } from "inquirer";
import { unzipPath } from "zip-i";
import { getAllFiles, mkdirs, rmdir } from "fs-i";
import * as path from "path";
import { GlobalData } from "../../../model/globalData";
import { ProjectType, newProjectType } from "../../../model/ProjectType";
import { AngularProj } from "./angularProj";
import { WebpackProj } from "./webpackProj";
import { NodeProj } from "./nodeProj";
import { editFile } from "../../../common/util";
export class MainProj extends BaseProj {
getQuestions() {
let questionList: Questions[] = [
{
name: "projectName",
type: "input",
message: "请输入项目名称",
default: "project1"
},
{
name: "projectType",
type: "list",
message: "请选择项目类型",
default: "node",
choices: ["node", "webpack", "angular"]
}
];
return questionList;
}
async run(projectPath: string) {
let answer = await this.getAnswers();
GlobalData.projectName = answer.projectName;
GlobalData.projectType = newProjectType(answer.projectType);
GlobalData.projectRootPath = path.join(projectPath, answer.projectName);
await mkdirs(GlobalData.projectRootPath);
let nodeProj = new NodeProj();
let angularProj = new AngularProj();
let webpackProj = new WebpackProj();
switch (GlobalData.projectType) {
case ProjectType.node:
await nodeProj.run();
break;
case ProjectType.webpack:
await webpackProj.run();
break;
case ProjectType.angular:
await angularProj.run();
break;
}
await this.replaceProjectName();
}
private async replaceProjectName() {
let files = await getAllFiles(GlobalData.projectRootPath);
for (let file of files) {
await editFile(file, fileContent => {
return fileContent.replace(/{{projectName}}/g, GlobalData.projectName);
});
}
}
}