-
Notifications
You must be signed in to change notification settings - Fork 53
/
rollup.config.mjs
134 lines (130 loc) · 4.11 KB
/
rollup.config.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import nodeResolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import typescript from "@rollup/plugin-typescript";
import fs from "fs";
import cleanup from "rollup-plugin-cleanup";
import replaceRegEx from "rollup-plugin-re";
function bundle(input, output, isMain, external = []) {
const isWpilib = process.env.ASCOPE_DISTRIBUTOR === "WPILIB";
return {
input: "src/" + input,
output: {
file: "bundles/" + output,
format: isMain ? "cjs" : "es"
},
context: "this",
external: external,
plugins: [
typescript(),
nodeResolve({
preferBuiltins: true
}),
commonjs(),
cleanup(),
json(),
replace({
preventAssignment: true,
values: {
__distributor__: isWpilib ? "WPILib" : "FRC6328",
__build_date__: new Date().toLocaleString("en-US", {
timeZone: "UTC",
hour12: false,
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
timeZoneName: "short"
}),
__copyright__: JSON.parse(
fs.readFileSync("package.json", {
encoding: "utf-8"
})
).build.copyright
}
}),
replaceRegEx({
patterns: [
// Remove unused eval in protobufjs
// https://github.com/protobufjs/protobuf.js/issues/593
{
test: /eval.*\(moduleName\);/g,
replace: "undefined;"
}
]
})
],
onwarn(message, warn) {
// Hide warnings about protobufjs circular dependencies
// https://github.com/protobufjs/protobuf.js/issues/1402
if (message.code === "CIRCULAR_DEPENDENCY") return;
warn(message);
}
};
}
const mainBundles = [
bundle("main/main.ts", "main.js", true, [
"electron",
"electron-fetch",
"fs",
"jsonfile",
"net",
"os",
"path",
"ssh2",
"download",
"ytdl-core",
"tesseract.js"
]),
bundle("preload.ts", "preload.js", true, ["electron"])
];
const largeRendererBundles = [bundle("hub/hub.ts", "hub.js", false), bundle("satellite.ts", "satellite.js", false)];
const smallRendererBundles = [
bundle("editRange.ts", "editRange.js", false),
bundle("unitConversion.ts", "unitConversion.js", false),
bundle("renameTab.ts", "renameTab.js", false),
bundle("editFov.ts", "editFov.js", false),
bundle("sourceListHelp.ts", "sourceListHelp.js", false),
bundle("betaWelcome.ts", "betaWelcome.js", false),
bundle("export.ts", "export.js", false),
bundle("download.ts", "download.js", false),
bundle("preferences.ts", "preferences.js", false),
bundle("licenses.ts", "licenses.js", false)
];
const workerBundles = [
bundle("hub/dataSources/rlog/rlogWorker.ts", "hub$rlogWorker.js", false),
bundle("hub/dataSources/wpilog/wpilogWorker.ts", "hub$wpilogWorker.js", false),
bundle("hub/dataSources/dslog/dsLogWorker.ts", "hub$dsLogWorker.js", false),
bundle("hub/exportWorker.ts", "hub$exportWorker.js", false),
bundle("shared/renderers/threeDimension/workers/loadField.ts", "shared$loadField.js", false),
bundle("shared/renderers/threeDimension/workers/loadRobot.ts", "shared$loadRobot.js", false)
];
const runOwletDownload = {
input: "src/runOwletDownload.ts",
output: {
file: "runOwletDownload.js",
format: "cjs"
},
context: "this",
external: ["download"],
plugins: [
typescript(),
nodeResolve({
preferBuiltins: true
}),
commonjs(),
json()
],
onwarn() {}
};
export default (cliArgs) => {
if (cliArgs.configMain === true) return mainBundles;
if (cliArgs.configLargeRenderers === true) return largeRendererBundles;
if (cliArgs.configSmallRenderers === true) return smallRendererBundles;
if (cliArgs.configWorkers === true) return workerBundles;
if (cliArgs.configRunOwletDownload === true) return runOwletDownload;
return [...mainBundles, ...largeRendererBundles, ...smallRendererBundles, ...workerBundles];
};