forked from JoshuaKGoldberg/create-typescript-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp.ts
182 lines (156 loc) · 3.87 KB
/
help.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
import chalk from "chalk";
import { logPipelessLine } from "../shared/cli/lines.js";
import { allArgOptions } from "../shared/options/args.js";
interface HelpTextSection {
sectionHeading: string;
subsections: {
flags: Flag[];
subheading: string | undefined;
warning: string | undefined;
}[];
}
interface Flag {
description: string;
flag: string;
type: string;
}
interface Option {
description: string;
docsSection: string;
type: string;
}
function logHelpTextSection(section: HelpTextSection): void {
logPipelessLine();
logPipelessLine(` ${chalk.black.bgGreenBright(section.sectionHeading)}`);
for (const subsection of section.subsections) {
if (typeof subsection.warning === "string") {
logPipelessLine(chalk.yellow(subsection.warning));
}
if (typeof subsection.subheading === "string") {
logPipelessLine(chalk.green(subsection.subheading));
}
for (const option of subsection.flags) {
const { description, flag, type } = option;
logPipelessLine(
chalk.cyan(
`
--${flag}${
type !== "boolean" ? ` (${chalk.cyanBright(type)})` : ""
}: ${description}`,
),
);
}
}
}
function createHelpTextSections(options: object): HelpTextSection[] {
const helpTextSections: HelpTextSection[] = [];
const core: HelpTextSection = {
sectionHeading: "Core options:",
subsections: [
{
flags: [],
subheading: undefined,
warning: undefined,
},
],
};
const optional: HelpTextSection = {
sectionHeading: "Optional options:",
subsections: [
{
flags: [],
subheading: undefined,
warning: undefined,
},
],
};
const optOut: HelpTextSection = {
sectionHeading: "Opt-outs:",
subsections: [
{
flags: [],
subheading: undefined,
warning: `
⚠️ Warning: Specifying any --exclude-* flag on the command-line will
cause the setup script to skip prompting for more excludes. ⚠️`,
},
{
flags: [
{
description: `Skips network calls that fetch all-contributors
data from GitHub`,
flag: "exclude-contributors",
type: "boolean",
},
],
subheading: `
You can prevent the migration script from making some network-based
changes using any or all of the following CLI flags:`,
warning: undefined,
},
{
flags: [],
subheading: `
You can prevent the migration script from making some changes on disk
using any or all of the following CLI flags:`,
warning: undefined,
},
],
};
for (const option of Object.keys(options)) {
const data = options[option as keyof object] as unknown as Option;
if (data.docsSection === "core") {
core.subsections[0].flags.push({
description: data.description,
flag: option,
type: data.type,
});
}
if (data.docsSection === "optional") {
optional.subsections[0].flags.push({
description: data.description,
flag: option,
type: data.type,
});
}
if (data.docsSection === "opt-out") {
optOut.subsections[0].flags.push({
description: data.description,
flag: option,
type: data.type,
});
}
if (data.docsSection === "skip-net") {
optOut.subsections[1].flags.push({
description: data.description,
flag: option,
type: data.type,
});
}
if (data.docsSection === "skip-disk") {
optOut.subsections[2].flags.push({
description: data.description,
flag: option,
type: data.type,
});
}
}
helpTextSections.push(core, optional, optOut);
return helpTextSections;
}
export function logHelpText(): void {
const helpTextSections = createHelpTextSections(allArgOptions);
logPipelessLine();
logPipelessLine(
chalk.cyan(
`
A quickstart-friendly TypeScript template with comprehensive formatting,
linting, releases, testing, and other great tooling built-in.
`,
),
);
for (const section of helpTextSections) {
logHelpTextSection(section);
logPipelessLine();
}
}