/
entry-points..js
53 lines (40 loc) · 1.41 KB
/
entry-points..js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import path from 'path';
import fs from 'fs';
// use the first command-line argument as the components directory, or default to 'dist'
// const componentsDir = './dist/components';
const componentsDir = process.argv[2]?'./dist/'+process.argv[2]:'./dist';
// const componentsDir = './dist';
// Get a list of all components with an index.js file
const components = fs
.readdirSync(componentsDir, { withFileTypes: true })
.filter(
(dirent) =>{
// console.log("🚀 ~ dirent === ", dirent);
console.log(
path.join(componentsDir, dirent.name, 'index.js'),
'== exists ==',
fs.existsSync(path.join(componentsDir, dirent.name, 'index.js'))
);
return dirent.isDirectory() && fs.existsSync(path.join(componentsDir, dirent.name, 'index.js'))
}
)
.map((dirent) => dirent.name);
// Generate the exports object
const exports = {
'.': {
import: './dist/index.js',
types: './dist/index.d.ts',
},
};
components.forEach((component) => {
// console.log('component ', component);
exports[`./${component}`] = {
import: `${componentsDir}/${component}/index.js`,
types: `${componentsDir}/${component}/index.d.ts`,
};
});
// Update the package.json file
const packageJsonPath = './package.json';
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
packageJson.exports = exports;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));