Skip to content

Commit 7de5243

Browse files
chore: update for 2.3.7 #1848 (#1851)
1 parent b674a42 commit 7de5243

File tree

3 files changed

+391
-60
lines changed

3 files changed

+391
-60
lines changed

_includes/renderCommand.tsx

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -52,56 +52,60 @@ export default function renderCommand(
5252

5353
const toc: TableOfContentsItem_[] = [];
5454

55-
let about = command.about!.replaceAll(
56-
SUBSEQUENT_ENCAPSULATED_ANSI_RE,
57-
function (
58-
_,
59-
_opening1,
60-
text1,
61-
_closing1,
62-
space,
63-
opening2,
64-
text2,
65-
closing2,
66-
) {
67-
return `${opening2}${text1}${space}${text2}${closing2}`;
68-
},
69-
).replaceAll(SUBSEQUENT_ANSI_RE, "");
70-
let aboutLines = about.split("\n");
71-
const aboutLinesReadMoreIndex = aboutLines.findLastIndex((line) =>
72-
line.toLowerCase().replaceAll(ANSI_RE, "").trim().startsWith("read more:")
73-
);
74-
if (aboutLinesReadMoreIndex !== -1) {
75-
aboutLines = aboutLines.slice(0, aboutLinesReadMoreIndex);
76-
}
77-
78-
about = aboutLines.join("\n").replaceAll(
79-
ENCAPSULATED_ANSI_RE,
80-
(_, opening, text, _closing, offset, string) => {
81-
if (opening === "\u001b[32m") { // green, used as heading
82-
return `### ${text}`;
83-
} else if (
84-
opening === "\u001b[38;5;245m" || opening === "\u001b[36m" ||
85-
opening === "\u001b[1m" || opening === "\u001b[22m"
86-
) { // gray and cyan used for code and snippets, and we treat yellow and bold as well as such
87-
const lines = string.split("\n");
88-
let line = "";
89-
90-
while (offset > 0) {
91-
line = lines.shift();
92-
offset -= line.length + 1;
93-
}
55+
// Add null check for command.about
56+
let about = "";
57+
if (command.about) {
58+
about = command.about.replaceAll(
59+
SUBSEQUENT_ENCAPSULATED_ANSI_RE,
60+
function (
61+
_,
62+
_opening1,
63+
text1,
64+
_closing1,
65+
space,
66+
opening2,
67+
text2,
68+
closing2,
69+
) {
70+
return `${opening2}${text1}${space}${text2}${closing2}`;
71+
},
72+
).replaceAll(SUBSEQUENT_ANSI_RE, "");
73+
let aboutLines = about.split("\n");
74+
const aboutLinesReadMoreIndex = aboutLines.findLastIndex((line) =>
75+
line.toLowerCase().replaceAll(ANSI_RE, "").trim().startsWith("read more:")
76+
);
77+
if (aboutLinesReadMoreIndex !== -1) {
78+
aboutLines = aboutLines.slice(0, aboutLinesReadMoreIndex);
79+
}
9480

95-
if (START_AND_END_ANSI_RE.test(line.trim())) {
96-
return "\n```\n" + text + "\n```\n\n";
81+
about = aboutLines.join("\n").replaceAll(
82+
ENCAPSULATED_ANSI_RE,
83+
(_, opening, text, _closing, offset, string) => {
84+
if (opening === "\u001b[32m") { // green, used as heading
85+
return `### ${text}`;
86+
} else if (
87+
opening === "\u001b[38;5;245m" || opening === "\u001b[36m" ||
88+
opening === "\u001b[1m" || opening === "\u001b[22m"
89+
) { // gray and cyan used for code and snippets, and we treat yellow and bold as well as such
90+
const lines = string.split("\n");
91+
let line = "";
92+
93+
while (offset > 0) {
94+
line = lines.shift();
95+
offset -= line.length + 1;
96+
}
97+
98+
if (START_AND_END_ANSI_RE.test(line.trim())) {
99+
return "\n```\n" + text + "\n```\n\n";
100+
} else {
101+
return "`" + text + "`";
102+
}
97103
} else {
98-
return "`" + text + "`";
104+
return text;
99105
}
100-
} else {
101-
return text;
102-
}
103-
},
104-
);
106+
},
107+
);
108+
}
105109

106110
const args = [];
107111
const options: Record<string, ArgType[]> = {};
@@ -171,16 +175,19 @@ function renderOption(group: string, arg: ArgType, helpers: Lume.Helpers) {
171175
const id = `${group}-${arg.name}`;
172176

173177
let docsLink = null;
174-
let help = arg.help.replaceAll(ANSI_RE, "");
175-
const helpLines = help.split("\n");
176-
const helpLinesDocsIndex = helpLines.findLastIndex((line) =>
177-
line.toLowerCase()
178-
.trim()
179-
.startsWith("docs:")
180-
);
181-
if (helpLinesDocsIndex !== -1) {
182-
help = helpLines.slice(0, helpLinesDocsIndex).join("\n");
183-
docsLink = helpLines[helpLinesDocsIndex].trim().slice("docs:".length);
178+
// Add null check for arg.help
179+
let help = arg.help ? arg.help.replaceAll(ANSI_RE, "") : "";
180+
if (help) {
181+
const helpLines = help.split("\n");
182+
const helpLinesDocsIndex = helpLines.findLastIndex((line) =>
183+
line.toLowerCase()
184+
.trim()
185+
.startsWith("docs:")
186+
);
187+
if (helpLinesDocsIndex !== -1) {
188+
help = helpLines.slice(0, helpLinesDocsIndex).join("\n");
189+
docsLink = helpLines[helpLinesDocsIndex].trim().slice("docs:".length);
190+
}
184191
}
185192

186193
return (

replacements.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"CLI_VERSION": "2.3.6"
2+
"CLI_VERSION": "2.3.7"
33
}

0 commit comments

Comments
 (0)