Skip to content

Commit d5d0625

Browse files
committed
feat: genrate the barrel dynamically
1 parent f24c12f commit d5d0625

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed
Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
const fs = require('fs');
22
const path = require('path');
33

4-
const components = [
5-
'accordion',
6-
'actionsheet',
7-
'alert',
8-
'alert-dialog',
9-
'avatar',
10-
'button',
11-
'checkbox',
12-
'fab',
13-
'form-control',
14-
'icon',
15-
'image',
16-
'input',
17-
'link',
18-
'menu',
19-
'modal',
20-
'overlay',
21-
'popover',
22-
'pressable',
23-
'progress',
24-
'radio',
25-
'select',
26-
'slider',
27-
'switch',
28-
'textarea',
29-
'toast',
30-
'tooltip'
31-
];
4+
// Dynamically get components from src directory
5+
const getComponents = () => {
6+
const srcPath = path.join(__dirname, '..', 'src');
7+
if (!fs.existsSync(srcPath)) {
8+
console.log('src directory not found');
9+
return [];
10+
}
11+
12+
return fs.readdirSync(srcPath, { withFileTypes: true })
13+
.filter(dirent => dirent.isDirectory())
14+
.map(dirent => dirent.name);
15+
};
3216

33-
const subdirs = ['creator', 'aria'];
17+
// Dynamically get subdirectories for a component
18+
const getSubdirs = (componentPath) => {
19+
if (!fs.existsSync(componentPath)) {
20+
return [];
21+
}
22+
23+
return fs.readdirSync(componentPath, { withFileTypes: true })
24+
.filter(dirent => dirent.isDirectory())
25+
.map(dirent => dirent.name);
26+
};
27+
28+
const components = getComponents();
29+
console.log('Found components:', components);
3430

3531
// Create barrel files for each component and subdir
3632
components.forEach(component => {
33+
const componentSrcPath = path.join(__dirname, '..', 'src', component);
34+
const subdirs = getSubdirs(componentSrcPath);
35+
36+
console.log(`Component ${component} has subdirs:`, subdirs);
37+
3738
subdirs.forEach(subdir => {
38-
const srcPath = path.join(__dirname, '..', 'src', component, subdir);
39+
const srcPath = path.join(componentSrcPath, subdir);
3940
const barrelPath = path.join(__dirname, '..', component, `${subdir}.ts`);
4041

4142
// Check if the source directory exists
@@ -49,6 +50,9 @@ components.forEach(component => {
4950
// Create barrel file
5051
const content = `export * from '../lib/esm/${component}/${subdir}';`;
5152
fs.writeFileSync(barrelPath, content);
53+
console.log(`Created barrel file: ${barrelPath}`);
5254
}
5355
});
5456
});
57+
58+
console.log('Barrel export generation completed!');

0 commit comments

Comments
 (0)