-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.helpers.mjs
More file actions
80 lines (70 loc) · 2.46 KB
/
build.helpers.mjs
File metadata and controls
80 lines (70 loc) · 2.46 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { existsSync as pathExists } from "node:fs";
import fs from "node:fs/promises";
async function ensureExtensionDirectoryExists(appDir, extensionDirectoryName) {
if (appDir.trim() !== "" && pathExists(appDir)) {
const extDir = `${appDir}/${extensionDirectoryName}`;
if (!pathExists(extDir)) {
await fs.mkdir(extDir);
}
return extDir;
}
}
async function copyExtensionAssetsToApplication(appExtensionDirPath, outDir) {
const extensionName = outDir.split("/").pop();
const deployedExtensionPath = `${appExtensionDirPath}/${extensionName}`;
if (pathExists(deployedExtensionPath)) {
await fs.rm(deployedExtensionPath, { recursive: true, force: true });
}
await fs.mkdir(deployedExtensionPath);
await fs.cp(outDir, deployedExtensionPath, { recursive: true });
}
export const copyToAppPlugin = (appDir, outDir, extensionDirectoryName) => ({
name: "copy-to-app",
setup(build) {
build.onEnd(async result => {
if (!result.errors.length) {
const appExtensionDirPath = await ensureExtensionDirectoryExists(appDir, extensionDirectoryName);
if (appExtensionDirPath) {
copyExtensionAssetsToApplication(appExtensionDirPath, outDir);
} else {
console.error("Could not find Mendix application directory:", appDir);
console.info("Skipping copying the extension to application directory");
}
}
});
}
});
export const copyManifestPlugin = outDir => ({
name: "copy-manifest",
setup(build) {
build.onEnd(async result => {
if (!result.errors.length) {
try {
await fs.copyFile("src/manifest.json", `${outDir}/manifest.json`);
} catch (error) {
console.error("Make sure that manifest.json file is present in src/ folder", error);
}
}
});
}
});
export const commonConfig = {
target: "es2023",
platform: "browser",
format: "esm",
bundle: true,
splitting: true,
treeShaking: true,
logLevel: "info",
assetNames: "assets/[ext]/[name]-[hash]",
external: ["@mendix/component-framework", "@mendix/model-access-sdk"],
loader: {
".png": "file",
".svg": "file",
".gif": "file",
".ttf": "file",
".woff": "file",
".woff2": "file"
},
sourcemap: true
};