291 lines
10 KiB
JavaScript
291 lines
10 KiB
JavaScript
// Generates apps/web/app/components/ui/icons/vendor.tsx — a compatibility shim
|
|
// that re-exports every vendor icon used across the app (lucide-react,
|
|
// @radix-ui/react-icons, @heroicons/react/24/outline) as a Subframe
|
|
// `@subframe/core` Feather icon. Feather IS the Lucide icon set, so the swap is
|
|
// visually lossless for lucide and a close match for radix/hero.
|
|
//
|
|
// The shim presents a lucide-compatible prop surface ({ className, size, ... })
|
|
// and bridges Feather's font-size sizing model onto vendor call sites that size
|
|
// via className (`size-4`, `h-4 w-4`) or the `size` prop, using the same
|
|
// `[&>svg]:size-full` technique as icons/_feather.tsx.
|
|
//
|
|
// After generating, run scripts/swap-vendor-icon-imports.mjs to repoint imports.
|
|
//
|
|
// Run from repo root: node scripts/migrate-vendor-icons-to-feather.mjs
|
|
import { readFileSync, writeFileSync, readdirSync, statSync } from "node:fs"
|
|
import { join, dirname } from "node:path"
|
|
import { fileURLToPath } from "node:url"
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
const repoRoot = join(__dirname, "..")
|
|
const appRoot = join(repoRoot, "apps/web/app")
|
|
const outFile = join(appRoot, "components/ui/icons/vendor.tsx")
|
|
|
|
const featherNames = new Set(
|
|
readFileSync("/tmp/feather-names.txt", "utf8").split("\n").map((s) => s.trim()).filter(Boolean)
|
|
)
|
|
|
|
// vendor identifier (as imported) -> Feather component name.
|
|
const MAP = {
|
|
// arrows / chevrons / carets
|
|
ArrowDownIcon: "FeatherArrowDown",
|
|
ArrowLeftIcon: "FeatherArrowLeft",
|
|
ArrowRightIcon: "FeatherArrowRight",
|
|
ChevronDown: "FeatherChevronDown",
|
|
ChevronDownIcon: "FeatherChevronDown",
|
|
ChevronUpIcon: "FeatherChevronUp",
|
|
ChevronLeftIcon: "FeatherChevronLeft",
|
|
ChevronRight: "FeatherChevronRight",
|
|
ChevronRightIcon: "FeatherChevronRight",
|
|
ChevronsUpDown: "FeatherChevronsUpDown",
|
|
CaretDownIcon: "FeatherChevronDown",
|
|
CaretSortIcon: "FeatherChevronsUpDown",
|
|
// checks / circles / dots / badges
|
|
Check: "FeatherCheck",
|
|
CheckIcon: "FeatherCheck",
|
|
CheckCircleIcon: "FeatherCheckCircle",
|
|
CircleIcon: "FeatherCircle",
|
|
DotIcon: "FeatherDot",
|
|
DotsHorizontalIcon: "FeatherMoreHorizontal",
|
|
XCircle: "FeatherXCircle",
|
|
XCircleIcon: "FeatherXCircle",
|
|
BadgeCheck: "FeatherBadgeCheck",
|
|
// x / close
|
|
XIcon: "FeatherX",
|
|
Cross2Icon: "FeatherX",
|
|
// more / overflow
|
|
MoreHorizontal: "FeatherMoreHorizontal",
|
|
MoreHorizontalIcon: "FeatherMoreHorizontal",
|
|
MoreVerticalIcon: "FeatherMoreVertical",
|
|
MessageCircleIcon: "FeatherMessageCircle",
|
|
// common ui
|
|
CreditCard: "FeatherCreditCard",
|
|
LogOut: "FeatherLogOut",
|
|
BellIcon: "FeatherBell",
|
|
FileTextIcon: "FeatherFileText",
|
|
PaintbrushIcon: "FeatherPaintbrush",
|
|
PlugIcon: "FeatherPlug",
|
|
ShieldCheckIcon: "FeatherShieldCheck",
|
|
BookIcon: "FeatherBook",
|
|
BotIcon: "FeatherBot",
|
|
BrainIcon: "FeatherBrain",
|
|
CalendarIcon: "FeatherCalendar",
|
|
Calendar: "FeatherCalendar",
|
|
ClockIcon: "FeatherClock",
|
|
WrenchIcon: "FeatherWrench",
|
|
ClipboardIcon: "FeatherClipboard",
|
|
EyeIcon: "FeatherEye",
|
|
CopyIcon: "FeatherCopy",
|
|
RefreshCcwIcon: "FeatherRefreshCcw",
|
|
LucideRefreshCcw: "FeatherRefreshCcw",
|
|
ReloadIcon: "FeatherRefreshCw",
|
|
ExternalLinkIcon: "FeatherExternalLink",
|
|
ImportIcon: "FeatherDownload",
|
|
SunIcon: "FeatherSun",
|
|
MoonIcon: "FeatherMoon",
|
|
PlusIcon: "FeatherPlus",
|
|
Plus: "FeatherPlus",
|
|
MinusIcon: "FeatherMinus",
|
|
StoreIcon: "FeatherStore",
|
|
GripVerticalIcon: "FeatherGripVertical",
|
|
ImageIcon: "FeatherImage",
|
|
Image: "FeatherImage",
|
|
Loader2Icon: "FeatherLoader2",
|
|
LoaderCircleIcon: "FeatherLoader2",
|
|
PaperclipIcon: "FeatherPaperclip",
|
|
SendIcon: "FeatherSend",
|
|
SquareIcon: "FeatherSquare",
|
|
LinkIcon: "FeatherLink",
|
|
LockIcon: "FeatherLock",
|
|
MenuIcon: "FeatherMenu",
|
|
PanelLeftIcon: "FeatherPanelLeft",
|
|
MessageSquareIcon: "FeatherMessageSquare",
|
|
TrashIcon: "FeatherTrash2",
|
|
SearchIcon: "FeatherSearch",
|
|
SparklesIcon: "FeatherSparkles",
|
|
WandSparkles: "FeatherWandSparkles",
|
|
GearIcon: "FeatherSettings",
|
|
// text editor (novel) formatting marks
|
|
Bold: "FeatherBold",
|
|
BoldIcon: "FeatherBold",
|
|
Italic: "FeatherItalic",
|
|
ItalicIcon: "FeatherItalic",
|
|
Underline: "FeatherUnderline",
|
|
UnderlineIcon: "FeatherUnderline",
|
|
Strikethrough: "FeatherStrikethrough",
|
|
Code: "FeatherCode",
|
|
CodeIcon: "FeatherCode",
|
|
List: "FeatherList",
|
|
ListOrdered: "FeatherListOrdered",
|
|
Quote: "FeatherQuote",
|
|
Undo: "FeatherUndo",
|
|
Redo: "FeatherRedo",
|
|
Eraser: "FeatherEraser",
|
|
EraserIcon: "FeatherEraser",
|
|
Link2: "FeatherLink2",
|
|
Heading1: "FeatherHeading1",
|
|
Heading2: "FeatherHeading2",
|
|
Heading3: "FeatherHeading3",
|
|
Text: "FeatherText",
|
|
TextIcon: "FeatherText",
|
|
TextQuote: "FeatherTextQuote",
|
|
// heroicons
|
|
NoSymbolIcon: "FeatherSlash",
|
|
ServerStackIcon: "FeatherServer",
|
|
|
|
// Additional Feather icons used by the inline-`<svg>` → Feather migration
|
|
// (raw hand-authored glyphs across feature components). Not imported from a
|
|
// vendor library directly, but exposed here so those call sites can use the
|
|
// same shim. See docs/subframe/INLINE-SVG-MIGRATION.md.
|
|
HomeIcon: "FeatherHome",
|
|
StarIcon: "FeatherStar",
|
|
MailIcon: "FeatherMail",
|
|
PhoneIcon: "FeatherPhone",
|
|
AlertTriangleIcon: "FeatherAlertTriangle",
|
|
ArrowUpIcon: "FeatherArrowUp",
|
|
GlobeIcon: "FeatherGlobe",
|
|
LanguagesIcon: "FeatherLanguages",
|
|
HelpCircleIcon: "FeatherHelpCircle",
|
|
InfoIcon: "FeatherInfo",
|
|
TrendingUpIcon: "FeatherTrendingUp",
|
|
TrendingDownIcon: "FeatherTrendingDown",
|
|
AtSignIcon: "FeatherAtSign",
|
|
PilcrowIcon: "FeatherPilcrow",
|
|
EditIcon: "FeatherEdit2",
|
|
PencilIcon: "FeatherEdit2",
|
|
PlayIcon: "FeatherPlay",
|
|
VariableIcon: "FeatherVariable",
|
|
ChevronsRightIcon: "FeatherChevronsRight",
|
|
ArrowLeftRightIcon: "FeatherArrowLeftRight",
|
|
UserIcon: "FeatherUser",
|
|
}
|
|
|
|
const VENDOR_SOURCES = ["lucide-react", "@radix-ui/react-icons", "@heroicons/react/24/outline"]
|
|
|
|
// --- collect every value identifier actually imported from the vendor sources ---
|
|
function walk(dir, acc = []) {
|
|
for (const entry of readdirSync(dir)) {
|
|
if (entry === "node_modules" || entry.startsWith(".")) continue
|
|
const full = join(dir, entry)
|
|
const st = statSync(full)
|
|
if (st.isDirectory()) walk(full, acc)
|
|
else if (/\.(tsx?|jsx?)$/.test(entry)) acc.push(full)
|
|
}
|
|
return acc
|
|
}
|
|
|
|
const usedValueIdents = new Set()
|
|
const importRe = /import\s*(?:type\s*)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g
|
|
for (const file of walk(appRoot)) {
|
|
const src = readFileSync(file, "utf8")
|
|
let m
|
|
while ((m = importRe.exec(src))) {
|
|
const source = m[2]
|
|
if (!VENDOR_SOURCES.includes(source)) continue
|
|
for (const raw of m[1].split(",")) {
|
|
let spec = raw.trim()
|
|
if (!spec) continue
|
|
if (spec.startsWith("type ")) continue // a type-only specifier (e.g. `type LucideIcon`)
|
|
// handle `Foo as Bar` -> the imported name is `Foo`
|
|
const asMatch = spec.match(/^([A-Za-z0-9_]+)\s+as\s+[A-Za-z0-9_]+$/)
|
|
const name = asMatch ? asMatch[1] : spec
|
|
if (name === "LucideIcon") continue // type, exported separately
|
|
usedValueIdents.add(name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- validate ---
|
|
const errors = []
|
|
for (const name of usedValueIdents) {
|
|
if (!MAP[name]) errors.push(`UNMAPPED vendor identifier: ${name}`)
|
|
}
|
|
for (const [name, feather] of Object.entries(MAP)) {
|
|
if (!featherNames.has(feather)) errors.push(`UNKNOWN Feather: ${feather} (for ${name})`)
|
|
}
|
|
if (errors.length) {
|
|
console.error("Validation failed:\n" + errors.join("\n"))
|
|
console.error("\nUsed value identifiers found:", [...usedValueIdents].sort().join(", "))
|
|
process.exit(1)
|
|
}
|
|
|
|
// --- generate the shim ---
|
|
const entries = Object.entries(MAP).sort(([a], [b]) => a.localeCompare(b))
|
|
const feathersUsed = [...new Set(entries.map(([, f]) => f))].sort()
|
|
|
|
const header = `import * as React from "react"
|
|
import {
|
|
${feathersUsed.map((f) => ` ${f},`).join("\n")}
|
|
} from "@subframe/core"
|
|
|
|
import { cn } from "~/lib/utils"
|
|
|
|
// AUTO-GENERATED by scripts/migrate-vendor-icons-to-feather.mjs — do not edit by hand.
|
|
//
|
|
// Compatibility shim mapping the vendor icons the app used (lucide-react,
|
|
// @radix-ui/react-icons, @heroicons) onto Subframe @subframe/core Feather icons.
|
|
// Import sources were repointed here so the whole app renders Subframe's icons.
|
|
// Feather IS the Lucide set, so lucide swaps are visually identical.
|
|
|
|
/**
|
|
* The subset of lucide-react's prop surface that app call sites use. Feather
|
|
* icons render <span><svg width="1em" stroke="currentColor"/></span>, so only
|
|
* \`className\`, \`size\`, \`color\` and \`style\` affect rendering; \`strokeWidth\` /
|
|
* \`absoluteStrokeWidth\` are accepted (for type-compat) but baked into Feather.
|
|
*/
|
|
export type LucideProps = React.HTMLAttributes<HTMLSpanElement> & {
|
|
size?: number | string
|
|
strokeWidth?: number | string
|
|
absoluteStrokeWidth?: boolean
|
|
color?: string
|
|
/** SVG-only attribute some call sites pass; accepted for compat, not forwarded. */
|
|
focusable?: boolean | "true" | "false"
|
|
}
|
|
|
|
export type LucideIcon = React.FC<LucideProps>
|
|
|
|
type FeatherComponent = React.ComponentType<
|
|
React.HTMLAttributes<HTMLSpanElement> & React.RefAttributes<HTMLSpanElement>
|
|
>
|
|
|
|
function make(Feather: FeatherComponent): LucideIcon {
|
|
function Icon({
|
|
className,
|
|
size,
|
|
color,
|
|
style,
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
strokeWidth: _strokeWidth,
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
absoluteStrokeWidth: _absoluteStrokeWidth,
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
focusable: _focusable,
|
|
"aria-hidden": ariaHidden,
|
|
"aria-label": ariaLabel,
|
|
...rest
|
|
}: LucideProps) {
|
|
const sizeStyle = size != null ? { width: size, height: size } : undefined
|
|
// Decorative by default: hide from assistive tech unless the caller gave the
|
|
// icon its own accessible name (aria-label) or set aria-hidden explicitly.
|
|
const resolvedAriaHidden = ariaHidden ?? (ariaLabel ? undefined : true)
|
|
return (
|
|
<Feather
|
|
aria-hidden={resolvedAriaHidden}
|
|
aria-label={ariaLabel}
|
|
className={cn("inline-flex shrink-0 [&>svg]:size-full", size == null && "size-4", className)}
|
|
style={sizeStyle || color || style ? { ...sizeStyle, color, ...style } : undefined}
|
|
{...rest}
|
|
/>
|
|
)
|
|
}
|
|
return Icon
|
|
}
|
|
`
|
|
|
|
const exportsBlock = entries.map(([name, feather]) => `export const ${name}: LucideIcon = make(${feather})`).join("\n")
|
|
|
|
writeFileSync(outFile, header + "\n" + exportsBlock + "\n", "utf8")
|
|
console.log(`Generated ${outFile}`)
|
|
console.log(` ${entries.length} icon exports, ${feathersUsed.length} distinct Feather icons.`)
|
|
console.log(` Covered ${usedValueIdents.size} used vendor identifiers.`)
|