Skip to content

Commit

Permalink
fix(assets): modify the exports script to export from assets dir
Browse files Browse the repository at this point in the history
  • Loading branch information
neuodev committed Dec 20, 2024
1 parent 3e44f66 commit 6d23313
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
31 changes: 15 additions & 16 deletions packages/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,43 @@
"vite-node": "^2.1.2"
},
"exports": {
"./Categories": "./dist/Categories.tsx",
"./LongLeftArrow": "./dist/LongLeftArrow.tsx",
"./LongRightArrow": "./dist/LongRightArrow.tsx",
"./AllMessages": "./dist/AllMessages.tsx",
"./ArrowDown": "./dist/ArrowDown.tsx",
"./ArrowLeft": "./dist/ArrowLeft.tsx",
"./ArrowRight": "./dist/ArrowRight.tsx",
"./BottomRightArch": "./dist/BottomRightArch.tsx",
"./Calendar": "./dist/Calendar.tsx",
"./CalendarEdit": "./dist/CalendarEdit.tsx",
"./CalendarEmpty": "./dist/CalendarEmpty.tsx",
"./CalendarRemove": "./dist/CalendarRemove.tsx",
"./Calendar": "./dist/Calendar.tsx",
"./CallIncoming": "./dist/CallIncoming.tsx",
"./Cancel": "./dist/Cancel.tsx",
"./CastScreen": "./dist/CastScreen.tsx",
"./Categories": "./dist/Categories.tsx",
"./Chat": "./dist/Chat.tsx",
"./CheckCircleFill": "./dist/CheckCircleFill.tsx",
"./CheckCircle": "./dist/CheckCircle.tsx",
"./Check": "./dist/Check.tsx",
"./Check16X16": "./dist/Check16X16.tsx",
"./Check2": "./dist/Check2.tsx",
"./Check3": "./dist/Check3.tsx",
"./CheckCircle": "./dist/CheckCircle.tsx",
"./CheckCircleFill": "./dist/CheckCircleFill.tsx",
"./Clock": "./dist/Clock.tsx",
"./Clock16X16": "./dist/Clock16X16.tsx",
"./Close": "./dist/Close.tsx",
"./Edit": "./dist/Edit.tsx",
"./EditMessage": "./dist/EditMessage.tsx",
"./EditMessage16X16": "./dist/EditMessage16X16.tsx",
"./Edit": "./dist/Edit.tsx",
"./EmptyChatsSummary": "./dist/EmptyChatsSummary.tsx",
"./EmptyLesson2": "./dist/EmptyLesson2.tsx",
"./EmptyLessons": "./dist/EmptyLessons.tsx",
"./EmptyUpcomingLessons": "./dist/EmptyUpcomingLessons.tsx",
"./Error": "./dist/Error.tsx",
"./ExclaimationMarkCircle": "./dist/ExclaimationMarkCircle.tsx",
"./ExclamationMark": "./dist/ExclamationMark.tsx",
"./Eye": "./dist/Eye.tsx",
"./EyeSlash": "./dist/EyeSlash.tsx",
"./Eye": "./dist/Eye.tsx",
"./FullScreen": "./dist/FullScreen.tsx",
"./Home": "./dist/Home.tsx",
"./Info": "./dist/Info.tsx",
Expand All @@ -60,16 +62,14 @@
"./LoginLight": "./dist/LoginLight.tsx",
"./Logo": "./dist/Logo.tsx",
"./Logout": "./dist/Logout.tsx",
"./LongLeftArrow": "./dist/LongLeftArrow.tsx",
"./LongRightArrow": "./dist/LongRightArrow.tsx",
"./Maximize": "./dist/Maximize.tsx",
"./MedalBadge": "./dist/MedalBadge.tsx",
"./MessageEdit": "./dist/MessageEdit.tsx",
"./MessageQuestion": "./dist/MessageQuestion.tsx",
"./Messages": "./dist/Messages.tsx",
"./Microphone": "./dist/Microphone.tsx",
"./MicrophoneSlash": "./dist/MicrophoneSlash.tsx",
"./MicrophoneSlashSmall": "./dist/MicrophoneSlashSmall.tsx",
"./MicrophoneSlash": "./dist/MicrophoneSlash.tsx",
"./Microphone": "./dist/Microphone.tsx",
"./Monitor": "./dist/Monitor.tsx",
"./More": "./dist/More.tsx",
"./Notification": "./dist/Notification.tsx",
Expand All @@ -87,10 +87,10 @@
"./SStar": "./dist/SStar.tsx",
"./Search": "./dist/Search.tsx",
"./Send": "./dist/Send.tsx",
"./Settings": "./dist/Settings.tsx",
"./SettingsScrew": "./dist/SettingsScrew.tsx",
"./Sound": "./dist/Sound.tsx",
"./Settings": "./dist/Settings.tsx",
"./SoundSmall": "./dist/SoundSmall.tsx",
"./Sound": "./dist/Sound.tsx",
"./Spinner": "./dist/Spinner.tsx",
"./Star": "./dist/Star.tsx",
"./StudentDefaultAvatar": "./dist/StudentDefaultAvatar.tsx",
Expand All @@ -100,20 +100,19 @@
"./StudentMaleLight": "./dist/StudentMaleLight.tsx",
"./Tag": "./dist/Tag.tsx",
"./ThemeSwitchLight": "./dist/ThemeSwitchLight.tsx",
"./Timer": "./dist/Timer.tsx",
"./TimerIndicator": "./dist/TimerIndicator.tsx",
"./Timer": "./dist/Timer.tsx",
"./TopLeftArch": "./dist/TopLeftArch.tsx",
"./Trash": "./dist/Trash.tsx",
"./TutorFemaleDark": "./dist/TutorFemaleDark.tsx",
"./TutorFemaleLight": "./dist/TutorFemaleLight.tsx",
"./TutorMaleDark": "./dist/TutorMaleDark.tsx",
"./TutorMaleLight": "./dist/TutorMaleLight.tsx",
"./Video": "./dist/Video.tsx",
"./Video16X16": "./dist/Video16X16.tsx",
"./VideoSlash": "./dist/VideoSlash.tsx",
"./Video": "./dist/Video.tsx",
"./WarningFill": "./dist/WarningFill.tsx",
"./X": "./dist/X.tsx",
"./XErroredFill": "./dist/XErroredFill.tsx",
"./index": "./dist/index.tsx"
"./X": "./dist/X.tsx"
}
}
30 changes: 19 additions & 11 deletions packages/assets/scripts/exports.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
import fs from "node:fs";
import path from "node:path/posix";
import { glob } from "glob";
import { camelCase, upperFirst } from "lodash";

