-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
37 lines (31 loc) · 1.11 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import fs from 'fs';
import path from 'path';
import { Document, Spectral, Ruleset } from "@stoplight/spectral-core";
import * as Parsers from '@stoplight/spectral-parsers';
import { oas } from "@stoplight/spectral-rulesets";
import { printMemoryUsage } from './monitor_memory.js';
import logUpdate from 'log-update';
const ruleset = new Ruleset({
extends: [oas],
rules: {},
});
const spectral = new Spectral();
spectral.setRuleset(ruleset);
const documentsFolder = path.join(__dirname, '_documents');
fs.readdir(documentsFolder, async (err, files) => {
if (err) {
console.error('Error reading documents folder:', err);
return;
}
const numberOfDocuments = files.length;
let documentCounter = 0;
for (const file of files) {
const filePath = path.join(documentsFolder, file);
const document = new Document(fs.readFileSync(filePath, "utf8"), Parsers.Json, filePath);
await spectral.run(document);
documentCounter++;
printMemoryUsage(file, documentCounter, numberOfDocuments);
}
});
logUpdate.done();
console.log('Validation completed.');