Skip to content

Commit 0332bac

Browse files
authored
refactor(tools): allow specifying replacement start/end (renovatebot#41250)
As part of future changes, we need to be able to specify the start/end of replacements in documentation, as we have multiple entries in the same page. We can also rename the variable so it's clearer that it's the default value, not the current scoped value.
1 parent 628f9a2 commit 0332bac

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tools/docs/utils.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { regEx } from '../../lib/util/regex.ts';
44
import { capitalize } from '../../lib/util/string.ts';
55
import { readFile } from '../utils/index.ts';
66

7-
const replaceStart =
7+
const defaultReplaceStart =
88
'<!-- Autogenerate in https://github.com/renovatebot/renovate -->';
9-
const replaceStop = '<!-- Autogenerate end -->';
9+
const defaultReplaceStop = '<!-- Autogenerate end -->';
1010
const goodUrlRegex = regEx(/\[(.+?)\]\((.+?)\)/);
1111

1212
export function formatName(input: string): string {
@@ -31,9 +31,16 @@ export function getNameWithUrl(
3131
return displayName;
3232
}
3333

34-
export function replaceContent(content: string, txt: string): string {
35-
const replaceStartIndex = content.indexOf(replaceStart);
36-
const replaceStopIndex = content.indexOf(replaceStop);
34+
export function replaceContent(
35+
content: string,
36+
txt: string,
37+
opts: {
38+
replaceStart: string;
39+
replaceStop: string;
40+
} = { replaceStart: defaultReplaceStart, replaceStop: defaultReplaceStop },
41+
): string {
42+
const replaceStartIndex = content.indexOf(opts.replaceStart);
43+
const replaceStopIndex = content.indexOf(opts.replaceStop);
3744

3845
if (replaceStartIndex < 0) {
3946
logger.error('Missing replace placeholder');
@@ -42,7 +49,7 @@ export function replaceContent(content: string, txt: string): string {
4249
return (
4350
content.slice(0, replaceStartIndex) +
4451
txt +
45-
content.slice(replaceStopIndex + replaceStop.length)
52+
content.slice(replaceStopIndex + opts.replaceStop.length)
4653
);
4754
}
4855

0 commit comments

Comments
 (0)