Files
simple-icons/scripts/lint/jsonlint.js
T

34 lines
924 B
JavaScript
Raw Normal View History

2021-10-25 21:13:10 +02:00
#!/usr/bin/env node
/**
* @fileoverview
* CLI tool to run jsonschema on the simple-icons.json data file.
*/
2021-12-25 06:22:56 -08:00
import { promises as fs } from 'node:fs';
import path from 'node:path';
import { Validator } from 'jsonschema';
import { getDirnameFromImportMeta, getIconsData } from '../utils.js';
const __dirname = getDirnameFromImportMeta(import.meta.url);
2021-10-25 21:13:10 +02:00
const rootDir = path.resolve(__dirname, '..', '..');
const schemaFile = path.resolve(rootDir, '.jsonschema.json');
2021-12-25 06:22:56 -08:00
(async () => {
const icons = await getIconsData();
const schema = JSON.parse(await fs.readFile(schemaFile, 'utf8'));
2021-12-25 06:22:56 -08:00
const validator = new Validator();
const result = validator.validate({ icons }, schema);
if (result.errors.length > 0) {
result.errors.forEach((error) => {
console.error(error);
});
2021-12-25 06:22:56 -08:00
console.error(
`Found ${result.errors.length} error(s) in simple-icons.json`,
);
process.exit(1);
}
})();