mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-05-18 09:34:43 +02:00
fix(@lucide/svelte): proper doc comments for svelte components (#4267)
* fix(@lucide/svelte): proper doc comments for svelte components * Update license text --------- Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
This commit is contained in:
@@ -7,6 +7,8 @@ import { getJSBanner } from './license.mts';
|
||||
const currentDir = getCurrentDirPath(import.meta.url);
|
||||
const targetDirectory = path.join(currentDir, '../dist');
|
||||
|
||||
const jsBanner = getJSBanner();
|
||||
|
||||
const files = await readdir(targetDirectory, {
|
||||
recursive: true,
|
||||
encoding: 'utf-8',
|
||||
@@ -22,43 +24,10 @@ for (const file of files) {
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const contents = (await readFile(filepath, { encoding: 'utf-8' })) as unknown as string;
|
||||
let newContents = contents;
|
||||
const ext = path.extname(filepath);
|
||||
let license;
|
||||
|
||||
if (/\.(js|mjs|cjs|ts)/.test(ext)) {
|
||||
license = getJSBanner();
|
||||
}
|
||||
|
||||
if (license) {
|
||||
newContents = license + contents;
|
||||
}
|
||||
|
||||
// Places icon block comment at the top of the Svelte component class
|
||||
if (/icons\/(.*?)\.svelte\.d\.ts/.test(filepath)) {
|
||||
const svelteFilepath = filepath.replace('.d.ts', '');
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const svelteFileContents = (await readFile(svelteFilepath, { encoding: 'utf-8' })) as unknown as string;;
|
||||
|
||||
const blockCommentRegex = /\/\*\*\n\s\*\s(@component\s@name)[\s\S]*?\*\//;
|
||||
const blockCommentMatch = blockCommentRegex.exec(svelteFileContents);
|
||||
|
||||
if (blockCommentMatch !== null) {
|
||||
const blockComment = blockCommentMatch[0];
|
||||
|
||||
const exportClassRegex = /export default class (\w+) extends SvelteComponentTyped<(.*?)> {/;
|
||||
|
||||
if (exportClassRegex.test(newContents)) {
|
||||
newContents = newContents.replace(
|
||||
exportClassRegex,
|
||||
`${blockComment}\nexport default class $1 extends SvelteComponentTyped<$2> {`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newContents !== contents) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await writeFile(filepath, newContents, { encoding: 'utf-8' });
|
||||
await writeFile(filepath, jsBanner + contents, { encoding: 'utf-8' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,34 @@
|
||||
import base64SVG from '@lucide/build-icons/utils/base64SVG';
|
||||
import { getJSBanner } from './license.mts';
|
||||
import { getHTMLBanner } from './license.mts';
|
||||
import defineExportTemplate from '@lucide/build-icons/utils/defineExportTemplate';
|
||||
|
||||
export default defineExportTemplate(async ({
|
||||
iconName,
|
||||
children,
|
||||
componentName,
|
||||
getSvg,
|
||||
deprecated,
|
||||
deprecationReason,
|
||||
}) => {
|
||||
const svgContents = await getSvg();
|
||||
const svgBase64 = base64SVG(svgContents);
|
||||
export default defineExportTemplate(
|
||||
async ({ iconName, children, getSvg, deprecated, deprecationReason }) => {
|
||||
const svgContents = await getSvg();
|
||||
const svgBase64 = base64SVG(svgContents);
|
||||
|
||||
return `\
|
||||
return `\
|
||||
${getHTMLBanner()}
|
||||
<script lang="ts">
|
||||
${getJSBanner()}
|
||||
import Icon from '../Icon.svelte';
|
||||
import type { IconNode, IconProps } from '../types.js';
|
||||
|
||||
let props: IconProps = $props();
|
||||
|
||||
const iconNode: IconNode = ${JSON.stringify(children)};
|
||||
|
||||
/**
|
||||
* @component @name ${componentName}
|
||||
* @description Lucide SVG icon component, renders SVG Element with children.
|
||||
*
|
||||
* @preview  - https://lucide.dev/icons/${iconName}
|
||||
* @see https://lucide.dev/guide/packages/lucide-svelte - Documentation
|
||||
*
|
||||
* @param {Object} props - Lucide icons props and any valid SVG attribute
|
||||
* @returns {FunctionalComponent} Svelte component
|
||||
* ${deprecated ? `@deprecated ${deprecationReason}` : ''}
|
||||
*/
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@component
|
||||
|
||||
Lucide SVG icon component, renders SVG Element with children.
|
||||
|
||||
@preview  - https://lucide.dev/icons/${iconName}
|
||||
@see https://lucide.dev/guide/packages/lucide-svelte - Documentation
|
||||
${deprecated ? `\n@deprecated ${deprecationReason}\n` : ''}\
|
||||
-->
|
||||
|
||||
<Icon name="${iconName}" {...props} iconNode={iconNode} />
|
||||
`;
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
@@ -3,11 +3,26 @@ import pkg from '../package.json' with { type: 'json' };
|
||||
|
||||
const license = fs.readFileSync('LICENSE', 'utf-8');
|
||||
|
||||
export function getHTMLBanner() {
|
||||
return `\
|
||||
<!--
|
||||
${pkg.name} v${pkg.version} - ${pkg.license}
|
||||
|
||||
This source code is licensed under the ${pkg.license} license.
|
||||
See the LICENSE file in the root directory of this source tree.
|
||||
-->
|
||||
|
||||
`;
|
||||
}
|
||||
|
||||
export function getJSBanner() {
|
||||
return `/**
|
||||
return `\
|
||||
/**
|
||||
* @file
|
||||
* @license ${pkg.name} v${pkg.version} - ${pkg.license}
|
||||
*
|
||||
* ${license.split('\n').join('\n * ')}
|
||||
* This source code is licensed under the ${pkg.license} license.
|
||||
* See the LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user