-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpost-build.js
More file actions
34 lines (28 loc) · 1.23 KB
/
post-build.js
File metadata and controls
34 lines (28 loc) · 1.23 KB
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
// @ts-check
import fs from "node:fs";
/** @type {(path: string) => URL} */
const relative = (path) => new URL(path, import.meta.url);
// Add the global declarations to the `dist` directory
fs.copyFileSync(relative("./src/globals.d.ts"), relative("./dist/globals.d.ts"));
let additionalExports = `
// Include declarations for all Java types
export * from "./globals";
`;
// All useful Java objects are converted to TypeScript types in `target/types`
const javaTypes = fs.readdirSync(relative("./target/types/"));
// Copy all Java types to the `dist/types` directory, append them to the `dist/index.d.ts`
for (const javaType of javaTypes) {
fs.copyFileSync(relative(`./target/types/${javaType}`), relative(`./dist/${javaType}`));
additionalExports += `export * from "./${javaType.replace(/\.d\.ts$/, "")}";\n`;
}
fs.appendFileSync(new URL("./dist/index.d.ts", import.meta.url), additionalExports);
// Add an helpful message to the user in case they try to import the `dist` directory
fs.writeFileSync(
relative("./dist/index.js"),
`console.error(
"You cannot import and run '@jahia/javascript-modules-library' because it's a virtual module.\\n" +
"Ensure the library is marked as *external* in your build configuration."
);
export {};
`,
);