File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,13 @@ return [
45
45
* extension to use for the enum files
46
46
*/
47
47
'enum_extension' => '.d.ts',
48
+
49
+
50
+ /*
51
+ * Enable File hash check
52
+ * - adds a hash check to determine if a file has changed to speed up performance
53
+ */
54
+ 'enable_file_hash_check' => true,
48
55
];
49
56
```
50
57
Original file line number Diff line number Diff line change 13
13
* extension to use for the enum files
14
14
*/
15
15
'enum_extension ' => '.d.ts ' ,
16
+
17
+ /*
18
+ * Enable File hash check
19
+ * - adds a hash check to determine if a file has changed to speed up performance
20
+ */
21
+ 'enable_file_hash_check ' => true ,
16
22
];
Original file line number Diff line number Diff line change 3
3
namespace GearboxSolutions \EnumConvertor \Commands ;
4
4
5
5
use Illuminate \Console \Command ;
6
+ use Illuminate \Support \Facades \Cache ;
6
7
use Illuminate \Support \Facades \File ;
7
8
use Illuminate \Support \Str ;
8
9
@@ -19,6 +20,10 @@ public function handle(): int
19
20
$ files = File::allFiles (base_path ($ path ));
20
21
21
22
collect ($ files )->each (function ($ file ) use ($ outputPath ) {
23
+ if (!$ this ->hasFileChanged ($ file )) {
24
+ return ;
25
+ }
26
+
22
27
$ class = Str::of ($ file )->replace ('.php ' , '' )
23
28
->replace (base_path (), '' )
24
29
->explode ('/ ' )
@@ -87,4 +92,24 @@ private function convertValue($item)
87
92
default => $ item ,
88
93
};
89
94
}
95
+
96
+ private function hasFileChanged ($ file ) {
97
+ if (!config ('enum-convertor-laravel.enable_file_hash_check ' , false )) {
98
+ return true ;
99
+ }
100
+
101
+ $ fileHash = hash_file ('sha256 ' , $ file ->getPathname ());
102
+
103
+ $ cacheKey = 'enum-convertor- ' . hash ('sha256 ' , $ file ->getPathname ());
104
+
105
+ $ previousHash = Cache::get ($ cacheKey , '' );
106
+
107
+ if ($ fileHash !== $ previousHash ) {
108
+ Cache::put ($ cacheKey , $ fileHash );
109
+
110
+ return true ;
111
+ }
112
+
113
+ return false ;
114
+ }
90
115
}
You can’t perform that action at this time.
0 commit comments