2021-10-25 22:13:10 +03:00
|
|
|
#!/usr/bin/env node
|
|
|
|
/**
|
|
|
|
* @fileoverview
|
|
|
|
* CLI tool to run jsonschema on the simple-icons.json data file.
|
|
|
|
*/
|
2021-02-19 17:19:22 +03:00
|
|
|
|
2021-12-25 17:22:56 +03:00
|
|
|
import { promises as fs } from 'node:fs';
|
|
|
|
import path from 'node:path';
|
|
|
|
import { Validator } from 'jsonschema';
|
2022-09-28 05:11:27 +03:00
|
|
|
import {
|
|
|
|
getDirnameFromImportMeta,
|
|
|
|
getIconsData,
|
|
|
|
getJsonSchemaData,
|
|
|
|
} from '../utils.js';
|
2021-12-25 17:22:56 +03:00
|
|
|
|
2022-09-28 05:11:27 +03:00
|
|
|
const icons = await getIconsData();
|
2021-12-25 17:22:56 +03:00
|
|
|
const __dirname = getDirnameFromImportMeta(import.meta.url);
|
2022-09-28 05:11:27 +03:00
|
|
|
const schema = await getJsonSchemaData(path.resolve(__dirname, '..', '..'));
|
2021-10-25 22:13:10 +03:00
|
|
|
|
2022-09-28 05:11:27 +03:00
|
|
|
const validator = new Validator();
|
|
|
|
const result = validator.validate({ icons }, schema);
|
|
|
|
if (result.errors.length > 0) {
|
|
|
|
result.errors.forEach((error) => {
|
|
|
|
console.error(error);
|
|
|
|
});
|
2021-02-19 17:19:22 +03:00
|
|
|
|
2022-09-28 05:11:27 +03:00
|
|
|
console.error(`Found ${result.errors.length} error(s) in simple-icons.json`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|