1
- const { execSync } = require ( 'child_process' ) ;
1
+ const { promisify } = require ( 'util' ) ;
2
+ const exec = promisify ( require ( 'child_process' ) . exec ) ;
2
3
const glob = require ( 'glob' ) ;
3
4
4
5
// Use glob to find all YAML files in the examples directory
5
6
const files = glob . sync ( './examples/**/*.{yml,yaml}' ) ;
6
7
7
- let filesCount = 0 ;
8
+ let filesCount = files . length ;
8
9
let errorFilesCount = 0 ;
9
10
let filesWithErrors = [ ] ; // Array to store files that failed validation
10
- // Validate each file using AsyncAPI CLI
11
- files . forEach ( ( file ) => {
12
- filesCount ++ ;
11
+
12
+ // Function to validate a single file asynchronously
13
+ async function validateFile ( file ) {
13
14
try {
14
15
console . log ( `\nValidating: ${ file } ` ) ;
15
- execSync ( `npx asyncapi validate ${ file } ` , { stdio : 'inherit' } ) ;
16
+ await exec ( `npx asyncapi validate ${ file } ` ) ;
17
+ console . log ( `Validation successful for: ${ file } \n` ) ;
16
18
} catch ( error ) {
17
19
console . error ( `Validation failed for: ${ file } \n` ) ;
18
20
errorFilesCount ++ ;
19
21
filesWithErrors . push ( file ) ;
20
22
}
23
+ }
21
24
22
- } ) ;
25
+ // Run validation for all files asynchronously
26
+ ( async ( ) => {
27
+ await Promise . all ( files . map ( validateFile ) ) ;
23
28
24
- console . log ( `\n\nValidation Completed!\nTotal files validated = ${ filesCount } \nTotal files having error = ${ errorFilesCount } ` )
29
+ // Output validation result
30
+ console . log ( `\n\nValidation Completed!\nTotal files validated = ${ filesCount } \nTotal files having error = ${ errorFilesCount } ` ) ;
25
31
26
- // Display files with errors
27
- if ( filesWithErrors . length > 0 ) {
28
- console . log ( '\nFiles with validation errors:' ) ;
29
- filesWithErrors . forEach ( ( file ) => {
30
- console . log ( file ) ;
31
- } ) ;
32
- process . exit ( 1 ) ;
33
- } else {
34
- console . log ( '\nAll files validated successfully.' ) ;
35
- }
32
+ // Display files with errors
33
+ if ( filesWithErrors . length > 0 ) {
34
+ console . log ( '\nFiles with validation errors:' ) ;
35
+ filesWithErrors . forEach ( ( file ) => {
36
+ console . log ( file ) ;
37
+ } ) ;
38
+ process . exit ( 1 ) ;
39
+ } else {
40
+ console . log ( '\nAll files validated successfully.' ) ;
41
+ process . exit ( 0 ) ;
42
+ }
43
+ } ) ( ) ;
0 commit comments