-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathgenerate-entrypoints.mjs
46 lines (44 loc) · 1.14 KB
/
generate-entrypoints.mjs
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
import fs from "node:fs";
import path from "node:path";
import {
__dirname,
entryPointFiles,
entryPointFromFile,
} from "./generate-utils.mjs";
function createEntrypoints() {
for (const entryPointFile of entryPointFiles()) {
const entryPoint = entryPointFromFile(entryPointFile);
if (entryPoint === ".") continue;
const entryPointPath = path.join(__dirname, entryPoint);
if (!fs.existsSync(entryPointPath)) {
// make directory
fs.mkdirSync(entryPointPath, { recursive: true });
}
const extensionless = path.join(
path.parse(entryPointFile).dir,
path.parse(entryPointFile).name,
);
const packagePath = path.join(entryPointPath, "package.json");
const parts = entryPoint.split("/");
const dist = path.join(
parts
.slice(1)
.map(() => "..")
.join("/"),
"dist",
);
fs.writeFileSync(
packagePath,
JSON.stringify(
{
type: "module",
module: path.join(dist, `${extensionless}.js`),
types: path.join(dist, `${extensionless}.d.ts`),
},
null,
2,
),
);
}
}
createEntrypoints();