2021-11-21 20:27:15 +01:00
|
|
|
import fs from 'fs';
|
|
|
|
|
import path from 'path';
|
|
|
|
|
import { parseSync } from 'svgson';
|
|
|
|
|
|
2024-06-28 11:24:37 +02:00
|
|
|
import { readSvgDirectory, getCurrentDirPath } from '@lucide/helpers';
|
2025-06-18 15:47:24 +02:00
|
|
|
import readSvgs from './readSvgs.mts';
|
|
|
|
|
import generateSprite from './generateSprite.mts';
|
|
|
|
|
import generateIconNodes from './generateIconNodes.mts';
|
|
|
|
|
import copyIcons from './copyIcons.mts';
|
2023-11-17 11:12:31 +01:00
|
|
|
|
2024-06-28 11:24:37 +02:00
|
|
|
import pkg from '../package.json' with { type: 'json' };
|
2021-11-21 20:27:15 +01:00
|
|
|
|
2025-06-18 15:47:24 +02:00
|
|
|
const createDirectory = (dir: string) => {
|
2021-11-21 20:27:15 +01:00
|
|
|
if (!fs.existsSync(dir)) {
|
|
|
|
|
fs.mkdirSync(dir);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-17 11:12:31 +01:00
|
|
|
const currentDir = getCurrentDirPath(import.meta.url);
|
2022-08-10 09:10:53 +02:00
|
|
|
|
|
|
|
|
const PACKAGE_DIR = path.resolve(currentDir, '../');
|
2023-11-17 11:12:31 +01:00
|
|
|
const ICONS_DIR = path.join(PACKAGE_DIR, '../../icons');
|
2025-06-18 15:47:24 +02:00
|
|
|
const LIB_DIR = path.join(PACKAGE_DIR, 'lib');
|
2021-11-21 20:27:15 +01:00
|
|
|
const ICON_MODULE_DIR = path.join(LIB_DIR, 'icons');
|
|
|
|
|
|
2023-11-17 11:12:31 +01:00
|
|
|
const license = `@license ${pkg.name} v${pkg.version} - ${pkg.license}`;
|
|
|
|
|
|
2021-11-21 20:27:15 +01:00
|
|
|
createDirectory(LIB_DIR);
|
|
|
|
|
createDirectory(ICON_MODULE_DIR);
|
|
|
|
|
|
2025-02-10 14:13:52 +01:00
|
|
|
const svgFiles = await readSvgDirectory(ICONS_DIR);
|
|
|
|
|
const svgs = await readSvgs(svgFiles, ICONS_DIR);
|
2021-11-21 20:27:15 +01:00
|
|
|
|
2025-02-10 14:13:52 +01:00
|
|
|
await Promise.all([
|
2025-06-18 15:47:24 +02:00
|
|
|
generateSprite(svgs, PACKAGE_DIR, license),
|
|
|
|
|
generateIconNodes(svgs, PACKAGE_DIR),
|
|
|
|
|
copyIcons(svgs, PACKAGE_DIR, license),
|
2025-02-10 14:13:52 +01:00
|
|
|
]);
|