-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathquestions.ts
125 lines (114 loc) · 3.29 KB
/
questions.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
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
122
123
124
125
import path = require("path");
interface IQuestionType {
message: string;
name: string;
type: string;
validate?: (value: string) => string|boolean;
default?: () => string;
}
const startUrlQuestion: IQuestionType = {
default: () => "/",
message: "Enter startURL for your application: ",
name: "startURL",
type: "input",
};
const entryQuestion: IQuestionType = {
default: () => "'./index.js'",
message: "Which file would be the first to enter the application?",
name: "entryFile",
type: "input",
validate: (value: string) => {
const pattern = /[^\s]*.js/i;
if (pattern.test(value)) {
return true;
} else {
return "Invalid path or file.";
}
},
};
const nameQuestion: IQuestionType = {
default: () => process.cwd().split(path.sep)
.pop(),
message: "Let's create one. What is the name of your application?",
name: "name",
type: "input",
validate: (value: string) => {
if (value.length <= 45) {
return true;
} else {
return "Name is too long. Please enter a shorter name (less than 45 characters)";
}
},
};
const shortNameQuestion: IQuestionType = {
default: () => process.cwd().split(path.sep)
.pop(),
message: "Enter a short name for your application",
name: "shortName",
type: "input",
validate: (value: string) => {
if (value.length <= 12) {
return true;
} else {
return "Short Name is too long. Please enter a shorter name (less than 12 characters)";
}
},
};
const descriptionQuestion: IQuestionType = {
message: "Enter description of you application: ",
name: "description",
type: "input",
};
const homePageQuestion: IQuestionType = {
default: () => "index.html",
message: "What is the name of the home page of your application?",
name: "homePage",
type: "input",
};
const themeColorQuestion: IQuestionType = {
default: () => "#ffffff",
message: "Please enter the theme color of your application.",
name: "themeColor",
type: "input",
validate: (value: string) => {
const pattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/i;
if (pattern.test(value)) {
return true;
} else {
return "Invalid Hex color code. A valid color looks like #de54ef or #abc";
}
},
};
const faviconQuestion: IQuestionType = {
message: "Enter path to your logo (in .svg or .png): ",
name: "favPath",
type: "input",
validate: function validate(value: string) {
if (this.fs.exists(value)) {
if (value.endsWith(".png") || value.endsWith(".svg")) {
return true;
} else {
return "Favicon can be in .svg or .png only";
}
} else {
return "Given file doesn't exists.";
}
},
};
const outputDirQuestion: IQuestionType = {
default: () => "./dist",
message: "Enter the path to directory where you would like to generate builds: ",
name: "outputDir",
type: "input",
};
export default {
descriptionQuestion,
entryQuestion,
faviconQuestion,
homePageQuestion,
nameQuestion,
outputDirQuestion,
shortNameQuestion,
startUrlQuestion,
themeColorQuestion,
};