Files
lucide/scripts/generateNextJSAliases.mjs
Eric Fennis aefb710e5c feat(@lucide/svelte): Lucide svelte 5 package (#2753)
* Lucide svelte (#1)

* Update peerDependencies to support Svelte 5

* Bump svelte version

* Bump @testing-library/svelte version

* Remove alias in vitest.config.ts that causes tests to fail due to deprecated svelte/internal API

* Convert to svelte 5 syntax

* Bump vite & @sveltejs/vite-plugin-svelte version

* Fix error during render when children prop is missing & fix components being mounted on the server during tests

* Update test snapshots to reflect the differences in the html generated by svelte 5

* Convert class attribute to new array syntax with built-in clsx

* Convert export template to svelte 5 syntax

* Move svelte 5 to separate directory

* Update snapshots

* Update docs

* fix(icon): change variable declaration from let to const in Icon.svelte

* Lucide svelte (#1) (#2727)

* Update peerDependencies to support Svelte 5

* Bump svelte version

* Bump @testing-library/svelte version

* Remove alias in vitest.config.ts that causes tests to fail due to deprecated svelte/internal API

* Convert to svelte 5 syntax

* Bump vite & @sveltejs/vite-plugin-svelte version

* Fix error during render when children prop is missing & fix components being mounted on the server during tests

* Update test snapshots to reflect the differences in the html generated by svelte 5

* Convert class attribute to new array syntax with built-in clsx

* Convert export template to svelte 5 syntax

* Revert changes in lucide-svelte library

* Update package lock

* Update test files

* Formatting

* Update clean command

* Fix build

* Update packages

* update deps

* Fix export script

* Format code

* Revert version number change in package json

* Update workflows

---------

Co-authored-by: Aurélien Richard <56389380+aurelienrichard@users.noreply.github.com>
2025-03-07 13:44:09 +01:00

50 lines
1.8 KiB
JavaScript

import path from 'path';
import { promises as fs } from 'fs';
import { getCurrentDirPath, readSvgDirectory } from '../tools/build-helpers/helpers.mjs';
// This is a special case convertion NextJS uses for their modularize imports. We try to follow the same convention, to generate the same imports.
function pascalToKebabNextJSFlavour(str) {
return str
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
.replace(/([a-z])-?([0-9]+|[A-Z])/g, '$1-$2')
.replace(/([0-9]+)-?([a-zA-Z])/g, '$1-$2')
.replace(/([0-9])-([0-9])/g, '$1$2')
.split('-')
.map((word) => word.toLowerCase())
.join('-');
}
const currentDir = getCurrentDirPath(import.meta.url);
const ICONS_DIR = path.resolve(currentDir, '../icons');
const svgFiles = await readSvgDirectory(ICONS_DIR);
const iconNames = svgFiles.map((icon) => icon.split('.')[0]).reverse();
console.log('Creating aliases for NextJS imports: ');
Promise.all(
iconNames.map(async (iconName) => {
const pascalCaseName = iconName.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
const iconNameKebabCaseNextjsFlavour = pascalToKebabNextJSFlavour(pascalCaseName);
if (iconName !== iconNameKebabCaseNextjsFlavour) {
console.log(iconName, '➡️', iconNameKebabCaseNextjsFlavour);
const metaJson = await fs.readFile(path.resolve(ICONS_DIR, `${iconName}.json`), 'utf-8');
const iconMetaData = JSON.parse(metaJson);
const aliases = iconMetaData.aliases ?? [];
if (!aliases.includes(iconNameKebabCaseNextjsFlavour)) {
aliases.push(iconNameKebabCaseNextjsFlavour);
}
let output = JSON.stringify({ ...iconMetaData, aliases }, null, 2);
output = `${output}\n`;
fs.writeFile(path.resolve(ICONS_DIR, `${iconName}.json`), output, 'utf-8');
}
}),
);