Skip to content

Commit

Permalink
Add block comment to lucide-static
Browse files Browse the repository at this point in the history
  • Loading branch information
ericfennis committed Jan 5, 2024
1 parent 1f2b477 commit ae4842d
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 25 deletions.
18 changes: 14 additions & 4 deletions packages/lucide-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,27 @@
"Fontawesome",
"Font Awesome"
],
"main": "lib/index.js",
"source": "src/lucide-static.js",
"main": "dist/cjs/lucide-static.js",
"module": "dist/esm/lucide-static.js",
"typings": "dist/lucide-static.d.ts",
"sideEffects": false,
"scripts": {
"copy:license": "cp ../../LICENSE ./LICENSE",
"build:tags": "node ../../scripts/migrateIconsToTags.mjs",
"build": "pnpm clean && pnpm copy:license && pnpm build:lib && pnpm build:tags",
"build": "pnpm clean && pnpm copy:license && pnpm build:icons && pnpm build:bundles && pnpm build:lib && pnpm build:tags",
"build:tags": "bun ../../scripts/migrateIconsToTags.mjs",
"build:icons": "build-icons --output=./src --templateSrc=./scripts/exportTemplate.mjs --iconFileExtension=.ts --withAliases --aliasNamesOnly --aliasesFileExtension=.ts --exportFileName=index.ts",
"build:lib": "node ./scripts/buildLib.mjs",
"build:bundles": "rollup -c rollup.config.mjs",
"clean": "rm -rf lib && rm -rf build && rm -rf icons && rm -f sprite.svg",
"version": "pnpm version --git-tag-version=false"
},
"devDependencies": {
"prettier": "^2.3.2",
"svgson": "^5.2.1"
"svgson": "^5.2.1",
"@lucide/build-icons": "workspace:*",
"@lucide/rollup-plugins": "workspace:*",
"rollup": "^4.9.2",
"rollup-plugin-dts": "^6.1.0"
}
}
59 changes: 59 additions & 0 deletions packages/lucide-static/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import plugins from '@lucide/rollup-plugins';
import dts from 'rollup-plugin-dts';
import pkg from './package.json' assert { type: 'json' };

const outputFileName = pkg.name;
const outputDir = 'dist';
const inputs = ['src/lucide-static.ts'];
const bundles = [
{
format: 'cjs',
inputs,
outputDir,
},
{
format: 'esm',
inputs,
outputDir,
preserveModules: true,
},
];

const configs = bundles
.map(({ inputs, outputDir, format, minify, preserveModules }) =>
inputs.map(input => ({
input,
plugins: plugins(pkg, minify),
output: {
name: outputFileName,
...(preserveModules
? {
dir: `${outputDir}/${format}`,
}
: {
file: `${outputDir}/${format}/${outputFileName}${minify ? '.min' : ''}.js`,
}),
format,
sourcemap: true,
preserveModules,
},
})),
)
.flat();

const typesFileConfig = {
input: inputs[0],
output: [
{
file: `${outputDir}/${outputFileName}.d.ts`,
format: 'esm',
},
],
plugins: [
dts({
include: ['src'],
}),
],
};

export default [...configs, typesFileConfig];
18 changes: 0 additions & 18 deletions packages/lucide-static/scripts/buildLib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import getArgumentOptions from 'minimist';
import { parseSync } from 'svgson';

import {
appendFile,
readSvgDirectory,
toCamelCase,
getCurrentDirPath,
} from '../../../scripts/helpers.mjs';
import readSvgs from './readSvgs.mjs';
Expand Down Expand Up @@ -39,22 +37,6 @@ createDirectory(ICON_MODULE_DIR);
const svgFiles = readSvgDirectory(ICONS_DIR);
const svgs = readSvgs(svgFiles, ICONS_DIR);

const jsLicense = `/**\n * ${license}\n */\n`;

appendFile(jsLicense, `index.js`, LIB_DIR);

svgs.forEach(({ name, contents }) => {
const componentName = toCamelCase(name);
const importString = `module.exports.${componentName} = require('./icons/${name}');\n`;
appendFile(importString, `index.js`, LIB_DIR);

const svgContent = contents.replace('<svg', `<svg
class="lucide lucide-${name}"`);

const exportString = `${jsLicense}module.exports = \`${svgContent}\`;\n`;
appendFile(exportString, `${name}.js`, ICON_MODULE_DIR);
});

const parsedSvgs = svgs.map(({ name, contents }) => ({
name,
contents,
Expand Down
32 changes: 32 additions & 0 deletions packages/lucide-static/scripts/exportTemplate.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable import/no-extraneous-dependencies */
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';

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

svgContents = svgContents.replace(
'<svg',
`
<svg
class="lucide lucide-${iconName}"`,
);

return `
/**
* @name ${iconName}
* @description Lucide SVG string.
*
* @preview ![img](data:image/svg+xml;base64,${svgBase64}) - https://lucide.dev/icons/${iconName}
* @see https://lucide.dev/guide/packages/lucide-static - Documentation
*
* @returns {String}
* ${deprecated ? '@deprecated' : ''}
*/
const ${componentName}: string = \`\
${svgContents}\
\`
export default ${componentName};
`;
};
2 changes: 2 additions & 0 deletions packages/lucide-static/src/lucide-static.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './icons'
export * from './aliases';
17 changes: 17 additions & 0 deletions packages/lucide-static/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"strict": true,
"declaration": true,
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"module": "ESNext",
"target": "ESNext",
"esModuleInterop": true,
"allowJs": true,
"lib": ["esnext", "dom"],
"resolveJsonModule": true,
"sourceMap": true,
"outDir": "./dist",
}
}
18 changes: 15 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ae4842d

Please sign in to comment.