mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-16 07:27:42 +01:00
ci: Improve build speeds (#2778)
* Revert sync to async functions * Replace more sync fs functions * Format files * Fix build svelte package
This commit is contained in:
@@ -1,16 +1,17 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
const currentDir = process.cwd();
|
const currentDir = process.cwd();
|
||||||
const dataDirectory = path.resolve(currentDir, '.vitepress/data');
|
const dataDirectory = path.resolve(currentDir, '.vitepress/data');
|
||||||
const directory = path.join(process.cwd(), '../categories');
|
const directory = path.join(process.cwd(), '../categories');
|
||||||
|
|
||||||
function getAllCategoryFiles() {
|
async function getAllCategoryFiles() {
|
||||||
const fileNames = fs.readdirSync(directory).filter((file) => path.extname(file) === '.json');
|
const categoryDirectoryContents = await fs.readdir(directory);
|
||||||
|
const fileNames = categoryDirectoryContents.filter((file) => path.extname(file) === '.json');
|
||||||
|
|
||||||
return fileNames.map((fileName) => {
|
const categoryJSONReadPromises = fileNames.map(async (fileName) => {
|
||||||
const name = path.basename(fileName, '.json');
|
const name = path.basename(fileName, '.json');
|
||||||
const fileContent = fs.readFileSync(path.join(directory, fileName), 'utf8');
|
const fileContent = await fs.readFile(path.join(directory, fileName), 'utf8');
|
||||||
|
|
||||||
const parsedFileContent = JSON.parse(fileContent);
|
const parsedFileContent = JSON.parse(fileContent);
|
||||||
|
|
||||||
@@ -19,14 +20,15 @@ function getAllCategoryFiles() {
|
|||||||
title: parsedFileContent.title,
|
title: parsedFileContent.title,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return Promise.all(categoryJSONReadPromises);
|
||||||
}
|
}
|
||||||
|
|
||||||
const categoriesFile = path.resolve(dataDirectory, `categoriesData.json`);
|
const categoriesFile = path.resolve(dataDirectory, `categoriesData.json`);
|
||||||
|
|
||||||
const categoriesData = getAllCategoryFiles();
|
const categoriesData = await getAllCategoryFiles();
|
||||||
|
|
||||||
fs.promises
|
fs.writeFile(categoriesFile, JSON.stringify(categoriesData, null, 2), 'utf-8')
|
||||||
.writeFile(categoriesFile, JSON.stringify(categoriesData, null, 2), 'utf-8')
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('Successfully written categoriesData.json file');
|
console.log('Successfully written categoriesData.json file');
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { readSvgDirectory, toCamelCase } from '@lucide/helpers';
|
|||||||
|
|
||||||
const currentDir = process.cwd();
|
const currentDir = process.cwd();
|
||||||
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
||||||
const icons = readSvgDirectory(ICONS_DIR, '.json');
|
const icons = await readSvgDirectory(ICONS_DIR, '.json');
|
||||||
|
|
||||||
const iconDetailsDirectory = path.resolve(currentDir, '.vitepress/data', 'iconDetails');
|
const iconDetailsDirectory = path.resolve(currentDir, '.vitepress/data', 'iconDetails');
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { readSvgDirectory, toCamelCase } from '@lucide/helpers';
|
|||||||
|
|
||||||
const currentDir = process.cwd();
|
const currentDir = process.cwd();
|
||||||
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
||||||
const iconJsonFiles = readSvgDirectory(ICONS_DIR, '.json');
|
const iconJsonFiles = await readSvgDirectory(ICONS_DIR, '.json');
|
||||||
|
|
||||||
const location = path.resolve(currentDir, '.vitepress/data', 'iconMetaData.ts');
|
const location = path.resolve(currentDir, '.vitepress/data', 'iconMetaData.ts');
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import { readSvgDirectory, toCamelCase } from '@lucide/helpers';
|
|||||||
|
|
||||||
const currentDir = process.cwd();
|
const currentDir = process.cwd();
|
||||||
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
||||||
const svgFiles = readSvgDirectory(ICONS_DIR);
|
const svgFiles = await readSvgDirectory(ICONS_DIR);
|
||||||
const icons = renderIconsObject(svgFiles, ICONS_DIR, true);
|
const icons = await renderIconsObject(svgFiles, ICONS_DIR, true);
|
||||||
|
|
||||||
const iconNodesDirectory = path.resolve(currentDir, '.vitepress/data', 'iconNodes');
|
const iconNodesDirectory = path.resolve(currentDir, '.vitepress/data', 'iconNodes');
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ const writeIconFiles = Object.entries(icons).map(async ([iconName, { children }]
|
|||||||
await fs.promises.writeFile(location, output, 'utf-8');
|
await fs.promises.writeFile(location, output, 'utf-8');
|
||||||
|
|
||||||
iconIndexFileImports.push(
|
iconIndexFileImports.push(
|
||||||
`import ${toCamelCase(iconName)}Node from './${iconName}.node.json' assert { type: "json" };`,
|
`import ${toCamelCase(iconName)}Node from './${iconName}.node.json' with { type: "json" };`,
|
||||||
);
|
);
|
||||||
iconIndexFileExports.push(` ${toCamelCase(iconName)}Node as ${toCamelCase(iconName)},`);
|
iconIndexFileExports.push(` ${toCamelCase(iconName)}Node as ${toCamelCase(iconName)},`);
|
||||||
iconIndexFileDefaultExports.push(` '${iconName}': ${toCamelCase(iconName)}Node,`);
|
iconIndexFileDefaultExports.push(` '${iconName}': ${toCamelCase(iconName)}Node,`);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { readSvgDirectory } from '@lucide/helpers';
|
|||||||
|
|
||||||
const currentDir = process.cwd();
|
const currentDir = process.cwd();
|
||||||
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
||||||
const svgFiles = readSvgDirectory(ICONS_DIR, '.json');
|
const svgFiles = await readSvgDirectory(ICONS_DIR, '.json');
|
||||||
|
|
||||||
const location = path.resolve(currentDir, '.vitepress/data', 'relatedIcons.json');
|
const location = path.resolve(currentDir, '.vitepress/data', 'relatedIcons.json');
|
||||||
|
|
||||||
@@ -18,9 +18,7 @@ const categoryWeight = 3;
|
|||||||
|
|
||||||
const MAX_RELATED_ICONS = 4 * 17; // grid of 4x17 icons, = 68 icons
|
const MAX_RELATED_ICONS = 4 * 17; // grid of 4x17 icons, = 68 icons
|
||||||
|
|
||||||
const arrayMatches = (a, b) => {
|
const arrayMatches = (a, b) => a.filter((item) => b.includes(item)).length;
|
||||||
return a.filter((item) => b.includes(item)).length;
|
|
||||||
};
|
|
||||||
|
|
||||||
const nameParts = (icon) =>
|
const nameParts = (icon) =>
|
||||||
[
|
[
|
||||||
@@ -36,6 +34,7 @@ const getRelatedIcons = (currentIcon, icons) => {
|
|||||||
nameWeight * arrayMatches(nameParts(item), nameParts(currentIcon)) +
|
nameWeight * arrayMatches(nameParts(item), nameParts(currentIcon)) +
|
||||||
categoryWeight * arrayMatches(item.categories ?? [], currentIcon.categories ?? []) +
|
categoryWeight * arrayMatches(item.categories ?? [], currentIcon.categories ?? []) +
|
||||||
tagWeight * arrayMatches(item.tags ?? [], currentIcon.tags ?? []);
|
tagWeight * arrayMatches(item.tags ?? [], currentIcon.tags ?? []);
|
||||||
|
|
||||||
return icons
|
return icons
|
||||||
.filter((i) => i.name !== currentIcon.name)
|
.filter((i) => i.name !== currentIcon.name)
|
||||||
.map((icon) => ({ icon, similarity: iconSimilarity(icon) }))
|
.map((icon) => ({ icon, similarity: iconSimilarity(icon) }))
|
||||||
@@ -46,7 +45,8 @@ const getRelatedIcons = (currentIcon, icons) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const iconsMetaDataPromises = svgFiles.map(async (iconName) => {
|
const iconsMetaDataPromises = svgFiles.map(async (iconName) => {
|
||||||
const metaData = JSON.parse(fs.readFileSync(`../icons/${iconName}`));
|
const metaDataFileContent = await fs.promises.readFile(`../icons/${iconName}`);
|
||||||
|
const metaData = JSON.parse(metaDataFileContent);
|
||||||
|
|
||||||
const name = iconName.replace('.json', '');
|
const name = iconName.replace('.json', '');
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const git = simpleGit();
|
|||||||
|
|
||||||
const currentDir = process.cwd();
|
const currentDir = process.cwd();
|
||||||
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
||||||
const iconJsonFiles = readSvgDirectory(ICONS_DIR, '.json');
|
const iconJsonFiles = await readSvgDirectory(ICONS_DIR, '.json');
|
||||||
const location = path.resolve(currentDir, '.vitepress/data', 'releaseMetaData.json');
|
const location = path.resolve(currentDir, '.vitepress/data', 'releaseMetaData.json');
|
||||||
const releaseMetaDataDirectory = path.resolve(currentDir, '.vitepress/data', 'releaseMetadata');
|
const releaseMetaDataDirectory = path.resolve(currentDir, '.vitepress/data', 'releaseMetadata');
|
||||||
|
|
||||||
|
|||||||
@@ -44,4 +44,4 @@ const output = JSON.stringify(vercelRouteConfig, null, 2);
|
|||||||
|
|
||||||
const vercelOutputJSON = path.resolve(currentDir, '.vercel/output/config.json');
|
const vercelOutputJSON = path.resolve(currentDir, '.vercel/output/config.json');
|
||||||
|
|
||||||
fs.writeFileSync(vercelOutputJSON, output, 'utf-8');
|
await fs.promises.writeFile(vercelOutputJSON, output, 'utf-8');
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
||||||
|
|
||||||
export default ({ componentName, iconName, children, getSvg, deprecated, deprecationReason }) => {
|
export default async ({
|
||||||
const svgContents = getSvg();
|
componentName,
|
||||||
|
iconName,
|
||||||
|
children,
|
||||||
|
getSvg,
|
||||||
|
deprecated,
|
||||||
|
deprecationReason,
|
||||||
|
}) => {
|
||||||
|
const svgContents = await getSvg();
|
||||||
const svgBase64 = base64SVG(svgContents);
|
const svgBase64 = base64SVG(svgContents);
|
||||||
|
|
||||||
return `\
|
return `\
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import plugins from '@lucide/rollup-plugins';
|
import plugins from '@lucide/rollup-plugins';
|
||||||
import dts from 'rollup-plugin-dts';
|
import dts from 'rollup-plugin-dts';
|
||||||
import pkg from './package.json' assert { type: 'json' };
|
import pkg from './package.json' with { type: 'json' };
|
||||||
|
|
||||||
const packageName = 'LucidePreact';
|
const packageName = 'LucidePreact';
|
||||||
const outputFileName = 'lucide-preact';
|
const outputFileName = 'lucide-preact';
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
||||||
|
|
||||||
export default ({ componentName, iconName, children, getSvg, deprecated, deprecationReason }) => {
|
export default async ({
|
||||||
const svgContents = getSvg();
|
componentName,
|
||||||
|
iconName,
|
||||||
|
children,
|
||||||
|
getSvg,
|
||||||
|
deprecated,
|
||||||
|
deprecationReason,
|
||||||
|
}) => {
|
||||||
|
const svgContents = await getSvg();
|
||||||
const svgBase64 = base64SVG(svgContents);
|
const svgBase64 = base64SVG(svgContents);
|
||||||
|
|
||||||
return `
|
return `
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
||||||
|
|
||||||
export default ({ componentName, iconName, children, getSvg, deprecated, deprecationReason }) => {
|
export default async ({
|
||||||
const svgContents = getSvg();
|
componentName,
|
||||||
|
iconName,
|
||||||
|
children,
|
||||||
|
getSvg,
|
||||||
|
deprecated,
|
||||||
|
deprecationReason,
|
||||||
|
}) => {
|
||||||
|
const svgContents = await getSvg();
|
||||||
const svgBase64 = base64SVG(svgContents);
|
const svgBase64 = base64SVG(svgContents);
|
||||||
|
|
||||||
return `
|
return `
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
||||||
|
|
||||||
export default ({ componentName, iconName, children, getSvg, deprecated, deprecationReason }) => {
|
export default async ({
|
||||||
const svgContents = getSvg();
|
componentName,
|
||||||
|
iconName,
|
||||||
|
children,
|
||||||
|
getSvg,
|
||||||
|
deprecated,
|
||||||
|
deprecationReason,
|
||||||
|
}) => {
|
||||||
|
const svgContents = await getSvg();
|
||||||
const svgBase64 = base64SVG(svgContents);
|
const svgBase64 = base64SVG(svgContents);
|
||||||
|
|
||||||
return `
|
return `
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
||||||
|
|
||||||
export default ({ componentName, iconName, children, getSvg, deprecated, deprecationReason }) => {
|
export default async ({
|
||||||
const svgContents = getSvg();
|
componentName,
|
||||||
|
iconName,
|
||||||
|
children,
|
||||||
|
getSvg,
|
||||||
|
deprecated,
|
||||||
|
deprecationReason,
|
||||||
|
}) => {
|
||||||
|
const svgContents = await getSvg();
|
||||||
const svgBase64 = base64SVG(svgContents);
|
const svgBase64 = base64SVG(svgContents);
|
||||||
|
|
||||||
return `
|
return `
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ const license = `@license ${pkg.name} v${pkg.version} - ${pkg.license}`;
|
|||||||
createDirectory(LIB_DIR);
|
createDirectory(LIB_DIR);
|
||||||
createDirectory(ICON_MODULE_DIR);
|
createDirectory(ICON_MODULE_DIR);
|
||||||
|
|
||||||
const svgFiles = readSvgDirectory(ICONS_DIR);
|
const svgFiles = await readSvgDirectory(ICONS_DIR);
|
||||||
const svgs = readSvgs(svgFiles, ICONS_DIR);
|
const svgs = await readSvgs(svgFiles, ICONS_DIR);
|
||||||
|
|
||||||
const parsedSvgs = svgs.map(({ name, contents }) => ({
|
const parsedSvgs = svgs.map(({ name, contents }) => ({
|
||||||
name,
|
name,
|
||||||
@@ -39,6 +39,8 @@ const parsedSvgs = svgs.map(({ name, contents }) => ({
|
|||||||
parsedSvg: parseSync(contents),
|
parsedSvg: parseSync(contents),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
generateSprite(parsedSvgs, PACKAGE_DIR, license);
|
await Promise.all([
|
||||||
generateIconNodes(parsedSvgs, PACKAGE_DIR);
|
generateSprite(parsedSvgs, PACKAGE_DIR, license),
|
||||||
copyIcons(parsedSvgs, PACKAGE_DIR, license);
|
generateIconNodes(parsedSvgs, PACKAGE_DIR),
|
||||||
|
copyIcons(parsedSvgs, PACKAGE_DIR, license),
|
||||||
|
]);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
||||||
|
|
||||||
export default ({ componentName, iconName, children, getSvg, deprecated, deprecationReason }) => {
|
export default async ({ componentName, iconName, getSvg, deprecated, deprecationReason }) => {
|
||||||
let svgContents = getSvg();
|
let svgContents = await getSvg();
|
||||||
const svgBase64 = base64SVG(svgContents);
|
const svgBase64 = base64SVG(svgContents);
|
||||||
|
|
||||||
svgContents = svgContents.replace(
|
svgContents = svgContents.replace(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { writeFile } from '@lucide/helpers';
|
import { writeFile } from '@lucide/helpers';
|
||||||
|
|
||||||
export default function generateIconNodes(parsedSvgs, packageDir) {
|
export default async function generateIconNodes(parsedSvgs, packageDir) {
|
||||||
const iconNodes = parsedSvgs.reduce((acc, { name, parsedSvg }) => {
|
const iconNodes = parsedSvgs.reduce((acc, { name, parsedSvg }) => {
|
||||||
acc[name] = parsedSvg.children.map(({ name, attributes }) => [name, attributes]);
|
acc[name] = parsedSvg.children.map(({ name, attributes }) => [name, attributes]);
|
||||||
|
|
||||||
@@ -9,5 +9,5 @@ export default function generateIconNodes(parsedSvgs, packageDir) {
|
|||||||
|
|
||||||
const iconNodesStringified = JSON.stringify(iconNodes, null, 2);
|
const iconNodesStringified = JSON.stringify(iconNodes, null, 2);
|
||||||
|
|
||||||
writeFile(iconNodesStringified, 'icon-nodes.json', packageDir);
|
await writeFile(iconNodesStringified, 'icon-nodes.json', packageDir);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { stringify } from 'svgson';
|
|||||||
import { format } from 'prettier';
|
import { format } from 'prettier';
|
||||||
import { appendFile } from '@lucide/helpers';
|
import { appendFile } from '@lucide/helpers';
|
||||||
|
|
||||||
export default function generateSprite(svgs, packageDir, license) {
|
export default async function generateSprite(svgs, packageDir, license) {
|
||||||
const symbols = svgs.map(({ name, parsedSvg }) => ({
|
const symbols = svgs.map(({ name, parsedSvg }) => ({
|
||||||
name: 'symbol',
|
name: 'symbol',
|
||||||
type: 'element',
|
type: 'element',
|
||||||
@@ -34,6 +34,6 @@ export default function generateSprite(svgs, packageDir, license) {
|
|||||||
|
|
||||||
const xmlMeta = `<?xml version="1.0" encoding="utf-8"?>\n<!-- ${license} -->\n`;
|
const xmlMeta = `<?xml version="1.0" encoding="utf-8"?>\n<!-- ${license} -->\n`;
|
||||||
|
|
||||||
appendFile(xmlMeta, `sprite.svg`, packageDir);
|
await appendFile(xmlMeta, `sprite.svg`, packageDir);
|
||||||
appendFile(prettifiedSprite, `sprite.svg`, packageDir);
|
await appendFile(prettifiedSprite, `sprite.svg`, packageDir);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ import { readSvg } from '@lucide/helpers';
|
|||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
export default function readSVGs(svgFiles, iconsDirectory) {
|
export default function readSVGs(svgFiles, iconsDirectory) {
|
||||||
return svgFiles.map((svgFile) => {
|
const SVGReadPromises = svgFiles.map(async (svgFile) => {
|
||||||
const name = basename(svgFile, '.svg');
|
const name = basename(svgFile, '.svg');
|
||||||
const contents = readSvg(svgFile, iconsDirectory);
|
const contents = await readSvg(svgFile, iconsDirectory);
|
||||||
|
|
||||||
return { name, contents };
|
return { name, contents };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return Promise.all(SVGReadPromises);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
"build:icons": "build-icons --output=./src --templateSrc=./scripts/exportTemplate.mjs --exportFileName=index.ts --iconFileExtension=.svelte --importImportFileExtension=.svelte --separateIconFileExport --separateIconFileExportExtension=.ts --withAliases --aliasesFileExtension=.ts --separateAliasesFile --separateAliasesFileExtension=.ts --aliasImportFileExtension=.js --pretty=false",
|
"build:icons": "build-icons --output=./src --templateSrc=./scripts/exportTemplate.mjs --exportFileName=index.ts --iconFileExtension=.svelte --importImportFileExtension=.svelte --separateIconFileExport --separateIconFileExportExtension=.ts --withAliases --aliasesFileExtension=.ts --separateAliasesFile --separateAliasesFileExtension=.ts --aliasImportFileExtension=.js --pretty=false",
|
||||||
"build:package": "svelte-package --input ./src",
|
"build:package": "svelte-package --input ./src",
|
||||||
"build:license": "node ./scripts/appendBlockComments.mjs",
|
"build:license": "node ./scripts/appendBlockComments.mjs",
|
||||||
"test": "pnpm build:icons && vitest run",
|
"test": "pnpm copy:license && pnpm build:icons && vitest run",
|
||||||
"test:watch": "vitest watch",
|
"test:watch": "vitest watch",
|
||||||
"version": "pnpm version --git-tag-version=false"
|
"version": "pnpm version --git-tag-version=false"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import path from 'path';
|
|||||||
import { getCurrentDirPath } from '@lucide/helpers';
|
import { getCurrentDirPath } from '@lucide/helpers';
|
||||||
import { getJSBanner } from './license.mjs';
|
import { getJSBanner } from './license.mjs';
|
||||||
|
|
||||||
const currentDir = getCurrentDirPath(import.meta.url);
|
const currentDir = await getCurrentDirPath(import.meta.url);
|
||||||
const targetDirectory = path.join(currentDir, '../dist');
|
const targetDirectory = path.join(currentDir, '../dist');
|
||||||
|
|
||||||
const files = await readdir(targetDirectory, {
|
const files = await readdir(targetDirectory, {
|
||||||
|
|||||||
@@ -2,8 +2,15 @@
|
|||||||
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
||||||
import { getJSBanner } from './license.mjs';
|
import { getJSBanner } from './license.mjs';
|
||||||
|
|
||||||
export default ({ iconName, children, componentName, getSvg, deprecated, deprecationReason }) => {
|
export default async ({
|
||||||
const svgContents = getSvg();
|
iconName,
|
||||||
|
children,
|
||||||
|
componentName,
|
||||||
|
getSvg,
|
||||||
|
deprecated,
|
||||||
|
deprecationReason,
|
||||||
|
}) => {
|
||||||
|
const svgContents = await getSvg();
|
||||||
const svgBase64 = base64SVG(svgContents);
|
const svgBase64 = base64SVG(svgContents);
|
||||||
|
|
||||||
return `\
|
return `\
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
||||||
|
|
||||||
export default ({ componentName, iconName, children, getSvg, deprecated, deprecationReason }) => {
|
export default async ({
|
||||||
const svgContents = getSvg();
|
componentName,
|
||||||
|
iconName,
|
||||||
|
children,
|
||||||
|
getSvg,
|
||||||
|
deprecated,
|
||||||
|
deprecationReason,
|
||||||
|
}) => {
|
||||||
|
const svgContents = await getSvg();
|
||||||
const svgBase64 = base64SVG(svgContents);
|
const svgBase64 = base64SVG(svgContents);
|
||||||
|
|
||||||
return `
|
return `
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
||||||
|
|
||||||
export default ({ componentName, iconName, children, getSvg, deprecated, deprecationReason }) => {
|
export default async ({
|
||||||
const svgContents = getSvg();
|
componentName,
|
||||||
|
iconName,
|
||||||
|
children,
|
||||||
|
getSvg,
|
||||||
|
deprecated,
|
||||||
|
deprecationReason,
|
||||||
|
}) => {
|
||||||
|
const svgContents = await getSvg();
|
||||||
const svgBase64 = base64SVG(svgContents);
|
const svgBase64 = base64SVG(svgContents);
|
||||||
|
|
||||||
return `
|
return `
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
import base64SVG from '@lucide/build-icons/utils/base64SVG.mjs';
|
||||||
|
|
||||||
export default ({ componentName, iconName, children, getSvg, deprecated, deprecationReason }) => {
|
export default async ({
|
||||||
const svgContents = getSvg();
|
componentName,
|
||||||
|
iconName,
|
||||||
|
children,
|
||||||
|
getSvg,
|
||||||
|
deprecated,
|
||||||
|
deprecationReason,
|
||||||
|
}) => {
|
||||||
|
const svgContents = await getSvg();
|
||||||
const svgBase64 = base64SVG(svgContents);
|
const svgBase64 = base64SVG(svgContents);
|
||||||
|
|
||||||
return `
|
return `
|
||||||
|
|||||||
24
pnpm-lock.yaml
generated
24
pnpm-lock.yaml
generated
@@ -704,9 +704,6 @@ importers:
|
|||||||
|
|
||||||
tools/build-icons:
|
tools/build-icons:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@lucide/helpers':
|
|
||||||
specifier: ^1.0.0
|
|
||||||
version: 1.0.0
|
|
||||||
minimist:
|
minimist:
|
||||||
specifier: ^1.2.7
|
specifier: ^1.2.7
|
||||||
version: 1.2.8
|
version: 1.2.8
|
||||||
@@ -722,6 +719,10 @@ importers:
|
|||||||
svgson:
|
svgson:
|
||||||
specifier: ^5.2.1
|
specifier: ^5.2.1
|
||||||
version: 5.3.1
|
version: 5.3.1
|
||||||
|
devDependencies:
|
||||||
|
'@lucide/helpers':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../build-helpers
|
||||||
|
|
||||||
tools/outline-svg:
|
tools/outline-svg:
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -3298,9 +3299,6 @@ packages:
|
|||||||
'@lezer/lr@1.3.10':
|
'@lezer/lr@1.3.10':
|
||||||
resolution: {integrity: sha512-BZfVvf7Re5BIwJHlZXbJn9L8lus5EonxQghyn+ih8Wl36XMFBPTXC0KM0IdUtj9w/diPHsKlXVgL+AlX2jYJ0Q==}
|
resolution: {integrity: sha512-BZfVvf7Re5BIwJHlZXbJn9L8lus5EonxQghyn+ih8Wl36XMFBPTXC0KM0IdUtj9w/diPHsKlXVgL+AlX2jYJ0Q==}
|
||||||
|
|
||||||
'@lucide/helpers@1.0.0':
|
|
||||||
resolution: {integrity: sha512-9dfxrgLLaoCfr3R/eh6wwlUcY+ZPdEv6SDwFMUhYoO6HhGL8yN8hb5ZwI/OfzbK9mdJpa+jYfwP4nF4ZlZwZLA==}
|
|
||||||
|
|
||||||
'@mapbox/node-pre-gyp@1.0.11':
|
'@mapbox/node-pre-gyp@1.0.11':
|
||||||
resolution: {integrity: sha512-Yhlar6v9WQgUp/He7BdgzOz8lqMQ8sU+jkCq7Wx8Myc5YFJLbEe7lgui/V7G1qB1DJykHSGwreceSaD60Y0PUQ==}
|
resolution: {integrity: sha512-Yhlar6v9WQgUp/He7BdgzOz8lqMQ8sU+jkCq7Wx8Myc5YFJLbEe7lgui/V7G1qB1DJykHSGwreceSaD60Y0PUQ==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
@@ -15810,8 +15808,6 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@lezer/common': 1.2.1
|
'@lezer/common': 1.2.1
|
||||||
|
|
||||||
'@lucide/helpers@1.0.0': {}
|
|
||||||
|
|
||||||
'@mapbox/node-pre-gyp@1.0.11(encoding@0.1.13)':
|
'@mapbox/node-pre-gyp@1.0.11(encoding@0.1.13)':
|
||||||
dependencies:
|
dependencies:
|
||||||
detect-libc: 2.0.2
|
detect-libc: 2.0.2
|
||||||
@@ -17591,18 +17587,6 @@ snapshots:
|
|||||||
postcss: 8.4.49
|
postcss: 8.4.49
|
||||||
source-map: 0.6.1
|
source-map: 0.6.1
|
||||||
|
|
||||||
'@vue/compiler-sfc@3.4.18':
|
|
||||||
dependencies:
|
|
||||||
'@babel/parser': 7.23.9
|
|
||||||
'@vue/compiler-core': 3.4.18
|
|
||||||
'@vue/compiler-dom': 3.4.18
|
|
||||||
'@vue/compiler-ssr': 3.4.18
|
|
||||||
'@vue/shared': 3.4.18
|
|
||||||
estree-walker: 2.0.2
|
|
||||||
magic-string: 0.30.11
|
|
||||||
postcss: 8.4.41
|
|
||||||
source-map-js: 1.2.1
|
|
||||||
|
|
||||||
'@vue/compiler-sfc@3.4.21':
|
'@vue/compiler-sfc@3.4.21':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/parser': 7.26.1
|
'@babel/parser': 7.26.1
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import categories from '../categories.json' assert { type: 'json' };
|
import categories from '../categories.json' with { type: 'json' };
|
||||||
import {
|
import {
|
||||||
mergeArrays,
|
mergeArrays,
|
||||||
writeFile,
|
writeFile,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { writeFile, getCurrentDirPath, readAllMetadata } from '../tools/build-he
|
|||||||
|
|
||||||
const currentDir = getCurrentDirPath(import.meta.url);
|
const currentDir = getCurrentDirPath(import.meta.url);
|
||||||
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
||||||
const icons = readAllMetadata(ICONS_DIR);
|
const icons = await readAllMetadata(ICONS_DIR);
|
||||||
|
|
||||||
const tags = Object.keys(icons)
|
const tags = Object.keys(icons)
|
||||||
.sort()
|
.sort()
|
||||||
@@ -14,4 +14,4 @@ const tags = Object.keys(icons)
|
|||||||
|
|
||||||
const tagsContent = JSON.stringify(tags, null, 2);
|
const tagsContent = JSON.stringify(tags, null, 2);
|
||||||
|
|
||||||
writeFile(tagsContent, 'tags.json', path.resolve(process.cwd()));
|
await writeFile(tagsContent, 'tags.json', path.resolve(process.cwd()));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable import/prefer-default-export */
|
/* eslint-disable import/prefer-default-export */
|
||||||
import fs from 'fs';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,4 +10,4 @@ import path from 'path';
|
|||||||
* @param {string} outputDirectory
|
* @param {string} outputDirectory
|
||||||
*/
|
*/
|
||||||
export const appendFile = (content, fileName, outputDirectory) =>
|
export const appendFile = (content, fileName, outputDirectory) =>
|
||||||
fs.appendFileSync(path.join(outputDirectory, fileName), content, 'utf-8');
|
fs.appendFile(path.join(outputDirectory, fileName), content, 'utf-8');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable import/prefer-default-export */
|
/* eslint-disable import/prefer-default-export */
|
||||||
import fs from 'fs';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { readMetadata } from './readMetadata.mjs';
|
import { readMetadata } from './readMetadata.mjs';
|
||||||
|
|
||||||
@@ -9,11 +9,13 @@ import { readMetadata } from './readMetadata.mjs';
|
|||||||
* @param {string} directory
|
* @param {string} directory
|
||||||
* @returns {object} A map of icon or category metadata
|
* @returns {object} A map of icon or category metadata
|
||||||
*/
|
*/
|
||||||
export const readAllMetadata = (directory) =>
|
export const readAllMetadata = async (directory) => {
|
||||||
fs
|
const directoryContent = await fs.readdir(directory);
|
||||||
.readdirSync(directory)
|
|
||||||
|
return directoryContent
|
||||||
.filter((file) => path.extname(file) === '.json')
|
.filter((file) => path.extname(file) === '.json')
|
||||||
.reduce((acc, fileName) => {
|
.reduce((acc, fileName) => {
|
||||||
acc[path.basename(fileName, '.json')] = readMetadata(fileName, directory);
|
acc[path.basename(fileName, '.json')] = readMetadata(fileName, directory);
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable import/prefer-default-export */
|
/* eslint-disable import/prefer-default-export */
|
||||||
import fs from 'fs';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,4 +8,4 @@ import path from 'path';
|
|||||||
* @param {string} path
|
* @param {string} path
|
||||||
* @returns {string} The contents of a file
|
* @returns {string} The contents of a file
|
||||||
*/
|
*/
|
||||||
export const readFile = (path) => fs.readFileSync(path.resolve(__dirname, '../', path), 'utf-8');
|
export const readFile = (path) => fs.readFile(path.resolve(__dirname, '../', path), 'utf-8');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable import/prefer-default-export */
|
/* eslint-disable import/prefer-default-export */
|
||||||
import fs from 'fs';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,5 +9,8 @@ import path from 'path';
|
|||||||
* @param {string} directory
|
* @param {string} directory
|
||||||
* @returns {object} The metadata for the icon or category
|
* @returns {object} The metadata for the icon or category
|
||||||
*/
|
*/
|
||||||
export const readMetadata = (fileName, directory) =>
|
export const readMetadata = async (fileName, directory) => {
|
||||||
JSON.parse(fs.readFileSync(path.join(directory, fileName), 'utf-8'));
|
const metadataFileContent = await fs.readFile(path.join(directory, fileName), 'utf-8');
|
||||||
|
|
||||||
|
return JSON.parse(metadataFileContent);
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable import/prefer-default-export */
|
/* eslint-disable import/prefer-default-export */
|
||||||
import fs from 'fs';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,4 +9,4 @@ import path from 'path';
|
|||||||
* @param {string} directory
|
* @param {string} directory
|
||||||
*/
|
*/
|
||||||
export const readSvg = (fileName, directory) =>
|
export const readSvg = (fileName, directory) =>
|
||||||
fs.readFileSync(path.join(directory, fileName), 'utf-8');
|
fs.readFile(path.join(directory, fileName), 'utf-8');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable import/prefer-default-export */
|
/* eslint-disable import/prefer-default-export */
|
||||||
import fs from 'fs';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,5 +9,8 @@ import path from 'path';
|
|||||||
* @param {string} fileExtension
|
* @param {string} fileExtension
|
||||||
* @returns {array} An array of file paths containing svgs
|
* @returns {array} An array of file paths containing svgs
|
||||||
*/
|
*/
|
||||||
export const readSvgDirectory = (directory, fileExtension = '.svg') =>
|
export const readSvgDirectory = async (directory, fileExtension = '.svg') => {
|
||||||
fs.readdirSync(directory).filter((file) => path.extname(file) === fileExtension);
|
const directoryContents = await fs.readdir(directory);
|
||||||
|
|
||||||
|
return directoryContents.filter((file) => path.extname(file) === fileExtension);
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable import/prefer-default-export */
|
/* eslint-disable import/prefer-default-export */
|
||||||
import fs from 'fs';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,4 +9,4 @@ import path from 'path';
|
|||||||
* @param {string} outputDirectory
|
* @param {string} outputDirectory
|
||||||
*/
|
*/
|
||||||
export const resetFile = (fileName, outputDirectory) =>
|
export const resetFile = (fileName, outputDirectory) =>
|
||||||
fs.writeFileSync(path.join(outputDirectory, fileName), '', 'utf-8');
|
fs.writeFile(path.join(outputDirectory, fileName), '', 'utf-8');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable import/prefer-default-export */
|
/* eslint-disable import/prefer-default-export */
|
||||||
import fs from 'fs';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,4 +10,4 @@ import path from 'path';
|
|||||||
* @param {string} outputDirectory
|
* @param {string} outputDirectory
|
||||||
*/
|
*/
|
||||||
export const writeFile = (content, fileName, outputDirectory) =>
|
export const writeFile = (content, fileName, outputDirectory) =>
|
||||||
fs.writeFileSync(path.join(outputDirectory, fileName), content, 'utf-8');
|
fs.writeFile(path.join(outputDirectory, fileName), content, 'utf-8');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable import/prefer-default-export */
|
/* eslint-disable import/prefer-default-export */
|
||||||
import fs from 'fs';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { writeFile } from './writeFile.mjs';
|
import { writeFile } from './writeFile.mjs';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable import/prefer-default-export */
|
/* eslint-disable import/prefer-default-export */
|
||||||
import fs from 'fs';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,4 +10,4 @@ import path from 'path';
|
|||||||
* @param {string} content
|
* @param {string} content
|
||||||
*/
|
*/
|
||||||
export const writeSvgFile = (fileName, outputDirectory, content) =>
|
export const writeSvgFile = (fileName, outputDirectory, content) =>
|
||||||
fs.writeFileSync(path.join(outputDirectory, fileName), content, 'utf-8');
|
fs.writeFile(path.join(outputDirectory, fileName), content, 'utf-8');
|
||||||
|
|||||||
@@ -31,11 +31,11 @@ export default async function generateAliasesFiles({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reset files
|
// Reset files
|
||||||
resetFile(aliasFileName, destinationDirectory);
|
await resetFile(aliasFileName, destinationDirectory);
|
||||||
|
|
||||||
if (!aliasNamesOnly) {
|
if (!aliasNamesOnly) {
|
||||||
resetFile(aliasPrefixesFileName, destinationDirectory);
|
await resetFile(aliasPrefixesFileName, destinationDirectory);
|
||||||
resetFile(aliasSuffixFileName, destinationDirectory);
|
await resetFile(aliasSuffixFileName, destinationDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate Import for Icon VNodes
|
// Generate Import for Icon VNodes
|
||||||
@@ -149,20 +149,20 @@ export default async function generateAliasesFiles({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
appendFile(aliasFileContent, aliasFileName, destinationDirectory);
|
await appendFile(aliasFileContent, aliasFileName, destinationDirectory);
|
||||||
|
|
||||||
if (!aliasNamesOnly) {
|
if (!aliasNamesOnly) {
|
||||||
appendFile(aliasPrefixesFileContent, aliasPrefixesFileName, destinationDirectory);
|
await appendFile(aliasPrefixesFileContent, aliasPrefixesFileName, destinationDirectory);
|
||||||
appendFile(aliasSuffixFileContent, aliasSuffixFileName, destinationDirectory);
|
await appendFile(aliasSuffixFileContent, aliasSuffixFileName, destinationDirectory);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
appendFile('\n', aliasFileName, destinationDirectory);
|
await appendFile('\n', aliasFileName, destinationDirectory);
|
||||||
|
|
||||||
if (!aliasNamesOnly) {
|
if (!aliasNamesOnly) {
|
||||||
appendFile('\n', aliasPrefixesFileName, destinationDirectory);
|
await appendFile('\n', aliasPrefixesFileName, destinationDirectory);
|
||||||
appendFile('\n', aliasSuffixFileName, destinationDirectory);
|
await appendFile('\n', aliasSuffixFileName, destinationDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showLog) {
|
if (showLog) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { resetFile, appendFile } from '@lucide/helpers';
|
import { resetFile, appendFile } from '@lucide/helpers';
|
||||||
|
|
||||||
export default function generateDynamicImports({
|
export default async function generateDynamicImports({
|
||||||
iconNodes,
|
iconNodes,
|
||||||
outputDirectory,
|
outputDirectory,
|
||||||
fileExtension,
|
fileExtension,
|
||||||
@@ -12,7 +12,7 @@ export default function generateDynamicImports({
|
|||||||
const icons = Object.keys(iconNodes);
|
const icons = Object.keys(iconNodes);
|
||||||
|
|
||||||
// Reset file
|
// Reset file
|
||||||
resetFile(fileName, outputDirectory);
|
await resetFile(fileName, outputDirectory);
|
||||||
|
|
||||||
let importString = `const dynamicIconImports = {\n`;
|
let importString = `const dynamicIconImports = {\n`;
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ export default function generateDynamicImports({
|
|||||||
|
|
||||||
importString += '};\nexport default dynamicIconImports;\n';
|
importString += '};\nexport default dynamicIconImports;\n';
|
||||||
|
|
||||||
appendFile(importString, fileName, outputDirectory);
|
await appendFile(importString, fileName, outputDirectory);
|
||||||
|
|
||||||
if (showLog) {
|
if (showLog) {
|
||||||
console.log(`Successfully generated ${fileName} file`);
|
console.log(`Successfully generated ${fileName} file`);
|
||||||
|
|||||||
@@ -3,22 +3,22 @@ import path from 'path';
|
|||||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
import { toPascalCase, toCamelCase, resetFile, appendFile } from '@lucide/helpers';
|
import { toPascalCase, toCamelCase, resetFile, appendFile } from '@lucide/helpers';
|
||||||
|
|
||||||
export default (
|
export default async function generateExportFile(
|
||||||
inputEntry,
|
inputEntry,
|
||||||
outputDirectory,
|
outputDirectory,
|
||||||
iconNodes,
|
iconNodes,
|
||||||
exportModuleNameCasing,
|
exportModuleNameCasing,
|
||||||
iconFileExtension = '',
|
iconFileExtension = '',
|
||||||
) => {
|
) {
|
||||||
const fileName = path.basename(inputEntry);
|
const fileName = path.basename(inputEntry);
|
||||||
|
|
||||||
// Reset file
|
// Reset file
|
||||||
resetFile(fileName, outputDirectory);
|
await resetFile(fileName, outputDirectory);
|
||||||
|
|
||||||
const icons = Object.keys(iconNodes);
|
const icons = Object.keys(iconNodes);
|
||||||
|
|
||||||
// Generate Import for Icon VNodes
|
// Generate Import for Icon VNodes
|
||||||
icons.forEach((iconName) => {
|
const iconImportNodesPromises = icons.map(async (iconName) => {
|
||||||
let componentName;
|
let componentName;
|
||||||
|
|
||||||
if (exportModuleNameCasing === 'camel') {
|
if (exportModuleNameCasing === 'camel') {
|
||||||
@@ -27,10 +27,12 @@ export default (
|
|||||||
componentName = toPascalCase(iconName);
|
componentName = toPascalCase(iconName);
|
||||||
}
|
}
|
||||||
const importString = `export { default as ${componentName} } from './${iconName}${iconFileExtension}';\n`;
|
const importString = `export { default as ${componentName} } from './${iconName}${iconFileExtension}';\n`;
|
||||||
appendFile(importString, fileName, outputDirectory);
|
return appendFile(importString, fileName, outputDirectory);
|
||||||
});
|
});
|
||||||
|
|
||||||
appendFile('\n', fileName, outputDirectory);
|
await Promise.all(iconImportNodesPromises);
|
||||||
|
|
||||||
|
await appendFile('\n', fileName, outputDirectory);
|
||||||
|
|
||||||
console.log(`Successfully generated ${fileName} file`);
|
console.log(`Successfully generated ${fileName} file`);
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import prettier from 'prettier';
|
|||||||
import { readSvg, toPascalCase } from '@lucide/helpers';
|
import { readSvg, toPascalCase } from '@lucide/helpers';
|
||||||
import deprecationReasonTemplate from '../utils/deprecationReasonTemplate.mjs';
|
import deprecationReasonTemplate from '../utils/deprecationReasonTemplate.mjs';
|
||||||
|
|
||||||
export default ({
|
function generateIconFiles({
|
||||||
iconNodes,
|
iconNodes,
|
||||||
outputDirectory,
|
outputDirectory,
|
||||||
template,
|
template,
|
||||||
@@ -15,7 +15,7 @@ export default ({
|
|||||||
pretty = true,
|
pretty = true,
|
||||||
iconsDir,
|
iconsDir,
|
||||||
iconMetaData,
|
iconMetaData,
|
||||||
}) => {
|
}) {
|
||||||
const icons = Object.keys(iconNodes);
|
const icons = Object.keys(iconNodes);
|
||||||
const iconsDistDirectory = path.join(outputDirectory, `icons`);
|
const iconsDistDirectory = path.join(outputDirectory, `icons`);
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ export default ({
|
|||||||
})
|
})
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
const elementTemplate = template({
|
const elementTemplate = await template({
|
||||||
componentName,
|
componentName,
|
||||||
iconName,
|
iconName,
|
||||||
children,
|
children,
|
||||||
@@ -71,7 +71,7 @@ export default ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Promise.all(writeIconFiles)
|
return Promise.all(writeIconFiles)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (showLog) {
|
if (showLog) {
|
||||||
console.log('Successfully built', icons.length, 'icons.');
|
console.log('Successfully built', icons.length, 'icons.');
|
||||||
@@ -80,4 +80,6 @@ export default ({
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw new Error(`Something went wrong generating icon files,\n ${error}`);
|
throw new Error(`Something went wrong generating icon files,\n ${error}`);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export default generateIconFiles;
|
||||||
|
|||||||
@@ -47,16 +47,16 @@ async function buildIcons() {
|
|||||||
throw new Error('No `templateSrc` argument given.');
|
throw new Error('No `templateSrc` argument given.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const svgFiles = readSvgDirectory(ICONS_DIR);
|
const svgFiles = await readSvgDirectory(ICONS_DIR);
|
||||||
|
|
||||||
const icons = renderIconsObject(svgFiles, ICONS_DIR, renderUniqueKey);
|
const icons = await renderIconsObject(svgFiles, ICONS_DIR, renderUniqueKey);
|
||||||
|
|
||||||
const { default: iconFileTemplate } = await import(path.resolve(process.cwd(), templateSrc));
|
const { default: iconFileTemplate } = await import(path.resolve(process.cwd(), templateSrc));
|
||||||
|
|
||||||
const iconMetaData = await getIconMetaData(ICONS_DIR);
|
const iconMetaData = await getIconMetaData(ICONS_DIR);
|
||||||
|
|
||||||
// Generates iconsNodes files for each icon
|
// Generates iconsNodes files for each icon
|
||||||
generateIconFiles({
|
await generateIconFiles({
|
||||||
iconNodes: icons,
|
iconNodes: icons,
|
||||||
outputDirectory: OUTPUT_DIR,
|
outputDirectory: OUTPUT_DIR,
|
||||||
template: iconFileTemplate,
|
template: iconFileTemplate,
|
||||||
@@ -86,7 +86,7 @@ async function buildIcons() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (withDynamicImports) {
|
if (withDynamicImports) {
|
||||||
generateDynamicImports({
|
await generateDynamicImports({
|
||||||
iconNodes: icons,
|
iconNodes: icons,
|
||||||
outputDirectory: OUTPUT_DIR,
|
outputDirectory: OUTPUT_DIR,
|
||||||
fileExtension: aliasesFileExtension,
|
fileExtension: aliasesFileExtension,
|
||||||
@@ -96,7 +96,7 @@ async function buildIcons() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generates entry files for the compiler filled with icons exports
|
// Generates entry files for the compiler filled with icons exports
|
||||||
generateExportsFile(
|
await generateExportsFile(
|
||||||
path.join(OUTPUT_DIR, 'icons', exportFileName),
|
path.join(OUTPUT_DIR, 'icons', exportFileName),
|
||||||
path.join(OUTPUT_DIR, 'icons'),
|
path.join(OUTPUT_DIR, 'icons'),
|
||||||
icons,
|
icons,
|
||||||
|
|||||||
@@ -20,11 +20,13 @@
|
|||||||
"@lucide/helpers": "workspace:*"
|
"@lucide/helpers": "workspace:*"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lucide/helpers": "^1.0.0",
|
|
||||||
"minimist": "^1.2.7",
|
"minimist": "^1.2.7",
|
||||||
"node-fetch": "^3.2.10",
|
"node-fetch": "^3.2.10",
|
||||||
"prettier": "2.7.1",
|
"prettier": "2.7.1",
|
||||||
"svgo": "^3.0.0",
|
"svgo": "^3.0.0",
|
||||||
"svgson": "^5.2.1"
|
"svgson": "^5.2.1"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@lucide/helpers": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,32 +8,39 @@ import { generateHashedKey, readSvg, hasDuplicatedChildren } from '@lucide/helpe
|
|||||||
* @param {Function} getSvg - A function that returns the contents of an SVG file given a filename.
|
* @param {Function} getSvg - A function that returns the contents of an SVG file given a filename.
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
export default (svgFiles, iconsDirectory, renderUniqueKey = false) =>
|
export default async function generateIconObject(
|
||||||
svgFiles
|
svgFiles,
|
||||||
.map((svgFile) => {
|
iconsDirectory,
|
||||||
const name = basename(svgFile, '.svg');
|
renderUniqueKey = false,
|
||||||
const svg = readSvg(svgFile, iconsDirectory);
|
) {
|
||||||
const contents = parseSync(svg);
|
const svgsContentPromises = svgFiles.map(async (svgFile) => {
|
||||||
|
const name = basename(svgFile, '.svg');
|
||||||
|
const svg = await readSvg(svgFile, iconsDirectory);
|
||||||
|
const contents = parseSync(svg);
|
||||||
|
|
||||||
if (!(contents.children && contents.children.length)) {
|
if (!(contents.children && contents.children.length)) {
|
||||||
throw new Error(`${name}.svg has no children!`);
|
throw new Error(`${name}.svg has no children!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasDuplicatedChildren(contents.children)) {
|
if (hasDuplicatedChildren(contents.children)) {
|
||||||
throw new Error(`Duplicated children in ${name}.svg`);
|
throw new Error(`Duplicated children in ${name}.svg`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renderUniqueKey) {
|
if (renderUniqueKey) {
|
||||||
contents.children = contents.children.map((child) => {
|
contents.children = contents.children.map((child) => {
|
||||||
child.attributes.key = generateHashedKey(child);
|
child.attributes.key = generateHashedKey(child);
|
||||||
|
|
||||||
return child;
|
return child;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { name, contents };
|
return { name, contents };
|
||||||
})
|
});
|
||||||
.reduce((icons, icon) => {
|
|
||||||
icons[icon.name] = icon.contents;
|
const svgsContents = await Promise.all(svgsContentPromises);
|
||||||
return icons;
|
|
||||||
}, {});
|
return svgsContents.reduce((icons, icon) => {
|
||||||
|
icons[icon.name] = icon.contents;
|
||||||
|
return icons;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import path from 'path';
|
|||||||
import { readSvgDirectory } from '@lucide/helpers';
|
import { readSvgDirectory } from '@lucide/helpers';
|
||||||
|
|
||||||
async function getAliases(iconDirectory) {
|
async function getAliases(iconDirectory) {
|
||||||
const iconJsons = readSvgDirectory(iconDirectory, '.json');
|
const iconJsons = await readSvgDirectory(iconDirectory, '.json');
|
||||||
const aliasesEntries = await Promise.all(
|
const aliasesEntries = await Promise.all(
|
||||||
iconJsons.map(async (jsonFile) => {
|
iconJsons.map(async (jsonFile) => {
|
||||||
const file = await import(path.join(iconDirectory, jsonFile), { with: { type: 'json' } });
|
const file = await import(path.join(iconDirectory, jsonFile), { with: { type: 'json' } });
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import path from 'path';
|
|||||||
import { readSvgDirectory } from '@lucide/helpers';
|
import { readSvgDirectory } from '@lucide/helpers';
|
||||||
|
|
||||||
async function getIconMetaData(iconDirectory) {
|
async function getIconMetaData(iconDirectory) {
|
||||||
const iconJsons = readSvgDirectory(iconDirectory, '.json');
|
const iconJsons = await readSvgDirectory(iconDirectory, '.json');
|
||||||
const aliasesEntries = await Promise.all(
|
const aliasesEntries = await Promise.all(
|
||||||
iconJsons.map(async (jsonFile) => {
|
iconJsons.map(async (jsonFile) => {
|
||||||
/** eslint-disable */
|
/** eslint-disable */
|
||||||
|
|||||||
Reference in New Issue
Block a user