-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.js
More file actions
49 lines (40 loc) · 1.55 KB
/
validate.js
File metadata and controls
49 lines (40 loc) · 1.55 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
/**
* Pre-deploy validation for data.json against world.geojson.
* Run: node validate.js
* Exit code 0 = pass, 1 = errors found.
*/
import { readFileSync } from 'fs';
import { validateEntries } from './js/data.js';
const warnings = [];
const data = JSON.parse(readFileSync('data.json', 'utf8'));
const geo = JSON.parse(readFileSync('assets/world.geojson', 'utf8'));
const entries = data.pathogens || [];
const errors = validateEntries(entries, { geoFeatures: geo.features });
const diseases = new Set(entries.map((entry) => entry.disease));
const countries = new Set(entries.map((entry) => entry.country));
const statuses = {};
const dates = new Set(entries.map((entry) => entry.lastUpdated).filter(Boolean));
entries.forEach((entry) => {
statuses[entry.transmissionStatus] = (statuses[entry.transmissionStatus] || 0) + 1;
});
console.log('\n--- Data Summary ---');
console.log(`Entries: ${entries.length}`);
console.log(`Diseases: ${diseases.size} (${[...diseases].join(', ')})`);
console.log(`Countries: ${countries.size}`);
for (const [status, count] of Object.entries(statuses)) {
console.log(` ${status}: ${count}`);
}
if (dates.size === 1) {
console.log(`Date: ${[...dates][0]}`);
}
if (warnings.length > 0) {
console.log(`\n--- Warnings (${warnings.length}) ---`);
warnings.forEach((warning) => console.log(` ⚠ ${warning}`));
}
if (errors.length > 0) {
console.log(`\n--- Errors (${errors.length}) ---`);
errors.forEach((error) => console.log(` ✗ ${error}`));
process.exit(1);
}
console.log('\n✓ All checks passed\n');