Skip to content

Commit 90cc66b

Browse files
Copilothotlong
andcommitted
Optimize validation script with concurrent file processing
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 6be7646 commit 90cc66b

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed

scripts/validate-yaml.js

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,40 +60,58 @@ let errorCount = 0;
6060

6161
console.log('🔍 Validating ObjectQL metadata YAML files...\n');
6262

63-
// Find and validate all metadata files
63+
// Find all metadata files
6464
const files = findFiles(process.cwd());
6565

6666
if (files.length === 0) {
6767
console.log('ℹ️ No metadata files found to validate.');
6868
process.exit(0);
6969
}
7070

71-
files.forEach(file => {
72-
try {
73-
const content = fs.readFileSync(file, 'utf8');
74-
yaml.load(content);
75-
console.log(`✓ ${path.relative(process.cwd(), file)}`);
76-
validCount++;
77-
} catch (error) {
78-
console.error(`✗ ${path.relative(process.cwd(), file)}`);
79-
console.error(` Error: ${error.message}`);
80-
if (error.mark) {
81-
console.error(` Line ${error.mark.line + 1}, Column ${error.mark.column + 1}`);
71+
// Validate all files concurrently
72+
async function validateFiles() {
73+
const results = await Promise.allSettled(
74+
files.map(async (file) => {
75+
const content = await fs.promises.readFile(file, 'utf8');
76+
yaml.load(content);
77+
return file;
78+
})
79+
);
80+
81+
results.forEach((result, index) => {
82+
const file = files[index];
83+
const relativePath = path.relative(process.cwd(), file);
84+
85+
if (result.status === 'fulfilled') {
86+
console.log(`✓ ${relativePath}`);
87+
validCount++;
88+
} else {
89+
const error = result.reason;
90+
console.error(`✗ ${relativePath}`);
91+
console.error(` Error: ${error.message}`);
92+
if (error.mark) {
93+
console.error(` Line ${error.mark.line + 1}, Column ${error.mark.column + 1}`);
94+
}
95+
console.error('');
96+
hasErrors = true;
97+
errorCount++;
8298
}
83-
console.error('');
84-
hasErrors = true;
85-
errorCount++;
99+
});
100+
101+
// Print summary
102+
console.log('\n' + '='.repeat(60));
103+
if (hasErrors) {
104+
console.error(`❌ Validation failed: ${errorCount} error(s) found`);
105+
console.log(`✓ Valid files: ${validCount}`);
106+
console.error(`✗ Invalid files: ${errorCount}`);
107+
process.exit(1);
108+
} else {
109+
console.log(`✅ All ${validCount} YAML metadata file(s) are valid!`);
110+
process.exit(0);
86111
}
87-
});
112+
}
88113

89-
// Print summary
90-
console.log('\n' + '='.repeat(60));
91-
if (hasErrors) {
92-
console.error(`❌ Validation failed: ${errorCount} error(s) found`);
93-
console.log(`✓ Valid files: ${validCount}`);
94-
console.error(`✗ Invalid files: ${errorCount}`);
114+
validateFiles().catch((error) => {
115+
console.error('Unexpected error during validation:', error);
95116
process.exit(1);
96-
} else {
97-
console.log(`✅ All ${validCount} YAML metadata file(s) are valid!`);
98-
process.exit(0);
99-
}
117+
});

0 commit comments

Comments
 (0)