Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051#!/usr/bin/env node/** * Reads the codicon SVGs named in src/icons/names.ts and emits src/icons/sprite.generated.ts: one * `<symbol id="nib-icon-<name>">` per icon, carrying that codicon's own `viewBox` verbatim (codicons * are not all 0 0 16 16 — e.g. "files" and "terminal" are 0 0 24 24 — so a hardcoded box clips them). * The output is committed, so consumers need no build step; `pnpm test` runs this script against a * scratch file and fails if the committed one is out of date. */import { readFileSync, writeFileSync } from "node:fs";import { dirname, join } from "node:path";import { fileURLToPath } from "node:url";
const packageDir = join(dirname(fileURLToPath(import.meta.url)), "..");const codiconsDir = join(packageDir, "node_modules/@vscode/codicons/src/icons");
export async function buildSprite() { const { ICON_NAMES } = await import(join(packageDir, "src/icons/names.ts"));
const symbols = Object.entries(ICON_NAMES).map(([name, codiconId]) => { const source = readFileSync(join(codiconsDir, `${codiconId}.svg`), "utf8"); const inner = source.match(/<svg[^>]*>([\s\S]*)<\/svg>/)?.[1]?.trim(); const viewBox = source.match(/\bviewBox="([^"]*)"/)?.[1]; if (!inner || !viewBox) throw new Error(`could not read paths or viewBox out of codicon "${codiconId}" for icon "${name}"`); return { name, markup: `<symbol id="nib-icon-${name}" viewBox="${viewBox}">${inner}</symbol>` }; });
const lines = [ "// Generated by scripts/build-icons.mjs. Do not edit by hand.", "//", "// Icons from codicons (https://github.com/microsoft/vscode-codicons), Copyright (c) Microsoft", "// Corporation, licensed under CC-BY-4.0 (https://creativecommons.org/licenses/by/4.0/).", "import type { IconName } from \"./names.ts\";", "", "/** Each icon's own `<symbol>` markup (with its native viewBox), keyed by our semantic name. */", "export const ICON_SYMBOLS: Record<IconName, string> = {", ...symbols.map((s) => ` "${s.name}": ${JSON.stringify(s.markup)},`), "};", "", ];
return lines.join("\n");}
async function main() { const outPath = join(packageDir, "src/icons/sprite.generated.ts"); writeFileSync(outPath, await buildSprite()); console.log(`wrote ${outPath}`);}
if (import.meta.url === `file://${process.argv[1]}`) await main();