mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-02-24 05:09:41 +01:00
Format code
This commit is contained in:
@@ -1911,4 +1911,4 @@
|
||||
"search-alert": 59055,
|
||||
"stone": 59055,
|
||||
"toolbox": 59056
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { type IconAliases } from "@lucide/helpers";
|
||||
import path from "path";
|
||||
import { type IconAliases } from '@lucide/helpers';
|
||||
import path from 'path';
|
||||
import { promises as fs } from 'fs';
|
||||
import { cwd } from "process";
|
||||
import { cwd } from 'process';
|
||||
|
||||
export type CodePoints = Record<string, number>;
|
||||
|
||||
async function getLatestCodePoints(): Promise<CodePoints> {
|
||||
// This is for the first release where no codepoints.json exists yet
|
||||
const codepointsContents = await fs.readFile(path.join(cwd(), 'codepoints.json'), 'utf-8')
|
||||
const codepointsContents = await fs.readFile(path.join(cwd(), 'codepoints.json'), 'utf-8');
|
||||
|
||||
return JSON.parse(codepointsContents) as CodePoints
|
||||
return JSON.parse(codepointsContents) as CodePoints;
|
||||
|
||||
// Next releases will use the codepoints.json from latest release in lucide-static.
|
||||
// const codepointsContents = await fetch('https://unpkg.com/lucide-static@latest/font/codepoints.json')
|
||||
@@ -18,20 +18,20 @@ async function getLatestCodePoints(): Promise<CodePoints> {
|
||||
|
||||
interface AllocateCodePointsOptions {
|
||||
saveCodePoints?: boolean;
|
||||
iconsWithAliases: IconAliases
|
||||
iconsWithAliases: IconAliases;
|
||||
}
|
||||
|
||||
export async function allocateCodePoints({
|
||||
saveCodePoints = false,
|
||||
iconsWithAliases
|
||||
iconsWithAliases,
|
||||
}: AllocateCodePointsOptions): Promise<CodePoints> {
|
||||
const baseCodePoints = await getLatestCodePoints()
|
||||
const baseCodePoints = await getLatestCodePoints();
|
||||
|
||||
const endCodePoint = Math.max(...Object.values(baseCodePoints))
|
||||
const endCodePoint = Math.max(...Object.values(baseCodePoints));
|
||||
|
||||
await Promise.all(
|
||||
iconsWithAliases.map(async ([iconName, aliases]) => {
|
||||
if(!baseCodePoints[iconName]) {
|
||||
if (!baseCodePoints[iconName]) {
|
||||
console.log('Code point not found creating new one for', iconName);
|
||||
baseCodePoints[iconName] = endCodePoint + 1;
|
||||
}
|
||||
@@ -45,14 +45,14 @@ export async function allocateCodePoints({
|
||||
|
||||
baseCodePoints[alias] = endCodePoint + index + 1;
|
||||
});
|
||||
})
|
||||
)
|
||||
}),
|
||||
);
|
||||
|
||||
if (saveCodePoints) {
|
||||
await fs.writeFile(
|
||||
path.join(cwd(), 'codepoints.json'),
|
||||
JSON.stringify(baseCodePoints, null, 2),
|
||||
'utf-8'
|
||||
'utf-8',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ interface BuildFontOptions {
|
||||
targetDir: string;
|
||||
fontName: string;
|
||||
classNamePrefix: string;
|
||||
codePoints: CodePoints
|
||||
codePoints: CodePoints;
|
||||
startUnicode: number;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function buildFont({
|
||||
fontName,
|
||||
classNamePrefix,
|
||||
codePoints,
|
||||
startUnicode
|
||||
startUnicode,
|
||||
}: BuildFontOptions) {
|
||||
console.time('Font generation');
|
||||
try {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { type IconAliases } from "@lucide/helpers";
|
||||
import { type CodePoints } from "./allocateCodepoints.ts";
|
||||
import { type IconAliases } from '@lucide/helpers';
|
||||
import { type CodePoints } from './allocateCodepoints.ts';
|
||||
|
||||
export function hasMissingCodePoints(iconsWithAliases: IconAliases, codePoints: CodePoints): boolean {
|
||||
return iconsWithAliases.map(([iconName, aliases]) => ([iconName, ...aliases]))
|
||||
export function hasMissingCodePoints(
|
||||
iconsWithAliases: IconAliases,
|
||||
codePoints: CodePoints,
|
||||
): boolean {
|
||||
return iconsWithAliases
|
||||
.map(([iconName, aliases]) => [iconName, ...aliases])
|
||||
.flat()
|
||||
.some(name => {
|
||||
.some((name) => {
|
||||
if (!codePoints?.[name]) {
|
||||
console.log(`Missing code point for icon/alias: ${name}`);
|
||||
return true;
|
||||
|
||||
@@ -13,29 +13,26 @@ const classNamePrefix = 'icon';
|
||||
const startUnicode = 57400;
|
||||
const outputDir = 'lucide-font';
|
||||
|
||||
const {
|
||||
saveCodePoints = false,
|
||||
} = getArgumentOptions(process.argv.slice(2)) ?? {}
|
||||
const { saveCodePoints = false } = getArgumentOptions(process.argv.slice(2)) ?? {};
|
||||
|
||||
const repoRoot = path.join(process.cwd(), '../../')
|
||||
const repoRoot = path.join(process.cwd(), '../../');
|
||||
const iconsDir = path.join(repoRoot, 'icons');
|
||||
const outlinedDir = path.join(repoRoot, 'outlined');
|
||||
const targetDir = path.join(repoRoot, outputDir);
|
||||
|
||||
const iconsWithAliases = await getAllIconAliases(iconsDir)
|
||||
const iconsWithAliases = await getAllIconAliases(iconsDir);
|
||||
|
||||
await outlineSVG({
|
||||
iconsDir,
|
||||
outlinedDir,
|
||||
iconsWithAliases
|
||||
iconsWithAliases,
|
||||
});
|
||||
|
||||
const codePoints = await allocateCodePoints({
|
||||
saveCodePoints,
|
||||
iconsWithAliases
|
||||
iconsWithAliases,
|
||||
});
|
||||
|
||||
|
||||
if (hasMissingCodePoints(iconsWithAliases, codePoints)) {
|
||||
throw new Error('Some icons or aliases are missing code points. See log for details.');
|
||||
}
|
||||
@@ -49,4 +46,7 @@ await buildFont({
|
||||
startUnicode,
|
||||
});
|
||||
|
||||
await fs.copyFile(path.join(process.cwd(), 'codepoints.json'), path.join(targetDir, 'codepoints.json'));
|
||||
await fs.copyFile(
|
||||
path.join(process.cwd(), 'codepoints.json'),
|
||||
path.join(targetDir, 'codepoints.json'),
|
||||
);
|
||||
|
||||
@@ -6,19 +6,15 @@ import path from 'path';
|
||||
interface OutlineSVGOptions {
|
||||
iconsDir: string;
|
||||
outlinedDir: string;
|
||||
iconsWithAliases: IconAliases
|
||||
iconsWithAliases: IconAliases;
|
||||
}
|
||||
|
||||
export async function outlineSVG({
|
||||
iconsDir,
|
||||
outlinedDir,
|
||||
iconsWithAliases
|
||||
}: OutlineSVGOptions) {
|
||||
export async function outlineSVG({ iconsDir, outlinedDir, iconsWithAliases }: OutlineSVGOptions) {
|
||||
console.time('icon outliner');
|
||||
try {
|
||||
try {
|
||||
await fs.mkdir(outlinedDir);
|
||||
} catch (error) { } // eslint-disable-line no-empty
|
||||
} catch (error) {} // eslint-disable-line no-empty
|
||||
|
||||
await SVGFixer(iconsDir, outlinedDir, {
|
||||
showProgressBar: true,
|
||||
@@ -27,20 +23,24 @@ export async function outlineSVG({
|
||||
|
||||
console.log('Duplicate icons with aliases..');
|
||||
|
||||
await Promise.all(iconsWithAliases.map(async ([iconName, aliases]) => {
|
||||
const sourcePath = path.join(outlinedDir, `${iconName}.svg`);
|
||||
await Promise.all(
|
||||
iconsWithAliases.map(async ([iconName, aliases]) => {
|
||||
const sourcePath = path.join(outlinedDir, `${iconName}.svg`);
|
||||
|
||||
await Promise.all(aliases.map(async (aliasName) => {
|
||||
const destinationPath = path.join(outlinedDir, `${aliasName}.svg`);
|
||||
await Promise.all(
|
||||
aliases.map(async (aliasName) => {
|
||||
const destinationPath = path.join(outlinedDir, `${aliasName}.svg`);
|
||||
|
||||
try {
|
||||
await fs.copyFile(sourcePath, destinationPath);
|
||||
console.log(`Copied ${iconName}.svg to ${aliasName}.svg`);
|
||||
} catch (err) {
|
||||
console.log(`Failed to copy ${sourcePath} to ${destinationPath}:`, err);
|
||||
}
|
||||
}));
|
||||
}));
|
||||
try {
|
||||
await fs.copyFile(sourcePath, destinationPath);
|
||||
console.log(`Copied ${iconName}.svg to ${aliasName}.svg`);
|
||||
} catch (err) {
|
||||
console.log(`Failed to copy ${sourcePath} to ${destinationPath}:`, err);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
console.timeEnd('icon outliner');
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
import { readAllMetadata } from "./readAllMetadata.ts";
|
||||
import { readAllMetadata } from './readAllMetadata.ts';
|
||||
|
||||
export type IconAliases = [iconName: string, aliases: string[]][];
|
||||
|
||||
export const getAllIconAliases = async (iconsDir: string): Promise<IconAliases> => {
|
||||
const metaDataFiles = await readAllMetadata(iconsDir)
|
||||
const metaDataFiles = await readAllMetadata(iconsDir);
|
||||
|
||||
return Object.entries(metaDataFiles).map(([iconName, metadata]) => {
|
||||
const { aliases } = metadata;
|
||||
|
||||
if (!aliases?.length) return [iconName, []];
|
||||
|
||||
const aliasesNames = aliases.map(alias =>
|
||||
typeof alias === 'string' ? alias : alias.name,
|
||||
);
|
||||
|
||||
return [iconName, aliasesNames]
|
||||
})
|
||||
}
|
||||
const aliasesNames = aliases.map((alias) => (typeof alias === 'string' ? alias : alias.name));
|
||||
|
||||
return [iconName, aliasesNames];
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user