Skip to content

Commit

Permalink
refactor: disable dynamic import for core component
Browse files Browse the repository at this point in the history
  • Loading branch information
flamrdevs committed Feb 10, 2024
1 parent 512dab0 commit 1dcd861
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 74 deletions.
10 changes: 3 additions & 7 deletions src/routes/bundlejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Hono } from 'hono';

import { bundlejs, npm } from '~/libs';

import { getValidColorQuery, getValidThemeQuery, components } from '~/ui';
import { getValidColorQuery, getValidThemeQuery, core } from '~/ui';

import * as response from '~/utils/response';

Expand All @@ -28,8 +28,6 @@ export default new Hono()
const { getBundleItem } = await bundlejs();
const { getValidPackageNameParam } = await npm();

const { Badge, calcBadgeWidth } = await components.core();

const param = ctx.req.param();
const query = ctx.req.query();

Expand All @@ -40,7 +38,7 @@ export default new Hono()

const s = (await getBundleItem(n)).size.uncompressedSize;

return await response.svg(ctx, async () => Badge({ c, t, w: calcBadgeWidth(s), children: s }));
return await response.svg(ctx, async () => core.Badge({ c, t, w: core.calcBadgeWidth(s), children: s }));
})

/**
Expand All @@ -50,8 +48,6 @@ export default new Hono()
const { getBundleItem } = await bundlejs();
const { getValidPackageNameParam } = await npm();

const { Badge, calcBadgeWidth } = await components.core();

const param = ctx.req.param();
const query = ctx.req.query();

Expand All @@ -62,5 +58,5 @@ export default new Hono()

const s = (await getBundleItem(n)).size.compressedSize;

return await response.svg(ctx, async () => Badge({ c, t, w: calcBadgeWidth(s), children: s }));
return await response.svg(ctx, async () => core.Badge({ c, t, w: core.calcBadgeWidth(s), children: s }));
});
17 changes: 7 additions & 10 deletions src/routes/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Hono } from 'hono';

import { github } from '~/libs';

import { getValidColorQuery, getValidThemeQuery, components } from '~/ui';
import { getValidColorQuery, getValidThemeQuery, core, icon } from '~/ui';

import * as response from '~/utils/response';

Expand Down Expand Up @@ -34,8 +34,7 @@ export default new Hono()
.get('/repo/fc/:user/:repo', async (ctx) => {
const { getRepoItem, getValidUsernameParam, getValidReponameParam, formatCount } = await github();

const { Badge, BadgeChildIcon, calcBadgeIconWidth } = await components.core();
const { LucideIcons } = await components.icon.lucide();
const { LucideIcons } = await icon.lucide();

const param = ctx.req.param();
const query = ctx.req.query();
Expand All @@ -48,7 +47,7 @@ export default new Hono()

const children = `${formatCount((await getRepoItem(user, repo)).forks_count)}`;

return await response.svg(ctx, async () => Badge({ c, t, w: calcBadgeIconWidth(children), children: BadgeChildIcon({ c: LucideIcons['git-fork']({ s: 12 }), e: children }) }));
return await response.svg(ctx, async () => core.Badge({ c, t, w: core.calcBadgeIconWidth(children), children: core.BadgeChildIcon({ c: LucideIcons['git-fork']({ s: 12 }), e: children }) }));
})

/**
Expand All @@ -57,8 +56,7 @@ export default new Hono()
.get('/repo/sc/:user/:repo', async (ctx) => {
const { getRepoItem, getValidUsernameParam, getValidReponameParam, formatCount } = await github();

const { Badge, BadgeChildIcon, calcBadgeIconWidth } = await components.core();
const { LucideIcons } = await components.icon.lucide();
const { LucideIcons } = await icon.lucide();

const param = ctx.req.param();
const query = ctx.req.query();
Expand All @@ -71,7 +69,7 @@ export default new Hono()

const children = `${formatCount((await getRepoItem(user, repo)).stargazers_count)}`;

return await response.svg(ctx, async () => Badge({ c, t, w: calcBadgeIconWidth(children), children: BadgeChildIcon({ c: LucideIcons['star']({ s: 12 }), e: children }) }));
return await response.svg(ctx, async () => core.Badge({ c, t, w: core.calcBadgeIconWidth(children), children: core.BadgeChildIcon({ c: LucideIcons['star']({ s: 12 }), e: children }) }));
})

/**
Expand All @@ -80,8 +78,7 @@ export default new Hono()
.get('/repo/l/:user/:repo', async (ctx) => {
const { getRepoItem, getValidUsernameParam, getValidReponameParam } = await github();

const { Badge, BadgeChildIcon, calcBadgeIconWidth } = await components.core();
const { LucideIcons } = await components.icon.lucide();
const { LucideIcons } = await icon.lucide();

const param = ctx.req.param();
const query = ctx.req.query();
Expand All @@ -95,5 +92,5 @@ export default new Hono()
const item = await getRepoItem(user, repo);
const children = item.license ? `${item.license.spdx_id}` : 'Null';

return await response.svg(ctx, async () => Badge({ c, t, w: calcBadgeIconWidth(children), children: BadgeChildIcon({ c: LucideIcons['scale']({ s: 12 }), e: children }) }));
return await response.svg(ctx, async () => core.Badge({ c, t, w: core.calcBadgeIconWidth(children), children: core.BadgeChildIcon({ c: LucideIcons['scale']({ s: 12 }), e: children }) }));
});
18 changes: 5 additions & 13 deletions src/routes/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Hono } from 'hono';

import { npm } from '~/libs';

import { getValidColorQuery, getValidThemeQuery, components } from '~/ui';
import { getValidColorQuery, getValidThemeQuery, core } from '~/ui';

import * as response from '~/utils/response';

Expand Down Expand Up @@ -59,8 +59,6 @@ export default new Hono()
.get('/v/:name{.+$}', async (ctx) => {
const { getPackageItem, getValidPackageNameParam } = await npm();

const { Badge, calcBadgeWidth } = await components.core();

const param = ctx.req.param();
const query = ctx.req.query();

Expand All @@ -71,7 +69,7 @@ export default new Hono()

const v = (await getPackageItem(n)).version;

return await response.svg(ctx, async () => Badge({ c, t, w: calcBadgeWidth(v), children: v }));
return await response.svg(ctx, async () => core.Badge({ c, t, w: core.calcBadgeWidth(v), children: v }));
})

/**
Expand All @@ -80,8 +78,6 @@ export default new Hono()
.get('/l/:name{.+$}', async (ctx) => {
const { getPackageItem, getValidPackageNameParam } = await npm();

const { Badge, calcBadgeWidth } = await components.core();

const param = ctx.req.param();
const query = ctx.req.query();

Expand All @@ -92,7 +88,7 @@ export default new Hono()

const l = (await getPackageItem(n)).license ?? 'UNLICENSED';

return await response.svg(ctx, async () => Badge({ c, t, w: calcBadgeWidth(l), children: l }));
return await response.svg(ctx, async () => core.Badge({ c, t, w: core.calcBadgeWidth(l), children: l }));
})

/**
Expand All @@ -101,8 +97,6 @@ export default new Hono()
.get('/dw/:name{.+$}', async (ctx) => {
const { getDownloadPointWeekItem, getValidPackageNameParam, formatDownloads } = await npm();

const { Badge, calcBadgeWidth } = await components.core();

const param = ctx.req.param();
const query = ctx.req.query();

Expand All @@ -113,7 +107,7 @@ export default new Hono()

const text = `${formatDownloads((await getDownloadPointWeekItem(n)).downloads)}/W`;

return await response.svg(ctx, async () => Badge({ c, t, w: calcBadgeWidth(text), children: text }));
return await response.svg(ctx, async () => core.Badge({ c, t, w: core.calcBadgeWidth(text), children: text }));
})

/**
Expand All @@ -122,8 +116,6 @@ export default new Hono()
.get('/dm/:name{.+$}', async (ctx) => {
const { getDownloadPointMonthItem, getValidPackageNameParam, formatDownloads } = await npm();

const { Badge, calcBadgeWidth } = await components.core();

const param = ctx.req.param();
const query = ctx.req.query();

Expand All @@ -134,5 +126,5 @@ export default new Hono()

const text = `${formatDownloads((await getDownloadPointMonthItem(n)).downloads)}/M`;

return await response.svg(ctx, async () => Badge({ c, t, w: calcBadgeWidth(text), children: text }));
return await response.svg(ctx, async () => core.Badge({ c, t, w: core.calcBadgeWidth(text), children: text }));
});
Loading

0 comments on commit 1dcd861

Please sign in to comment.