@@ -8,8 +8,14 @@ import { ContributorSchema as ContributorFunction } from "../contributors/_schem
88import z from "zod" ;
99
1010const TEAM_DIR = path . resolve ( process . cwd ( ) , "contributors" ) ;
11- const PROJECTS_FILE = path . resolve ( process . cwd ( ) , "contributors/_schema/projects.ts" ) ;
12- const SCHEMA_FILE = path . resolve ( process . cwd ( ) , "contributors/_schema/index.ts" ) ;
11+ const PROJECTS_FILE = path . resolve (
12+ process . cwd ( ) ,
13+ "contributors/_schema/projects.ts"
14+ ) ;
15+ const SCHEMA_FILE = path . resolve (
16+ process . cwd ( ) ,
17+ "contributors/_schema/index.ts"
18+ ) ;
1319
1420// Global abort controller to manage running validations
1521let currentValidationController : AbortController | null = null ;
@@ -21,9 +27,9 @@ interface ValidationResult {
2127}
2228
2329class InvalidRoleError extends Error {
24- constructor ( projectName : string , filePath : string ) {
30+ constructor ( roleName : string , projectName : string , filePath : string ) {
2531 super (
26- `Invalid role in project "${ projectName } " for file ./${ path . relative (
32+ `Invalid role ${ roleName } in project "${ projectName } " for file ./${ path . relative (
2733 process . cwd ( ) ,
2834 filePath
2935 ) } .`
@@ -43,7 +49,7 @@ class InvalidProjectError extends Error {
4349}
4450
4551// @ts -expect-error This is fucked up because it's type of image in Astro
46- const Contributor = ContributorFunction ( { image : z . string } )
52+ const Contributor = ContributorFunction ( { image : z . string } ) ;
4753
4854function formatValidationError ( error : any , filePath : string ) : string {
4955 if ( error . code === "unrecognized_keys" ) {
@@ -57,7 +63,11 @@ function formatValidationError(error: any, filePath: string): string {
5763 const path = error . path . join ( "." ) ;
5864 if ( path . includes ( "roles." ) ) {
5965 const projectName = path . split ( "." ) [ 1 ] ;
60- throw new InvalidRoleError ( projectName , filePath ) ;
66+ const roleName = error . unionErrors
67+ // TODO: figure out zod typings
68+ . flatMap ( ( e : any ) => e . issues )
69+ . find ( ( issue : any ) => issue . code == "invalid_enum_value" ) ?. received ;
70+ throw new InvalidRoleError ( roleName , projectName , filePath ) ;
6171 }
6272 }
6373
@@ -149,8 +159,13 @@ function validateAllTeamFiles(signal?: AbortSignal) {
149159 return results ;
150160}
151161
152- function printResults ( results : ValidationResult [ ] ) : void {
153- console . clear ( ) ;
162+ function printResults (
163+ results : ValidationResult [ ] ,
164+ isWatchMode : boolean = false
165+ ) : void {
166+ if ( isWatchMode ) {
167+ console . clear ( ) ;
168+ }
154169 const hasErrors = results . some ( ( r ) => r . errors . length > 0 ) ;
155170
156171 if ( hasErrors ) {
@@ -200,7 +215,9 @@ async function runValidation(isWatchMode: boolean = false) {
200215 const signal = currentValidationController . signal ;
201216
202217 try {
203- console . clear ( ) ;
218+ if ( isWatchMode ) {
219+ console . clear ( ) ;
220+ }
204221 console . log ( "Running validation..." ) ;
205222
206223 // Needs to wait or it's not clear anything is happening
0 commit comments