mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-07-10 01:38:46 +02:00
* setup icon popularity call * Adjust sort button * Adjust sorting * Adds aliases * Format code * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Add check for env variable * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Improve styling on mobile * Remove hardcoded sort icon * Fix build * Format code --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import path from 'path';
|
|
import fs from 'fs';
|
|
import { getIconMetaData } from '@lucide/build-icons';
|
|
import { getCurrentDirPath } from '@lucide/helpers';
|
|
|
|
const currentDir = process.cwd();
|
|
const scriptDir = getCurrentDirPath(import.meta.url);
|
|
|
|
const iconMetaData = await getIconMetaData(path.resolve(scriptDir, '../../icons'));
|
|
|
|
const iconAliasesRedirectRoutes = Object.entries(iconMetaData)
|
|
.filter(([, { aliases }]) => aliases?.length)
|
|
.map(([iconName, { aliases }]) => {
|
|
const aliasRouteMatches = aliases.map((alias) => typeof alias === 'string' ? alias : alias?.name).join('|');
|
|
|
|
return {
|
|
src: `^/icons/(${aliasRouteMatches})$`,
|
|
status: 308,
|
|
headers: {
|
|
Location: `/icons/${iconName}`,
|
|
},
|
|
};
|
|
});
|
|
|
|
const vercelOutputJSON = path.resolve(currentDir, '.vercel/output/config.json');
|
|
|
|
const vercelConfig = await fs.promises.readFile(vercelOutputJSON, 'utf-8');
|
|
|
|
const vercelRouteConfig = JSON.parse(vercelConfig);
|
|
|
|
vercelRouteConfig.routes = [...iconAliasesRedirectRoutes, ...vercelRouteConfig.routes];
|
|
|
|
// Adjust the existing catch-all route to only catch API routes, so that we can add a new catch-all route for 404s
|
|
const allCatchRoute = '/(.*)';
|
|
const fallBackIndex = vercelRouteConfig.routes.findIndex((route) => route.src === allCatchRoute);
|
|
|
|
if (fallBackIndex === -1) {
|
|
throw new Error(
|
|
`Could not find the expected catch-all route with src "${allCatchRoute}" in the existing Vercel config. Please make sure that the existing config has a catch-all route and that its src is "${allCatchRoute}".`,
|
|
);
|
|
}
|
|
|
|
vercelRouteConfig.routes[fallBackIndex].src = '/api/(.*)';
|
|
vercelRouteConfig.routes.push({
|
|
src: allCatchRoute,
|
|
dest: '/404.html',
|
|
});
|
|
|
|
const output = JSON.stringify(vercelRouteConfig, null, 2);
|
|
|
|
await fs.promises.writeFile(vercelOutputJSON, output, 'utf-8');
|