Skip to content

Commit e68a0cb

Browse files
authored
Merge pull request #11 from ensi-platform/fix_ignore_files
Fix ignore files
2 parents 6846dce + 61592e3 commit e68a0cb

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/Commands/GenerateClient.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,35 +150,41 @@ protected function externalTemplatePath(string $path): ?string
150150
return $resultPath;
151151
}
152152

153-
private function recursiveClearDirectory(string $dir, int $level = 0)
153+
private function recursiveClearDirectory(string $dir, int $level = 0, string $baseDir = ''): bool
154154
{
155155
if (!$dir) {
156-
return;
156+
return true;
157157
}
158158

159159
if ($level === 0 && !is_dir($dir)) {
160160
mkdir($dir, 0755, true);
161161
}
162162

163+
$disableDeleteDir = false;
163164
foreach (scandir($dir) as $fileWithoutDir) {
164165
if (in_array($fileWithoutDir, ['..', '.'])) {
165166
continue;
166167
}
167168
$file = $dir . "/" . $fileWithoutDir;
169+
$pathFromBase = $baseDir ? $baseDir . '/' . $fileWithoutDir : $fileWithoutDir;
170+
171+
if (in_array($pathFromBase, $this->filesToIgnoreDuringCleanup)) {
172+
$disableDeleteDir = true;
168173

169-
if ($level === 0 && in_array($fileWithoutDir, $this->filesToIgnoreDuringCleanup)) {
170174
continue;
171175
}
172176

173177
if (is_dir($file)) {
174-
$this->recursiveClearDirectory($file, $level + 1);
178+
$disableDeleteDir = $this->recursiveClearDirectory($file, $level + 1, $pathFromBase) || $disableDeleteDir;
175179
} else {
176180
unlink($file);
177181
}
178182
}
179183

180-
if ($level > 0) {
184+
if ($level > 0 && !$disableDeleteDir) {
181185
rmdir($dir);
182186
}
187+
188+
return $disableDeleteDir;
183189
}
184190
}

src/Commands/GeneratePhpClient.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,18 @@ private function patchEnums(): void
7676
RegexIterator::MATCH
7777
);
7878

79+
$filesOrFoldersToIgnore = array_map(
80+
fn ($fileOfFolder) => $this->outputDir . '/' . $fileOfFolder,
81+
$this->filesToIgnoreDuringCleanup
82+
);
83+
7984
foreach ($files as $file) {
85+
foreach ($filesOrFoldersToIgnore as $fileOrFolderToIgnore) {
86+
if (str_contains($file, $fileOrFolderToIgnore)) {
87+
continue 2;
88+
}
89+
}
90+
8091
try {
8192
$patcher = new PhpEnumPatcher($file);
8293
$patcher->patch();

0 commit comments

Comments
 (0)