Skip to content

Commit 2e19d3c

Browse files
committed
Skip unchanged files
This feature is key for clients that apply a CS fixer after generation. This can easily save minutes per client generation.
1 parent bfded35 commit 2e19d3c

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/Generator.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,30 @@ public static function generate(Configuration $configuration, string $configurat
7777
$fileName .= (is_string($file->contents) && strpos($file->contents, '<?php') === false ? '' : '.php');
7878
$fileContents = $fileStringyfier->toString($file);
7979
$fileContentsHash = md5($fileContents);
80-
try {
81-
/** @phpstan-ignore-next-line */
82-
@mkdir(dirname($fileName), 0744, true);
83-
} catch (FilesystemException) {
84-
// @ignoreException
80+
81+
if (
82+
! $state->generatedFiles->has($fileName) ||
83+
$state->generatedFiles->get($fileName)->hash !== $fileContentsHash
84+
) {
85+
try {
86+
/** @phpstan-ignore-next-line */
87+
@mkdir(dirname($fileName), 0744, true);
88+
} catch (FilesystemException) {
89+
// @ignoreException
90+
}
91+
92+
file_put_contents($fileName, $fileContents);
93+
$state->generatedFiles->upsert($fileName, $fileContentsHash);
94+
95+
while (! file_exists($fileName) || $fileContentsHash !== md5(file_get_contents($fileName))) {
96+
usleep(100);
97+
}
8598
}
8699

87-
file_put_contents($fileName, $fileContents);
88-
$state->generatedFiles->upsert($fileName, $fileContentsHash);
100+
$existingFiles = array_filter(
101+
$existingFiles,
102+
static fn (string $file): bool => $file !== $fileName,
103+
);
89104

90105
if ($file->loadOnWrite === \OpenAPITools\Utils\File::DO_NOT_LOAD_ON_WRITE) {
91106
continue;

0 commit comments

Comments
 (0)