Skip to content

Commit 22b4f10

Browse files
committed
add depth
1 parent 5f92e79 commit 22b4f10

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/removeInternalOas.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ import { PRODUCTION_API_PATH } from "./lib/config";
1212
/**
1313
* Recursively removes all files ending in '-internal.yaml' from a directory and its subdirectories
1414
* @param directoryPath - The path to the directory to process
15+
* @param depth - The depth of the directory to process, we limit the depth to 3 to avoid infinite recursion
1516
*/
16-
export function removeInternalOas(directoryPath: string): void {
17+
export function removeInternalOas(directoryPath: string, depth = 0): void {
18+
if (depth > 3) {
19+
console.warn(
20+
`Reached maximum depth (${depth}) for directory: ${directoryPath}`
21+
);
22+
return;
23+
}
24+
1725
if (!fs.existsSync(directoryPath)) {
1826
console.warn(`Directory does not exist: ${directoryPath}`);
1927
return;
@@ -27,7 +35,7 @@ export function removeInternalOas(directoryPath: string): void {
2735

2836
if (stat.isDirectory()) {
2937
// Recursively process subdirectories
30-
removeInternalOas(fullPath);
38+
removeInternalOas(fullPath, depth + 1);
3139
} else if (stat.isFile() && item.endsWith("-internal.yaml")) {
3240
// Remove internal files
3341
fs.removeSync(fullPath);

0 commit comments

Comments
 (0)