Skip to content

Commit

Permalink
Merge pull request #11 from ensi-platform/fix_ignore_files
Browse files Browse the repository at this point in the history
Fix ignore files
  • Loading branch information
MsNatali authored Oct 9, 2023
2 parents 6846dce + 61592e3 commit e68a0cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Commands/GenerateClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,35 +150,41 @@ protected function externalTemplatePath(string $path): ?string
return $resultPath;
}

private function recursiveClearDirectory(string $dir, int $level = 0)
private function recursiveClearDirectory(string $dir, int $level = 0, string $baseDir = ''): bool
{
if (!$dir) {
return;
return true;
}

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

$disableDeleteDir = false;
foreach (scandir($dir) as $fileWithoutDir) {
if (in_array($fileWithoutDir, ['..', '.'])) {
continue;
}
$file = $dir . "/" . $fileWithoutDir;
$pathFromBase = $baseDir ? $baseDir . '/' . $fileWithoutDir : $fileWithoutDir;

if (in_array($pathFromBase, $this->filesToIgnoreDuringCleanup)) {
$disableDeleteDir = true;

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

if (is_dir($file)) {
$this->recursiveClearDirectory($file, $level + 1);
$disableDeleteDir = $this->recursiveClearDirectory($file, $level + 1, $pathFromBase) || $disableDeleteDir;
} else {
unlink($file);
}
}

if ($level > 0) {
if ($level > 0 && !$disableDeleteDir) {
rmdir($dir);
}

return $disableDeleteDir;
}
}
11 changes: 11 additions & 0 deletions src/Commands/GeneratePhpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,18 @@ private function patchEnums(): void
RegexIterator::MATCH
);

$filesOrFoldersToIgnore = array_map(
fn ($fileOfFolder) => $this->outputDir . '/' . $fileOfFolder,
$this->filesToIgnoreDuringCleanup
);

foreach ($files as $file) {
foreach ($filesOrFoldersToIgnore as $fileOrFolderToIgnore) {
if (str_contains($file, $fileOrFolderToIgnore)) {
continue 2;
}
}

try {
$patcher = new PhpEnumPatcher($file);
$patcher->patch();
Expand Down

0 comments on commit e68a0cb

Please sign in to comment.