-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes: - made the script asynchronous in nature as suggested by Sergio to make it's performance more better - applied suggestion from here: https://github.com/asyncapi/spec/pull/1046/files#r1535471235
- Loading branch information
1 parent
d2e81b1
commit baa7c12
Showing
1 changed file
with
26 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,43 @@ | ||
const { execSync } = require('child_process'); | ||
const { promisify } = require('util'); | ||
const exec = promisify(require('child_process').exec); | ||
const glob = require('glob'); | ||
|
||
// Use glob to find all YAML files in the examples directory | ||
const files = glob.sync('./examples/**/*.{yml,yaml}'); | ||
|
||
let filesCount = 0; | ||
let filesCount = files.length; | ||
let errorFilesCount = 0; | ||
let filesWithErrors = []; // Array to store files that failed validation | ||
// Validate each file using AsyncAPI CLI | ||
files.forEach((file) => { | ||
filesCount++; | ||
|
||
// Function to validate a single file asynchronously | ||
async function validateFile(file) { | ||
try { | ||
console.log(`\nValidating: ${file}`); | ||
execSync(`npx asyncapi validate ${file}`, { stdio: 'inherit' }); | ||
await exec(`npx asyncapi validate ${file}`); | ||
console.log(`Validation successful for: ${file}\n`); | ||
} catch (error) { | ||
console.error(`Validation failed for: ${file}\n`); | ||
errorFilesCount++; | ||
filesWithErrors.push(file); | ||
} | ||
} | ||
|
||
}); | ||
// Run validation for all files asynchronously | ||
(async () => { | ||
await Promise.all(files.map(validateFile)); | ||
|
||
console.log(`\n\nValidation Completed!\nTotal files validated = ${filesCount}\nTotal files having error = ${errorFilesCount}`) | ||
// Output validation result | ||
console.log(`\n\nValidation Completed!\nTotal files validated = ${filesCount}\nTotal files having error = ${errorFilesCount}`); | ||
|
||
// Display files with errors | ||
if (filesWithErrors.length > 0) { | ||
console.log('\nFiles with validation errors:'); | ||
filesWithErrors.forEach((file) => { | ||
console.log(file); | ||
}); | ||
process.exit(1); | ||
} else { | ||
console.log('\nAll files validated successfully.'); | ||
} | ||
// Display files with errors | ||
if (filesWithErrors.length > 0) { | ||
console.log('\nFiles with validation errors:'); | ||
filesWithErrors.forEach((file) => { | ||
console.log(file); | ||
}); | ||
process.exit(1); | ||
} else { | ||
console.log('\nAll files validated successfully.'); | ||
process.exit(0); | ||
} | ||
})(); |