Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

4.0 KB
Raw Blame
#!/usr/bin/env node
// Vendors the Nucleo outline React components (core 24px by default) named in
// src/components/icons/nucleo-map.json into src/components/icons/nucleo/ and
// regenerates src/components/icons/index.ts. Nucleo is a paid library; the
// source install lives outside the repo (~/.nucleo/skills, set NUCLEO_SKILLS_ROOT
// to override) and only the icons the app actually uses are committed, so the
// bundle works offline and without a Nucleo license on the build machine.

const fs = require("fs");
const os = require("os");
const path = require("path");
const { execFileSync } = require("child_process");

const NUCLEO_ROOT = process.env.NUCLEO_SKILLS_ROOT || path.join(os.homedir(), ".nucleo", "skills");
const ICONS_DIR = path.join(__dirname, "..", "src", "components", "icons");
const VENDOR_DIR = path.join(ICONS_DIR, "nucleo");
const FILL = "outline";
// A map entry is either a core 24px label ("calendar") or, for icons that only
// exist elsewhere, { family, label, size } (e.g. { family: "ui", label: "redo-2", size: "18px" }).
const DEFAULT_FAMILY = "core";
const DEFAULT_SIZE = "24px";

const map = JSON.parse(fs.readFileSync(path.join(ICONS_DIR, "nucleo-map.json"), "utf8"));
const entries = Object.entries(map).map(([name, spec]) => [
  name,
  typeof spec === "string"
    ? { family: DEFAULT_FAMILY, label: spec, size: DEFAULT_SIZE }
    : { family: DEFAULT_FAMILY, size: DEFAULT_SIZE, ...spec },
]);

const catalogs = new Map();
function lookup({ family, label, size }) {
  if (!catalogs.has(family)) {
    const catalog = JSON.parse(
      fs.readFileSync(path.join(NUCLEO_ROOT, family, "icons.json"), "utf8")
    );
    catalogs.set(
      family,
      new Map(
        catalog.icons
          .filter((icon) => icon.fills?.includes(FILL))
          .map((icon) => [`${icon.label}@${icon.sizes?.[0]}`, icon])
      )
    );
  }
  return catalogs.get(family).get(`${label}@${size}`);
}

const missing = entries
  .filter(([, spec]) => !lookup(spec))
  .map(([name, spec]) => `${name} -> ${spec.family}/${spec.label}@${spec.size}`);
if (missing.length) {
  console.error(`Not found as ${FILL}: ${missing.join(", ")}`);
  process.exit(1);
}

fs.rmSync(VENDOR_DIR, { recursive: true, force: true });
fs.mkdirSync(VENDOR_DIR, { recursive: true });

const components = new Set();
for (const [, spec] of entries) {
  const { component, componentPath } = lookup(spec);
  if (components.has(component)) continue;
  components.add(component);
  // Core components default to butt caps; the app's soft geometry wants round.
  const source = fs
    .readFileSync(path.join(NUCLEO_ROOT, componentPath), "utf8")
    .replace('corners = "square"', 'corners = "round"');
  fs.writeFileSync(path.join(VENDOR_DIR, `${component}.tsx`), source);
}

const kebab = (name) =>
  name
    .replace(/([a-z])([A-Z0-9])/g, "$1-$2")
    .replace(/([0-9])([A-Z])/g, "$1-$2")
    .toLowerCase();

const exportLines = entries
  .sort(([a], [b]) => a.localeCompare(b))
  .map(
    ([name, spec]) =>
      `export const ${name} = createIcon("${kebab(name)}", Nucleo.${lookup(spec).component});`
  );

const index = `// Generated by scripts/sync-nucleo-icons.js from nucleo-map.json. Do not edit by hand.
import { createIcon } from "./createIcon";
import * as Nucleo from "./nucleo";

export type { IconComponent, IconProps } from "./createIcon";
export {
  Bold,
  ChevronsUpDown,
  Circle,
  CopyRounded,
  FolderRounded,
  Heading,
  Italic,
  List,
  ListChecks,
  ListEnd,
  ListOrdered,
  Quote,
  Square,
  SquareSlash,
  SquareSparkle,
  Strikethrough,
  Table,
} from "./primitives";

${exportLines.join("\n")}
`;
fs.writeFileSync(path.join(ICONS_DIR, "index.ts"), index);

const barrel = [...components]
  .sort()
  .map((component) => `export { ${component} } from "./${component}";`)
  .join("\n");
fs.writeFileSync(path.join(VENDOR_DIR, "index.ts"), `${barrel}\n`);

execFileSync("npx", ["prettier", "--write", ICONS_DIR], { stdio: "ignore" });
console.log(`Vendored ${components.size} Nucleo components for ${entries.length} icons.`);