File size: 903 Bytes
04b48d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import fs from "node:fs";
import path from "node:path";
import { root, validateProfiles } from "./profile-utils.mjs";

const result = validateProfiles();

if (result.errors.length) {
  console.error(result.errors.join("\n"));
  process.exit(1);
}

const payload = {
  schema_version: "1.0.0",
  generated_at: generatedAt(result.profiles),
  profiles: result.profiles,
};
const target = path.join(root, "assets", "local-frontier-profile-data.js");
const source = `window.LOCAL_FRONTIER_PROFILE_DATA = ${JSON.stringify(payload, null, 2)};\n`;

fs.writeFileSync(target, source);
console.log(
  `wrote ${path.relative(root, target)} with ${result.profiles.length} profiles`,
);

function generatedAt(profiles) {
  const dates = profiles
    .map((profile) => profile.review?.reviewed_at)
    .filter(Boolean)
    .sort();
  const latest = dates.at(-1) || "1970-01-01";
  return `${latest}T00:00:00.000Z`;
}