-
Notifications
You must be signed in to change notification settings - Fork 247
/
inquire.ts
183 lines (174 loc) · 4.85 KB
/
inquire.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { DistinctQuestion, prompt } from 'inquirer';
import { Runner, TypescriptStarterCLIOptions, validateName } from './utils';
export async function inquire(): Promise<TypescriptStarterCLIOptions> {
const packageNameQuestion: DistinctQuestion = {
filter: (answer: string) => answer.trim(),
message: '📦 Enter the new package name:',
name: 'projectName',
type: 'input',
validate: validateName,
};
enum ProjectType {
Node = 'node',
Library = 'lib',
}
const projectTypeQuestion: DistinctQuestion = {
choices: [
{ name: 'Node.js application', value: ProjectType.Node },
{ name: 'Javascript library', value: ProjectType.Library },
],
message: '🔨 What are you making?',
name: 'type',
type: 'list',
};
const packageDescriptionQuestion: DistinctQuestion = {
filter: (answer: string) => answer.trim(),
message: '💬 Enter the package description:',
name: 'description',
type: 'input',
validate: (answer: string) => answer.length > 0,
};
const runnerQuestion: DistinctQuestion = {
choices: [
{ name: 'npm', value: Runner.Npm },
{ name: 'yarn', value: Runner.Yarn },
],
message: '🚄 Will this project use npm or yarn?',
name: 'runner',
type: 'list',
};
enum TypeDefinitions {
none = 'none',
node = 'node',
dom = 'dom',
nodeAndDom = 'both',
}
const typeDefsQuestion: DistinctQuestion = {
choices: [
{
name: `None — the library won't use any globals or modules from Node.js or the DOM`,
value: TypeDefinitions.none,
},
{
name: `Node.js — parts of the library require access to Node.js globals or built-in modules`,
value: TypeDefinitions.node,
},
{
name: `DOM — parts of the library require access to the Document Object Model (DOM)`,
value: TypeDefinitions.dom,
},
{
name: `Both Node.js and DOM — some parts of the library require Node.js, other parts require DOM access`,
value: TypeDefinitions.nodeAndDom,
},
],
message: '📚 Which global type definitions do you want to include?',
name: 'definitions',
type: 'list',
when: (answers) => answers.type === ProjectType.Library,
};
enum Extras {
appveyor = 'appveyor',
circleci = 'circleci',
cspell = 'cspell',
editorconfig = 'editorconfig',
functional = 'functional',
strict = 'strict',
travis = 'travis',
vscode = 'vscode',
}
const extrasQuestion: DistinctQuestion = {
choices: [
{
name: 'Enable stricter type-checking',
value: Extras.strict,
},
{
checked: true,
name: 'Enable eslint-plugin-functional',
value: Extras.functional,
},
{
checked: true,
name: 'Include .editorconfig',
value: Extras.editorconfig,
},
{
checked: true,
name: 'Include cspell',
value: Extras.cspell,
},
{
checked: true,
name: 'Include VS Code debugging config',
value: Extras.vscode,
},
{
checked: true,
name: 'Include CircleCI config',
value: Extras.circleci,
},
{
checked: false,
name: 'Include Appveyor (Windows-based CI) config',
value: Extras.appveyor,
},
{
checked: false,
name: 'Include Travis CI config',
value: Extras.travis,
},
],
message: '🚀 More fun stuff:',
name: 'extras',
type: 'checkbox',
};
return prompt([
packageNameQuestion,
projectTypeQuestion,
packageDescriptionQuestion,
runnerQuestion,
typeDefsQuestion,
extrasQuestion,
]).then((answers) => {
const {
definitions,
description,
extras,
projectName,
runner,
type,
} = answers as {
readonly definitions?: TypeDefinitions;
readonly description: string;
readonly extras: ReadonlyArray<string>;
readonly projectName: string;
readonly runner: Runner;
readonly type: ProjectType;
};
return {
appveyor: extras.includes(Extras.appveyor),
circleci: extras.includes(Extras.circleci),
cspell: extras.includes(Extras.cspell),
description,
domDefinitions: definitions
? [TypeDefinitions.dom, TypeDefinitions.nodeAndDom].includes(
definitions
)
: false,
editorconfig: extras.includes(Extras.editorconfig),
functional: extras.includes(Extras.functional),
install: true,
nodeDefinitions: definitions
? [TypeDefinitions.node, TypeDefinitions.nodeAndDom].includes(
definitions
)
: type === ProjectType.Node,
projectName,
runner,
strict: extras.includes(Extras.strict),
travis: extras.includes(Extras.travis),
vscode: extras.includes(Extras.vscode),
};
});
}