type Exports = Record<string, string>;
type PackageJson = {
exports: Exports;
};

function withCurrentDir(file: string): string {
return `./${file}`;
function asComponentName(file: string) {
// e.g. assets/arrow-down.svg => arrow-down.svg
const name = path.basename(file);
// remove `.svg` file extension
if (!name.endsWith(".svg")) throw new Error(`Invalid file name: ${file}`);
const key = name.replace(".svg", "");
// e.g., arrow-down => ArrowDown
return upperFirst(camelCase(key));
}

function asExportKey(file: string) {
// e.g. dist/ArrowDown.tsx => ArrowDown.tsx
const name = path.basename(file);
// remove `.tsx` file extension
if (!name.endsWith(".tsx")) throw new Error(`Invalid file name: ${file}`);
const key = name.replace(".tsx", "");
// prefix it with `./` (current dir) => ./ArrowDown
return withCurrentDir(key);
const component = asComponentName(file);
return `./${component}`;
}

function asComponentPath(file: string) {
const component = asComponentName(file);
return `./dist/${component}.tsx`;
}

async function getExports(): Promise<Exports> {
const files = await glob("dist/*.tsx", {
const files = await glob("assets/*.svg", {
posix: true,
});
const sorted = [...files].sort();
const exports: Exports = {};

for (const file of sorted) {
exports[asExportKey(file)] = withCurrentDir(file);
exports[asExportKey(file)] = asComponentPath(file);
}

return exports;
}

Expand Down

0 comments on commit 6d23313

Please sign in to comment.