2021-11-21 20:27:15 +01:00
|
|
|
import fs from 'fs';
|
|
|
|
|
import path from 'path';
|
|
|
|
|
import getArgumentOptions from 'minimist';
|
|
|
|
|
import { parseSync } from 'svgson';
|
|
|
|
|
|
2024-06-28 11:24:37 +02:00
|
|
|
import { readSvgDirectory, getCurrentDirPath } from '@lucide/helpers';
|
2022-08-10 09:10:53 +02:00
|
|
|
import readSvgs from './readSvgs.mjs';
|
|
|
|
|
import generateSprite from './generateSprite.mjs';
|
|
|
|
|
import generateIconNodes from './generateIconNodes.mjs';
|
2023-11-17 11:12:31 +01:00
|
|
|
import copyIcons from './copyIcons.mjs';
|
|
|
|
|
|
2024-06-28 11:24:37 +02:00
|
|
|
import pkg from '../package.json' with { type: 'json' };
|
2021-11-21 20:27:15 +01:00
|
|
|
|
|
|
|
|
const cliArguments = getArgumentOptions(process.argv.slice(2));
|
2023-11-17 11:12:31 +01:00
|
|
|
const createDirectory = (dir) => {
|
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');
|
2021-11-21 20:27:15 +01:00
|
|
|
const LIB_DIR = path.join(PACKAGE_DIR, cliArguments.output || 'lib');
|
|
|
|
|
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
|
|
|
|
|
|
|
|
const parsedSvgs = svgs.map(({ name, contents }) => ({
|
|
|
|
|
name,
|
|
|
|
|
contents,
|
|
|
|
|
parsedSvg: parseSync(contents),
|
|
|
|
|
}));
|
|
|
|
|
|
2025-02-10 14:13:52 +01:00
|
|
|
await Promise.all([
|
|
|
|
|
generateSprite(parsedSvgs, PACKAGE_DIR, license),
|
|
|
|
|
generateIconNodes(parsedSvgs, PACKAGE_DIR),
|
|
|
|
|
copyIcons(parsedSvgs, PACKAGE_DIR, license),
|
|
|
|
|
]);
|