Init
This commit is contained in:
commit
e5a7886b9c
7 files changed
+316
No files matched your search
@@ -0,0 +1,45 @@
|
||||
const Ajv = require('ajv');
|
||||
const addFormats = require('ajv-formats');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const schema = require('./token-schema.json');
|
||||
|
||||
function validateJsonFile(filePath) {
|
||||
try {
|
||||
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
const valid = validate(data);
|
||||
if (valid) {
|
||||
console.log(`File ${path.basename(filePath)} is valid.`);
|
||||
} else {
|
||||
console.log(`File ${path.basename(filePath)} is invalid:`, validate.errors);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error reading or parsing the file ${path.basename(filePath)}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
function validateAllJsonFilesInDirectory(directoryPath) {
|
||||
fs.readdir(directoryPath, (err, files) => {
|
||||
if (err) {
|
||||
console.error('Error reading directory:', err);
|
||||
return;
|
||||
}
|
||||
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(directoryPath, file);
|
||||
if (path.extname(file) === '.json') {
|
||||
validateJsonFile(filePath);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const ajv = new Ajv();
|
||||
addFormats(ajv);
|
||||
|
||||
const validate = ajv.compile(schema);
|
||||
|
||||
const dataDirectoryPath = path.resolve(process.cwd(), 'data');
|
||||
|
||||
validateAllJsonFilesInDirectory(dataDirectoryPath);
|
||||
Reference in new issue
Block a user