-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-exports.js
45 lines (38 loc) · 1.12 KB
/
generate-exports.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
import fs from "fs";
import path from "path";
const distPath = "./dist";
const excludeFolders = ["rest-api"]; // Add the names of folders you want to exclude
const components = fs.readdirSync(distPath).filter((file) => {
return (
fs.statSync(path.join(distPath, file)).isDirectory() &&
!excludeFolders.includes(file)
);
});
const exportsObject = {
".": {
import: "./dist/index.js",
types: "./dist/types/index.d.ts",
},
"./di-types": {
import: "./dist/types.js",
types: "./dist/types.d.ts",
},
"./resolver": {
import: "./dist/resolver.js",
types: "./dist/resolver.d.ts",
},
"./config": {
import: "./dist/config.js",
types: "./dist/config.d.ts",
},
};
components.forEach((component) => {
exportsObject[`./${component}`] = {
import: `./dist/${component}/index.js`,
types: `./dist/${component}/index.d.ts`,
};
});
const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf-8"));
packageJson.exports = exportsObject;
fs.writeFileSync("./package.json", JSON.stringify(packageJson, null, 2));
console.log("exports field generated and saved to package.json");