@@ -19,6 +19,7 @@ class ProjectType(Enum):
19
19
20
20
JAVA = auto ()
21
21
PYTHON = auto ()
22
+ PRETTIER = auto ()
22
23
23
24
24
25
@dataclass
@@ -27,6 +28,8 @@ class Project:
27
28
28
29
path : str
29
30
type : ProjectType
31
+ taskName : str | None = None # Used for prettier projects
32
+ filePattern : str | None = None # Used for prettier projects
30
33
31
34
@property
32
35
def gradle_path (self ) -> str :
@@ -151,8 +154,12 @@ def generate_config(self) -> dict:
151
154
for project in self .projects :
152
155
if project .type == ProjectType .PYTHON :
153
156
hooks .append (self ._generate_lint_fix_hook (project ))
154
- else : # ProjectType.JAVA
157
+ elif project . type == ProjectType .JAVA :
155
158
hooks .append (self ._generate_spotless_hook (project ))
159
+ elif project .type == ProjectType .PRETTIER :
160
+ hooks .append (self ._generate_prettier_hook (project ))
161
+ else :
162
+ print (f"Warning: Unsupported project type { project .type } for { project .path } " )
156
163
157
164
config = {"repos" : [{"repo" : "local" , "hooks" : hooks }]}
158
165
@@ -203,6 +210,17 @@ def _generate_spotless_hook(self, project: Project) -> dict:
203
210
"pass_filenames" : False ,
204
211
}
205
212
213
+ def _generate_prettier_hook (self , project : Project ) -> dict :
214
+ """Generate a prettier hook for projects."""
215
+ return {
216
+ "id" : f"{ project .project_id } -{ project .taskName } " ,
217
+ "name" : f"{ project .taskName } " ,
218
+ "entry" : f"./gradlew { project .gradle_path } :{ project .taskName } " ,
219
+ "language" : "system" ,
220
+ "files" : project .filePattern ,
221
+ "pass_filenames" : False ,
222
+ }
223
+
206
224
207
225
class PrecommitDumper (yaml .Dumper ):
208
226
"""Custom YAML dumper that maintains proper indentation."""
@@ -253,7 +271,21 @@ def main():
253
271
254
272
# Find projects
255
273
finder = ProjectFinder (root_dir )
256
- projects = finder .find_all_projects ()
274
+ prettier_projects = [
275
+ Project (
276
+ path = "datahub-web-react" ,
277
+ type = ProjectType .PRETTIER ,
278
+ taskName = "mdPrettierWriteChanged" ,
279
+ filePattern = "^.*\\ .md$" ,
280
+ ),
281
+ Project (
282
+ path = "datahub-web-react" ,
283
+ type = ProjectType .PRETTIER ,
284
+ taskName = "githubActionsPrettierWriteChanged" ,
285
+ filePattern = "^\\ .github/.*\\ .(yml|yaml)$"
286
+ ),
287
+ ]
288
+ projects = [* prettier_projects , * finder .find_all_projects ()]
257
289
258
290
# Print summary
259
291
print ("Found projects:" )
@@ -276,4 +308,4 @@ def main():
276
308
277
309
278
310
if __name__ == "__main__" :
279
- main ()
311
+ main ()
0 commit comments