-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mjs
46 lines (39 loc) · 1.28 KB
/
build.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 { promises as fs } from "fs";
import esbuild from "esbuild";
import path from "path";
const modules = [
"cytoscape",
"cytoscape-cola",
"neo4j-driver",
"@popperjs/core",
"cytoscape-popper"
];
for (const module of modules) {
// Construct the package.json path
const packageJsonPath = path.resolve(`./node_modules/${module}/package.json`);
try {
// Read and parse package.json
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf-8"));
const version = packageJson.version;
// Determine the entry point (favoring "module" over "main" for ESM compatibility)
const entryPoint = packageJson.module || packageJson.main;
if (!entryPoint) {
console.warn(`No entry point found for ${module}, skipping.`);
continue;
}
const resolvedEntry = path.resolve(`./node_modules/${module}/${entryPoint}`);
const outputFile = `docs/lib/${module}@${version}.mjs`;
// Build the module using esbuild
await esbuild.build({
entryPoints: [resolvedEntry],
outfile: outputFile,
format: "esm",
bundle: true,
platform: "browser",
external: [module]
});
console.log(`Built ${module} -> ${outputFile}`);
} catch (error) {
console.error(`Failed to process ${module}:`, error.message);
}
}