Skip to content

Commit

Permalink
Add export template with comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ericfennis committed Dec 23, 2023
1 parent cb2022c commit 4db0fff
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 10 deletions.
21 changes: 20 additions & 1 deletion packages/lucide-preact/scripts/exportTemplate.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
export default ({ componentName, children }) => `
/* eslint-disable import/no-extraneous-dependencies */
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';

export default ({ componentName, iconName, children, getSvg, deprecated }) => {
const svgContents = getSvg();
const svgBase64 = base64SVG(svgContents);

return `
import createLucideIcon from '../createLucideIcon';
/**
* @component @name ${componentName}
* @description Lucide SVG icon component, renders SVG Element with children.
*
* @preview ![img](data:image/svg+xml;base64,${svgBase64}) - https://lucide.dev/icons/${iconName}
* @see https://lucide.dev/guide/packages/lucide-preact - Documentation
*
* @param {Object} props - Lucide icons props and any valid SVG attribute
* @returns {JSX.Element} JSX Element
* ${deprecated ? '@deprecated' : ''}
*/
const ${componentName} = createLucideIcon('${componentName}', ${JSON.stringify(children)});
export default ${componentName};
`;
};
21 changes: 20 additions & 1 deletion packages/lucide-react-native/scripts/exportTemplate.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
export default ({ componentName, children }) => `
/* eslint-disable import/no-extraneous-dependencies */
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';

export default ({ componentName, iconName, children, getSvg, deprecated }) => {
const svgContents = getSvg();
const svgBase64 = base64SVG(svgContents);

return `
import createLucideIcon from '../createLucideIcon';
/**
* @component @name ${componentName}
* @description Lucide SVG icon component, renders SVG Element with children.
*
* @preview ![img](data:image/svg+xml;base64,${svgBase64}) - https://lucide.dev/icons/${iconName}
* @see https://lucide.dev/guide/packages/lucide-react-native - Documentation
*
* @param {Object} props - Lucide icons props and any valid SVG attribute
* @returns {JSX.Element} JSX Element
* ${deprecated ? '@deprecated' : ''}
*/
const ${componentName} = createLucideIcon('${componentName}', ${JSON.stringify(children)});
export default ${componentName};
`;
};
21 changes: 20 additions & 1 deletion packages/lucide-solid/scripts/exportTemplate.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
export default ({ componentName, children }) => `
/* eslint-disable import/no-extraneous-dependencies */
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';

export default ({ componentName, iconName, children, getSvg, deprecated }) => {
const svgContents = getSvg();
const svgBase64 = base64SVG(svgContents);

return `
import Icon from '../Icon';
import type { IconNode, LucideProps } from '../types';
const iconNode: IconNode = ${JSON.stringify(children)};
/**
* @component @name ${componentName}
* @description Lucide SVG icon component, renders SVG Element with children.
*
* @preview ![img](data:image/svg+xml;base64,${svgBase64}) - https://lucide.dev/icons/${iconName}
* @see https://lucide.dev/guide/packages/lucide-solid - Documentation
*
* @param {Object} props - Lucide icons props and any valid SVG attribute
* @returns {JSX.Element} JSX Element
* ${deprecated ? '@deprecated' : ''}
*/
const ${componentName} = (props: LucideProps) => (
<Icon {...props} name="${componentName}" iconNode={iconNode} />
)
export default ${componentName};
`;
};
4 changes: 2 additions & 2 deletions packages/lucide-vue-next/scripts/buildTypes.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
// eslint-disable-next-line import/no-extraneous-dependencies
import { getAliases } from '@lucide/build-icons';
import { getIconMetaData } from '@lucide/build-icons';
import {
readSvgDirectory,
resetFile,
Expand Down Expand Up @@ -48,7 +48,7 @@ svgFiles.forEach((svgFile) => {
declarationFileContent += getComponentImport(componentName);
});

const aliases = await getAliases(ICONS_DIR);
const aliases = await getIconMetaData(ICONS_DIR);

declarationFileContent += `\n
Expand Down
21 changes: 20 additions & 1 deletion packages/lucide-vue-next/scripts/exportTemplate.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
export default ({ componentName, children }) => `
/* eslint-disable import/no-extraneous-dependencies */
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';

export default ({ componentName, iconName, children, getSvg, deprecated }) => {
const svgContents = getSvg();
const svgBase64 = base64SVG(svgContents);

return `
import createLucideIcon from '../createLucideIcon';
/**
* @component @name ${componentName}
* @description Lucide SVG icon component, renders SVG Element with children.
*
* @preview ![img](data:image/svg+xml;base64,${svgBase64}) - https://lucide.dev/icons/${iconName}
* @see https://lucide.dev/guide/packages/lucide-vue-next - Documentation
*
* @param {Object} props - Lucide icons props and any valid SVG attribute
* @returns {FunctionalComponent} Vue component
* ${deprecated ? '@deprecated' : ''}
*/
const ${componentName} = createLucideIcon('${componentName}Icon', ${JSON.stringify(children)});
export default ${componentName};
`;
};
23 changes: 21 additions & 2 deletions packages/lucide-vue/scripts/exportTemplate.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
export default ({ componentName, children }) => `
import createVueComponent from '../createVueComponent';
/* eslint-disable import/no-extraneous-dependencies */
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';

export default ({ componentName, iconName, children, getSvg, deprecated }) => {
const svgContents = getSvg();
const svgBase64 = base64SVG(svgContents);

return `
import createLucideIcon from '../createLucideIcon';
/**
* @component @name ${componentName}
* @description Lucide SVG icon component, renders SVG Element with children.
*
* @preview ![img](data:image/svg+xml;base64,${svgBase64}) - https://lucide.dev/icons/${iconName}
* @see https://lucide.dev/guide/packages/lucide-vue - Documentation
*
* @param {Object} props - Lucide icons props and any valid SVG attribute
* @returns {Component} Vue Component
* ${deprecated ? '@deprecated' : ''}
*/
const ${componentName} = createVueComponent('${componentName}Icon', ${JSON.stringify(children)});
export default ${componentName};
`;
};
20 changes: 19 additions & 1 deletion packages/lucide/scripts/exportTemplate.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
export default ({ componentName, children }) => `
/* eslint-disable import/no-extraneous-dependencies */
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';

export default ({ componentName, iconName, children, getSvg, deprecated }) => {
const svgContents = getSvg();
const svgBase64 = base64SVG(svgContents);

return `
import defaultAttributes from '../defaultAttributes';
import type { IconNode } from '../types';
/**
* @name ${iconName}
* @description Lucide SVG icon node.
*
* @preview ![img](data:image/svg+xml;base64,${svgBase64}) - https://lucide.dev/icons/${iconName}
* @see https://lucide.dev/guide/packages/lucide - Documentation
*
* @returns {Array}
* ${deprecated ? '@deprecated' : ''}
*/
const ${componentName}: IconNode = [
'svg',
defaultAttributes,
Expand All @@ -10,3 +27,4 @@ const ${componentName}: IconNode = [
export default ${componentName};
`;
};
2 changes: 1 addition & 1 deletion tools/build-icons/index.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// eslint-disable-next-line import/prefer-default-export
export { default as getAliases } from './utils/getAliases.mjs';
export { default as getIconMetaData } from './utils/getIconMetaData.mjs';

0 comments on commit 4db0fff

Please sign in to comment.