Skip to content

Commit

Permalink
feat: export old ui library (#1821)
Browse files Browse the repository at this point in the history
* feat: export old ui library

* fix: vite lib build

* fix: vite lib build
  • Loading branch information
vacekj authored Oct 2, 2024
1 parent 7888ea4 commit 15fe29b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"types": "./dist/src/tailwindConfig.d.ts",
"default": "./dist/src/tailwindConfig.js"
},
"./components/*": {
"types": "./dist/components/ui/*.d.ts",
"default": "./dist/components/ui/*.js"
},
"./*": {
"types": "./dist/src/*/index.d.ts",
"default": "./dist/src/*/index.js"
Expand Down
32 changes: 32 additions & 0 deletions packages/ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { resolve, join } from 'path';
import { readdirSync, existsSync } from 'fs';
import dts from 'vite-plugin-dts';
import { exec } from 'child_process';
import * as path from 'node:path';

/**
* Returns an object with keys as resulting component build paths and values as
Expand All @@ -25,10 +26,35 @@ const getAllUIComponents = (): Record<string, string> => {
);
};

const getDeprecatedUIComponents = (): Record<string, string> => {
const source = resolve(__dirname, 'components/ui');
return getRecursiveTsxFiles(source, 'components/ui');
};

const getRecursiveTsxFiles = (dir: string, baseDir: string): Record<string, string> => {
const files = readdirSync(dir, { withFileTypes: true });
return files.reduce(
(accum, file) => {
const fullPath = join(dir, file.name);
const relativePath = path.relative(resolve(__dirname, baseDir), fullPath);
if (file.isDirectory()) {
return { ...accum, ...getRecursiveTsxFiles(fullPath, baseDir) };
} else if (file.isFile() && file.name.endsWith('.tsx')) {
const key = `${baseDir}/${relativePath.replace(/\.tsx$/, '')}`;
accum[key] = fullPath;
}
return accum;
},
{} as Record<string, string>,
);
};

/** Extends the `getAllUIComponents` function to add support for other useful files */
const getAllEntries = (): Record<string, string> => {
return {
tailwindconfig: resolve('../tailwind-config'),
'src/tailwindConfig': join(__dirname, 'src', 'tailwindConfig.ts'),
...getDeprecatedUIComponents(),
...getAllUIComponents(),
};
};
Expand All @@ -48,6 +74,11 @@ export default defineConfig({
},
},
],
resolve: {
alias: {
'@repo/tailwind-config': path.resolve(__dirname, '../', 'tailwind-config'),
},
},
build: {
emptyOutDir: true,
lib: {
Expand All @@ -64,6 +95,7 @@ export default defineConfig({
'framer-motion',
'styled-components',
'lucide-react',
'react-router-dom',
],
},
},
Expand Down

0 comments on commit 15fe29b

Please sign in to comment.