From 465b1d36cc27c459962d39e72309042eedb6a304 Mon Sep 17 00:00:00 2001 From: sheykei Date: Mon, 13 Jan 2025 18:17:37 +0100 Subject: [PATCH 1/2] add: scripts + generated idnex --- scripts/generateExports.ts | 55 ++++++++ src/components.ts | 67 ---------- src/components/primitives/Switch.tsx | 0 src/index.ts | 191 ++++++++++++++++++++++----- 4 files changed, 213 insertions(+), 100 deletions(-) create mode 100644 scripts/generateExports.ts delete mode 100644 src/components.ts delete mode 100644 src/components/primitives/Switch.tsx diff --git a/scripts/generateExports.ts b/scripts/generateExports.ts new file mode 100644 index 000000000..d2b7dd0c4 --- /dev/null +++ b/scripts/generateExports.ts @@ -0,0 +1,55 @@ +import { readdir } from "node:fs/promises"; + +async function listAllExports() { + //Get all typescript files + const tsFiles = (await readdir("./src", { recursive: true })).filter(file => + [".ts", ".tsx"].some(ext => file.endsWith(ext)), + ); + + //Split paths into [directory, filename] + const filesToExport = tsFiles.map(path => { + const split = path.split("/"); + const directory = split.slice(0, split.length - 1).join("/"); + const file = split.slice(-1)[0]; + + return [directory, file]; + }); + + //Get all unique directoies + const directories = new Set(); + for (const dir of filesToExport.map(([dir]) => dir).filter(dir => !dir.includes("routes"))) { + directories.add(dir); + } + + //Map directories to export lines + const directoryExportLines = await Promise.all( + Array.from(directories).map(async dir => { + const dirFiles = await Promise.all( + filesToExport + .filter(([_dir]) => _dir === dir) + .map(async ([_, filename]) => { + return [dir, filename, await Bun.file(`./src/${dir}/${filename}`).text()]; + }), + ); + + return [ + `/**\n * ${dir}\n */`, + dirFiles + .map(([dir, filename, content]) => { + const name = filename.split(".").slice(0, -1).join("."); + const hasDefaultExports = content.includes("export default ") && !name.includes("."); + + return `export * from "./${dir}/${name}";${ + hasDefaultExports ? `\nexport { default as ${name} } from "./${dir}/${name}";` : "" + }`; + }) + .join("\n"), + "", + ].join("\n"); + }), + ); + + return directoryExportLines.join("\n"); +} + +await Bun.write("./src/index.generated.ts", await listAllExports()); diff --git a/src/components.ts b/src/components.ts deleted file mode 100644 index 572d29816..000000000 --- a/src/components.ts +++ /dev/null @@ -1,67 +0,0 @@ -// /!\ Generated by scripts/generateExports.ts, do not edit directly - -export * from "./components/primitives/Slider"; -export { default as Slider } from "./components/primitives/Slider"; -export * from "./components/primitives/ColorPicker"; -export { default as ColorPicker } from "./components/primitives/ColorPicker"; -export * from "./components/primitives/Space"; -export { default as Space } from "./components/primitives/Space"; -export * from "./components/primitives/Block"; -export { default as Block } from "./components/primitives/Block"; -export * from "./components/primitives/Image"; -export { default as Image } from "./components/primitives/Image"; -export * from "./components/primitives/Box"; -export { default as Box } from "./components/primitives/Box"; -export * from "./components/primitives/Button"; -export { default as Button } from "./components/primitives/Button"; -export * from "./components/primitives/PrimitiveTag"; -export { default as PrimitiveTag } from "./components/primitives/PrimitiveTag"; -export * from "./components/primitives/Checkbox"; -export { default as Checkbox } from "./components/primitives/Checkbox"; -export * from "./components/primitives/Icon"; -export { default as Icon } from "./components/primitives/Icon"; -export * from "./components/primitives/Value"; -export { default as Value } from "./components/primitives/Value"; -export * from "./components/primitives/Divider"; -export { default as Divider } from "./components/primitives/Divider"; -export * from "./components/primitives/Table"; -export * from "./components/primitives/Input"; -export { default as Input } from "./components/primitives/Input"; -export * from "./components/primitives/Title"; -export { default as Title } from "./components/primitives/Title"; -export * from "./components/primitives/Tabs"; -export { default as Tabs } from "./components/primitives/Tabs"; -export * from "./components/primitives/List"; -export { default as List } from "./components/primitives/List"; -export * from "./components/primitives/Hash"; -export { default as Hash } from "./components/primitives/Hash"; -export * from "./components/primitives/Text"; -export { default as Text } from "./components/primitives/Text"; -export * from "./components/primitives/Collapsible"; -export { default as Collapsible } from "./components/primitives/Collapsible"; -export * from "./components/primitives/EventBlocker"; -export { default as EventBlocker } from "./components/primitives/EventBlocker"; -export * from "./components/dapp/WalletButton"; -export { default as WalletButton } from "./components/dapp/WalletButton"; -export * from "./components/dapp/WalletConnectors"; -export { default as WalletConnectors } from "./components/dapp/WalletConnectors"; -export * from "./components/extenders/Modal"; -export { default as Modal } from "./components/extenders/Modal"; -export * from "./components/extenders/Card"; -export { default as Card } from "./components/extenders/Card"; -export * from "./components/extenders/Group"; -export { default as Group } from "./components/extenders/Group"; -export * from "./components/extenders/Select"; -export { default as Select } from "./components/extenders/Select"; -export * from "./components/extenders/Dropdown"; -export { default as Dropdown } from "./components/extenders/Dropdown"; -export * from "./components/extenders/Icons"; -export { default as Icons } from "./components/extenders/Icons"; -export * from "./components/layout/Container.js"; -export { default as Container } from "./components/layout/Container.js"; -export * from "./components/dapp/Countdown"; -export { default as Countdown } from "./components/dapp/Countdown"; -export * from "./components/primitives/Bar"; -export { default as Bar } from "./components/primitives/Bar"; -export * from "./components/dapp/Connected"; -export { default as Connected } from "./components/dapp/Connected"; diff --git a/src/components/primitives/Switch.tsx b/src/components/primitives/Switch.tsx deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/index.ts b/src/index.ts index 5138c6981..d019bd35c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,41 +1,166 @@ -import "./style.css"; -export * from "./context/Dapp.context"; +/** + * + */ +export * from "./color"; + +/** + * context + */ +export * from "./context/Wallet.context"; export * from "./context/Theme.context"; -export { default as Button } from "./components/primitives/Button"; -export * from "./utils/tailwind"; +export * from "./context/Dapp.context"; -export * from "./components"; +/** + * theme + */ +export * from "./theme/classes"; +export * from "./theme/variables"; + +/** + * hooks + */ +export * from "./hooks/useClipboard"; +export { default as useClipboard } from "./hooks/useClipboard"; +export * from "./hooks/useWalletState"; +export { default as useWalletState } from "./hooks/useWalletState"; + +/** + * components + */ +export * from "./components/VisuallyHidden"; +export { default as VisuallyHidden } from "./components/VisuallyHidden"; + +/** + * hooks/events + */ export * from "./hooks/events/useShortcut"; +export * from "./hooks/events/useOverflowing"; + +/** + * hooks/theming + */ +export * from "./hooks/theming/useThemedVariables"; +export { default as useThemedVariables } from "./hooks/theming/useThemedVariables"; +export * from "./hooks/theming/useThemableProps"; +export { default as useThemableProps } from "./hooks/theming/useThemableProps"; export * from "./hooks/theming/OverrideTheme"; export { default as OverrideTheme } from "./hooks/theming/OverrideTheme"; + +/** + * components/extenders + */ +export * from "./components/extenders/Modal"; +export { default as Modal } from "./components/extenders/Modal"; +export * from "./components/extenders/Card"; +export { default as Card } from "./components/extenders/Card"; +export * from "./components/extenders/Group"; +export { default as Group } from "./components/extenders/Group"; +export * from "./components/extenders/Select"; +export { default as Select } from "./components/extenders/Select"; +export * from "./components/extenders/Dropdown"; +export { default as Dropdown } from "./components/extenders/Dropdown"; +export * from "./components/extenders/Icons"; +export { default as Icons } from "./components/extenders/Icons"; + +/** + * config + */ +export * from "./config/themes"; + +/** + * components/dapp + */ +export * from "./components/dapp/WalletButton"; +export { default as WalletButton } from "./components/dapp/WalletButton"; +export * from "./components/dapp/TransactionButton"; +export { default as TransactionButton } from "./components/dapp/TransactionButton"; +export * from "./components/dapp/WalletConnectors"; +export { default as WalletConnectors } from "./components/dapp/WalletConnectors"; +export * from "./components/dapp/TransactionHelper"; +export { default as TransactionHelper } from "./components/dapp/TransactionHelper"; +export * from "./components/dapp/Connected"; +export { default as Connected } from "./components/dapp/Connected"; +export * from "./components/dapp/Countdown"; +export { default as Countdown } from "./components/dapp/Countdown"; + +/** + * theming + */ +// export * from "./theming/variables"; +export * from "./theming/spacing"; +export * from "./theming/tailwind"; +export * from "./theming/static"; export * from "./theming/coloring"; -export * from "./theming/variables"; + +/** + * components/layout + */ +export * from "./components/layout/Container"; +export { default as Container } from "./components/layout/Container"; + +/** + * components/primitives + */ +export * from "./components/primitives/PrimitiveTag"; +export { default as PrimitiveTag } from "./components/primitives/PrimitiveTag"; +export * from "./components/primitives/Tabs"; +export { default as Tabs } from "./components/primitives/Tabs"; +export * from "./components/primitives/Collapsible"; +export { default as Collapsible } from "./components/primitives/Collapsible"; +export * from "./components/primitives/Slider"; +export { default as Slider } from "./components/primitives/Slider"; +export * from "./components/primitives/ColorPicker"; +export { default as ColorPicker } from "./components/primitives/ColorPicker"; +export * from "./components/primitives/Space"; +export { default as Space } from "./components/primitives/Space"; +export * from "./components/primitives/Block"; +export { default as Block } from "./components/primitives/Block"; +export * from "./components/primitives/Image"; +export { default as Image } from "./components/primitives/Image"; +export * from "./components/primitives/Box"; +export { default as Box } from "./components/primitives/Box"; +export * from "./components/primitives/Tooltip"; +export { default as Tooltip } from "./components/primitives/Tooltip"; +export * from "./components/primitives/Button"; +export { default as Button } from "./components/primitives/Button"; +export * from "./components/primitives/Checkbox"; +export { default as Checkbox } from "./components/primitives/Checkbox"; +export * from "./components/primitives/Icon"; +export { default as Icon } from "./components/primitives/Icon"; +export * from "./components/primitives/EventBlocker"; +export { default as EventBlocker } from "./components/primitives/EventBlocker"; +export * from "./components/primitives/Scroll"; +export { default as Scroll } from "./components/primitives/Scroll"; +export * from "./components/primitives/Value"; +export { default as Value } from "./components/primitives/Value"; +export * from "./components/primitives/Divider"; +export { default as Divider } from "./components/primitives/Divider"; +export * from "./components/primitives/Table"; +export * from "./components/primitives/Input"; +export { default as Input } from "./components/primitives/Input"; +export * from "./components/primitives/Notifications"; +export { default as Notifications } from "./components/primitives/Notifications"; +export * from "./components/primitives/Title"; +export { default as Title } from "./components/primitives/Title"; +export * from "./components/primitives/Accordion"; +export { default as Accordion } from "./components/primitives/Accordion"; +export * from "./components/primitives/Bar"; +export { default as Bar } from "./components/primitives/Bar"; +export * from "./components/primitives/Time"; +export { default as Time } from "./components/primitives/Time"; +export * from "./components/primitives/List"; +export { default as List } from "./components/primitives/List"; +export * from "./components/primitives/Hash"; +export { default as Hash } from "./components/primitives/Hash"; +export * from "./components/primitives/Text"; +export { default as Text } from "./components/primitives/Text"; + +/** + * utils + */ +export * from "./utils/event"; +export * from "./utils/tailwind"; export * from "./utils/css"; +export * from "./utils/formatter.service"; export * from "./utils/types"; - -//Primitives -// export * from "./components/primitives/Block"; -// export * from "./components/primitives/Box"; - -// // export * from "./components/primitives/Checkbox"; -// export * from "./components/primitives/Divider"; -// export * from "./components/primitives/Icon"; -// export * from "./components/primitives/Image"; -// export * from "./components/primitives/Input"; -// // export * from "./components/primitives/Switch"; -// export * from "./components/primitives/Text"; - -// //Extenders -// export { default as Dropdown } from "./components/extenders/Dropdown"; -// export * from "./components/extenders/Dropdown"; -// export * from "./components/extenders/Group"; -// export * from "./components/extenders/Modal"; -// export * from "./components/extenders/Select"; - -// //DApp -// export * from "./context/Dapp.context"; -// export * from "./context/Theme.context"; -// export * from "./components/dapp/WalletButton"; -// // export * from "./components/dapp/WalletConnectors"; - -// //Utils +export * from "./utils/react"; From 22b0ee2799df95ac05f173db177296b47338efb6 Mon Sep 17 00:00:00 2001 From: sheykei Date: Tue, 14 Jan 2025 10:47:14 +0100 Subject: [PATCH 2/2] fix: lint --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index d019bd35c..e9d831d79 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ /** - * + * */ export * from "./color";