mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-05-18 11:56:26 +02:00
* Add new lucide angular package * feat(packages/angular): added initial @lucide/angular package * feat(packages/angular): update readme * feat(packages/angular): update angular.json * docs(packages/angular): added (for now) full documentation for @lucide/angular * docs(packages/angular): added migration guide from lucide-angular * fix(github): fix package label syntax 😅 * fix(lint): fix linting issues * fix(github/angular): add prebuild stage * fix(github/angular): add prebuild stage & fix tests * fix(github/angular): fix LucideIconComponentType, update with _real_ public members * fix(github/angular): add prebuild to build step manually * fix(github/angular): downgrade vitest * fix(packages/angular): fix migration guide code example * fix(packages): add vitest + @vitest/* to pnpm overrides * fix(packages): update pnpm-lock with merged version * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix(packages): fix aria-hidden logic * fix(packages): update pnpm-lock * fix(packages): extract vitest and jsdom to root devDependencies * Fix copy utils script * Format code * feat(packages/angular): switched to self-describing IconData object from separate node+name – no more toKebabCase hackery feat(packages/angular): renamed LucideIconComponentType => LucideIcon, and LucideIcon => LucideDynamicIcon feat(packages/angular): added backwards compatible CSS class support feat(packages/angular): switched to vector-effect: non-scaling-stroke implementation from computed stroke width feat(packages/angular): rewrote icon provider to only accept a list of self-described icons – no more toKebabCase hackery & as an added bonus automatic backwards compatible alias support 🚀 feat(packages/angular): added legacy icon node helper function for passing legacy icons to providers test(packages/angular): added unit tests on LUCIDE_CONFIG provider usage * fix(packages/angular): fix linting issues * feat(packages/angular): extract createLucideIcon logic into helper function, refactor export template to use the iconData object as defined in ExportTemplate * Replace author * Remove private field * fix(packages/angular): remove createLucideIcon, it breaks the package :'( * fix(packages/angular): fix rendering order of child elements (_before_ projected content) * Format package.json * Update docs/guide/packages/angular.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/angular/MIGRATION.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Eric Fennis <eric.fennis@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
116 lines
3.2 KiB
TypeScript
116 lines
3.2 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import prettier from 'prettier';
|
|
import { readSvg, toPascalCase } from '@lucide/helpers';
|
|
import deprecationReasonTemplate from '../utils/deprecationReasonTemplate.ts';
|
|
import type { IconMetadata, IconNode, Path, TemplateFunction } from '../types.ts';
|
|
import { type INode } from 'svgson';
|
|
|
|
interface GenerateIconFiles {
|
|
iconNodes: Record<string, INode>;
|
|
outputDirectory: Path;
|
|
template: TemplateFunction;
|
|
showLog?: boolean;
|
|
iconFileExtension?: string;
|
|
separateIconFileExport?: boolean;
|
|
separateIconFileExportExtension?: string;
|
|
pretty?: boolean;
|
|
iconsDir: string;
|
|
iconMetaData: Record<string, IconMetadata>;
|
|
}
|
|
|
|
function generateIconFiles({
|
|
iconNodes,
|
|
outputDirectory,
|
|
template,
|
|
showLog = true,
|
|
iconFileExtension = '.js',
|
|
separateIconFileExport = false,
|
|
separateIconFileExportExtension,
|
|
pretty = true,
|
|
iconsDir,
|
|
iconMetaData,
|
|
}: GenerateIconFiles) {
|
|
const icons = Object.keys(iconNodes);
|
|
const iconsDistDirectory = path.join(outputDirectory, `icons`);
|
|
|
|
if (!fs.existsSync(iconsDistDirectory)) {
|
|
fs.mkdirSync(iconsDistDirectory);
|
|
}
|
|
|
|
const writeIconFiles = icons.map(async (iconName) => {
|
|
const location = path.join(iconsDistDirectory, `${iconName}${iconFileExtension}`);
|
|
const componentName = toPascalCase(iconName);
|
|
|
|
const children: IconNode = iconNodes[iconName].children.map(({ name, attributes }) => [
|
|
name,
|
|
attributes,
|
|
]);
|
|
|
|
const getSvg = () => readSvg(`${iconName}.svg`, iconsDir);
|
|
const {
|
|
deprecated = false,
|
|
toBeRemovedInVersion = undefined,
|
|
aliases = [],
|
|
} = iconMetaData[iconName];
|
|
const deprecationReason = deprecated
|
|
? deprecationReasonTemplate(iconMetaData[iconName].deprecationReason ?? '', {
|
|
componentName,
|
|
iconName,
|
|
toBeRemovedInVersion,
|
|
})
|
|
: '';
|
|
|
|
const iconData = {
|
|
name: iconName,
|
|
size: 24,
|
|
node: children,
|
|
...((aliases?.length ?? 0) > 0 && {
|
|
aliases: aliases.map((alias) => (typeof alias === 'string' ? alias : alias.name)),
|
|
}),
|
|
};
|
|
const elementTemplate = await template({
|
|
componentName,
|
|
iconName,
|
|
children,
|
|
getSvg,
|
|
deprecated,
|
|
deprecationReason,
|
|
iconData,
|
|
});
|
|
|
|
const output = pretty
|
|
? await prettier.format(elementTemplate, {
|
|
singleQuote: true,
|
|
trailingComma: 'all',
|
|
printWidth: 100,
|
|
parser: iconFileExtension.endsWith('.ts') ? 'babel-ts' : 'babel',
|
|
})
|
|
: elementTemplate;
|
|
|
|
await fs.promises.writeFile(location, output, 'utf-8');
|
|
|
|
if (separateIconFileExport) {
|
|
const output = `export { default } from "./${iconName}${iconFileExtension}";\n`;
|
|
const location = path.join(
|
|
iconsDistDirectory,
|
|
`${iconName}${separateIconFileExportExtension ?? iconFileExtension}`,
|
|
);
|
|
|
|
await fs.promises.writeFile(location, output, 'utf-8');
|
|
}
|
|
});
|
|
|
|
return Promise.all(writeIconFiles)
|
|
.then(() => {
|
|
if (showLog) {
|
|
console.log('Successfully built', icons.length, 'icons.');
|
|
}
|
|
})
|
|
.catch((error) => {
|
|
throw new Error(`Something went wrong generating icon files,\n ${error}`);
|
|
});
|
|
}
|
|
|
|
export default generateIconFiles;
|