Spaces:
Sleeping
Sleeping
File size: 8,894 Bytes
f2f339a | 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | import { z } from "zod";
import * as fs from "fs";
import * as path from "path";
import { fileURLToPath } from "url";
import * as yaml from "js-yaml";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const CONFERENCES_DIR = path.resolve(__dirname, "../src/data/conferences");
const DATETIME_RE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
const UTC_OFFSET_RE = /^(UTC|GMT)([+-]\d{1,2})?$/;
const KNOWN_ABBREVIATIONS = new Set([
"PST",
"PDT",
"MST",
"MDT",
"CST",
"CDT",
"EST",
"EDT",
"CET",
"CEST",
"BST",
"IST",
"JST",
"KST",
"AEST",
"AEDT",
]);
function isValidTimezone(tz: string): boolean {
if (tz === "AoE") return true;
if (UTC_OFFSET_RE.test(tz)) return true;
if (KNOWN_ABBREVIATIONS.has(tz)) return true;
try {
Intl.DateTimeFormat(undefined, { timeZone: tz });
return true;
} catch {
return false;
}
}
const timezoneSchema = z.string().refine(isValidTimezone, {
message:
"Must be 'AoE', a valid IANA timezone, UTC/GMT offset, or known abbreviation (e.g. PST)",
});
const deadlineEntrySchema = z.object({
type: z.string().min(1, "Deadline type is required"),
label: z.string().min(1, "Deadline label is required"),
date: z.string().regex(DATETIME_RE, {
message: "Deadline date must match 'YYYY-MM-DD HH:mm:ss'",
}),
timezone: timezoneSchema.optional(),
});
// Helper: accept both undefined and null for optional fields (YAML parses missing vs explicit null)
function nullable<T extends z.ZodTypeAny>(schema: T) {
return schema.nullable().optional();
}
const conferenceSchema = z.object({
title: z.string().min(1, "Title is required"),
year: z.number().int().positive("Year must be a positive integer"),
id: z
.string()
.min(1, "ID is required")
.regex(
/^[a-z0-9+-]+$/,
"ID must be lowercase alphanumeric (hyphens and plus signs allowed)"
),
full_name: nullable(z.string()),
link: nullable(z.string().url("Link must be a valid URL")),
deadline: nullable(
z.string().regex(DATETIME_RE, {
message: "deadline must match 'YYYY-MM-DD HH:mm:ss'",
})
),
deadlines: nullable(z.array(deadlineEntrySchema)),
timezone: nullable(timezoneSchema),
date: z.string().min(1, "Date is required"),
place: nullable(z.string()),
city: nullable(z.string()),
country: nullable(z.string()),
venue: nullable(z.string()),
tags: nullable(z.array(z.string())),
note: nullable(z.string()),
abstract_deadline: nullable(
z.string().regex(DATETIME_RE, {
message: "abstract_deadline must match 'YYYY-MM-DD HH:mm:ss'",
})
),
start: nullable(z.union([z.string(), z.date()])),
end: nullable(z.union([z.string(), z.date()])),
rankings: nullable(z.string()),
hindex: nullable(z.number()),
rebuttal_period_start: nullable(z.string()),
rebuttal_period_end: nullable(z.string()),
final_decision_date: nullable(z.string()),
review_release_date: nullable(z.string()),
submission_deadline: nullable(z.string()),
timezone_submission: nullable(z.string()),
commitment_deadline: nullable(z.string()),
paperslink: nullable(z.string()),
pwclink: nullable(z.string()),
era_rating: nullable(z.string()),
});
interface ValidationIssue {
file: string;
index: number;
id?: string;
severity: "error" | "warning";
message: string;
}
function extractYearFromId(id: string): number | null {
const match = id.match(/(\d{2,4})(?:[a-z]*)$/);
if (!match) return null;
const digits = match[1];
if (digits.length === 4) return parseInt(digits, 10);
if (digits.length === 2) return 2000 + parseInt(digits, 10);
return null;
}
function validateConferences(): boolean {
const issues: ValidationIssue[] = [];
const allIds = new Map<string, string>(); // id -> file path
const files = fs
.readdirSync(CONFERENCES_DIR)
.filter((f) => f.endsWith(".yml") || f.endsWith(".yaml"))
.sort();
if (files.length === 0) {
console.error("No conference YAML files found in", CONFERENCES_DIR);
process.exit(1);
}
for (const file of files) {
const filePath = path.join(CONFERENCES_DIR, file);
const relPath = path.relative(process.cwd(), filePath);
let content: unknown;
try {
const raw = fs.readFileSync(filePath, "utf-8");
content = yaml.load(raw);
} catch (e) {
issues.push({
file: relPath,
index: -1,
severity: "error",
message: `Failed to parse YAML: ${e instanceof Error ? e.message : String(e)}`,
});
continue;
}
if (!Array.isArray(content)) {
issues.push({
file: relPath,
index: -1,
severity: "error",
message: "File must contain a YAML array of conference entries",
});
continue;
}
for (let i = 0; i < content.length; i++) {
const entry = content[i];
const entryId = entry?.id ?? `entry[${i}]`;
const result = conferenceSchema.safeParse(entry);
if (!result.success) {
for (const issue of result.error.issues) {
issues.push({
file: relPath,
index: i,
id: entryId,
severity: "error",
message: `${issue.path.join(".")}: ${issue.message}`,
});
}
continue;
}
const conf = result.data;
// Warn if conference has no deadline information at all
const hasDeadline = conf.deadline || (conf.deadlines && conf.deadlines.length > 0);
if (!hasDeadline) {
issues.push({
file: relPath,
index: i,
id: conf.id,
severity: "warning",
message: "No 'deadline' or 'deadlines' - conference won't appear in deadline views",
});
}
// Check for duplicate IDs across all files
const existingFile = allIds.get(conf.id);
if (existingFile) {
issues.push({
file: relPath,
index: i,
id: conf.id,
severity: "error",
message: `Duplicate id '${conf.id}' (also in ${existingFile})`,
});
} else {
allIds.set(conf.id, relPath);
}
// Warn if id year suffix doesn't match year field
const idYear = extractYearFromId(conf.id);
if (idYear !== null && idYear !== conf.year) {
issues.push({
file: relPath,
index: i,
id: conf.id,
severity: "warning",
message: `ID year suffix (${idYear}) does not match year field (${conf.year})`,
});
}
// Warn about missing tags on entries that have future deadlines
if (!conf.tags || conf.tags.length === 0) {
issues.push({
file: relPath,
index: i,
id: conf.id,
severity: "warning",
message: "Missing 'tags' - conference will not appear in filtered views",
});
}
// Warn about missing era_rating
if (!conf.era_rating) {
issues.push({
file: relPath,
index: i,
id: conf.id,
severity: "warning",
message: "Missing 'era_rating' - conference has no ERA rating defined",
});
}
// Warn about timezone abbreviations (not portable)
const allTimezones: string[] = [];
if (conf.timezone) allTimezones.push(conf.timezone);
if (conf.deadlines) {
for (const d of conf.deadlines) {
if (d.timezone) allTimezones.push(d.timezone);
}
}
for (const tz of allTimezones) {
if (KNOWN_ABBREVIATIONS.has(tz)) {
issues.push({
file: relPath,
index: i,
id: conf.id,
severity: "warning",
message: `Timezone '${tz}' is an abbreviation - prefer 'AoE', IANA name, or UTC/GMT offset`,
});
break;
}
}
}
}
// Print results
const errors = issues.filter((i) => i.severity === "error");
const warnings = issues.filter((i) => i.severity === "warning");
if (warnings.length > 0) {
console.log(`\n⚠ ${warnings.length} warning(s):\n`);
for (const w of warnings) {
const loc = w.index >= 0 ? ` [${w.id ?? `#${w.index}`}]` : "";
console.log(` ${w.file}${loc}: ${w.message}`);
}
}
if (errors.length > 0) {
console.log(`\n✗ ${errors.length} error(s):\n`);
for (const e of errors) {
const loc = e.index >= 0 ? ` [${e.id ?? `#${e.index}`}]` : "";
console.log(` ${e.file}${loc}: ${e.message}`);
}
console.log(
`\nValidation failed: ${errors.length} error(s), ${warnings.length} warning(s) across ${files.length} files.\n`
);
return false;
}
console.log(
`\n✓ All ${allIds.size} conferences in ${files.length} files passed validation.` +
(warnings.length > 0 ? ` (${warnings.length} warning(s))` : "") +
"\n"
);
return true;
}
const success = validateConferences();
process.exit(success ? 0 : 1);
|