Files
Jonathan Adeline 38ccc54c2e chore: update Iconoir to 7.12.2 (#7012)
* chore(deps): update Iconoir to 7.12.2

* test: update grid visibility selector for Iconoir 7

* fix: restore open and slashed eye icons

* docs: document Iconoir 7 plugin changes
2026-12-04 15:36:56 +04:00

66 lines
2.1 KiB
JavaScript

import { readFileSync, readdirSync, existsSync } from 'node:fs'
import pathe from 'pathe'
/**
* Changes the stroke-width of the iconoir svg files because this way, we don't
* have to fork the repository and change it there.
*/
export function patchIconoirStrokeWidth(css) {
return css.replace(/stroke-width="1\.5"/g, 'stroke-width="2.0"')
}
/**
* The directories of the Baserow modules, like core, premium, enterprise and the
* ones added with `ADDITIONAL_MODULES`, which are registered as a path to their
* `module.js`.
*/
export function getLocalModuleDirectories(options) {
return options.modules
.map((module) => (Array.isArray(module) ? module[0] : module))
.filter((module) => typeof module === 'string')
.map((module) => pathe.resolve(options.rootDir, module))
.filter((modulePath) => existsSync(modulePath))
.map((modulePath) => pathe.dirname(modulePath))
}
/**
* Icons must be mentioned with their full class, like `iconoir-info-circle`,
* because a name that's put together at runtime can't be found.
*/
export function findUsedIconoirIcons(directories, ignoredDirectory) {
const icons = new Set()
const visit = (directory) => {
for (const entry of readdirSync(directory, { withFileTypes: true })) {
const entryPath = pathe.join(directory, entry.name)
if (entry.isDirectory()) {
if (
entry.name !== 'node_modules' &&
!entry.name.startsWith('.') &&
entryPath !== ignoredDirectory
) {
visit(entryPath)
}
} else if (/\.(vue|jsx?|tsx?|scss)$/.test(entry.name)) {
const content = readFileSync(entryPath, 'utf-8')
for (const match of content.matchAll(
/iconoir-([a-z0-9]+(?:-[a-z0-9]+)*)/g
)) {
icons.add(match[1])
}
}
}
}
directories.forEach(visit)
return icons
}
/**
* Iconoir inlines an SVG for each icon. Keep only the icon rules the app uses.
*/
export function removeUnusedIconoirIcons(css, usedIcons) {
return css.replace(
/\.iconoir-([a-z0-9 -]+)::before\{[^}]*\}/g,
(rule, name) => (usedIcons.has(name) ? rule : '')
)
}