xref: /expo/tools/src/versioning/android/utils.ts (revision ca5a2fa2)
1export function deleteLinesBetweenTags(
2  startRegex: RegExp | string,
3  endRegex: RegExp | string,
4  fileContent: string
5): string {
6  const lines = fileContent.split(/\r?\n/);
7  let insideTags = 0;
8  const filteredLines = lines.filter((line) => {
9    if (line.match(startRegex)) {
10      insideTags += 1;
11    }
12
13    const shouldDelete = insideTags > 0;
14
15    if (line.match(endRegex)) {
16      insideTags -= 1;
17    }
18    return !shouldDelete;
19  });
20  return filteredLines.join('\n');
21}
22