2021-11-21 20:27:15 +01:00
|
|
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
|
|
|
import { basename } from 'path';
|
2024-06-28 11:24:37 +02:00
|
|
|
import { readSvg } from '@lucide/helpers';
|
2025-06-18 15:47:24 +02:00
|
|
|
import { type INode, parseSync } from 'svgson';
|
2021-11-21 20:27:15 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build an object in the format: `{ <name>: <contents> }`.
|
|
|
|
|
* @param {string[]} svgFiles - A list of filenames.
|
|
|
|
|
* @param {Function} getSvg - A function that returns the contents of an SVG file given a filename.
|
|
|
|
|
* @returns {Object}
|
|
|
|
|
*/
|
2025-06-18 15:47:24 +02:00
|
|
|
export default function readSVGs(svgFiles: string[], iconsDirectory: string) {
|
2025-02-10 14:13:52 +01:00
|
|
|
const SVGReadPromises = svgFiles.map(async (svgFile) => {
|
2021-11-21 20:27:15 +01:00
|
|
|
const name = basename(svgFile, '.svg');
|
2025-02-10 14:13:52 +01:00
|
|
|
const contents = await readSvg(svgFile, iconsDirectory);
|
2021-11-21 20:27:15 +01:00
|
|
|
|
2025-06-18 15:47:24 +02:00
|
|
|
return {
|
|
|
|
|
name,
|
|
|
|
|
contents,
|
|
|
|
|
parsedSvg: parseSync(contents),
|
|
|
|
|
};
|
2021-11-21 20:27:15 +01:00
|
|
|
});
|
2025-02-10 14:13:52 +01:00
|
|
|
|
|
|
|
|
return Promise.all(SVGReadPromises);
|
2023-11-17 11:12:31 +01:00
|
|
|
}
|
2025-06-18 15:47:24 +02:00
|
|
|
|
|
|
|
|
export type SVGFile = {
|
|
|
|
|
name: string;
|
|
|
|
|
contents: string;
|
|
|
|
|
parsedSvg: INode
|
|
|
|
|
}
|