Skip to content

Commit

Permalink
Clean up build constants support
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Aug 6, 2023
1 parent 29ae259 commit 1447693
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 91 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,36 @@ It includes the following tools:

1. Find the [latest release](https://github.com/Mechanical-Advantage/AdvantageScope/releases/latest) under "Releases".
2. Download the appropriate build based on the OS & architecture. AdvantageScope supports Windows, macOS, and Linux on both x86 and ARM architectures.

## Building

To install all dependencies, run:

```bash
npm install
```

To build for the current platform, run:

```bash
npm run build
```

To build for another platform, run:

```bash
npm run build -- --win --x64 # For full list of options, run "npx electron-builder help"
```

To build the WPILib version, set the environment variable `ASCOPE_DISTRIBUTOR` to `WPILIB` before building:

```bash
export ASCOPE_DISTRIBUTOR=WPILIB
```

For development, run:

```bash
npm run watch
npm start
```
126 changes: 58 additions & 68 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,66 @@ import replace from "@rollup/plugin-replace";
import typescript from "@rollup/plugin-typescript";
import cleanup from "rollup-plugin-cleanup";

const bundle = (input, output, isWpilib, external = []) => ({
input: "src/" + input,
output: {
file: "bundles/" + output,
format: "cjs"
},
plugins: [
typescript(),
nodeResolve(),
commonjs(),
cleanup(),
replace({
preventAssignment: true,
values: {
__distributor__: isWpilib ? "WPILib" : "Team6328",
__build_date__: new Date().toUTCString()
}
})
],
external: external
});

function mainBundles(isWpilib) {
return [
bundle("main/main.ts", "main.js", isWpilib, [
"electron",
"electron-fetch",
"fs",
"jsonfile",
"net",
"os",
"path",
"ssh2"
]),
bundle("preload.ts", "preload.js", isWpilib, ["electron"])
];
}
function largeRendererBundles(isWpilib) {
return [bundle("hub/hub.ts", "hub.js", isWpilib), bundle("satellite.ts", "satellite.js", isWpilib)];
}
function smallRendererBundles(isWpilib) {
return [
bundle("editRange.ts", "editRange.js", isWpilib),
bundle("unitConversion.ts", "unitConversion.js", isWpilib),
bundle("renameTab.ts", "renameTab.js", isWpilib),
bundle("export.ts", "export.js", isWpilib),
bundle("download.ts", "download.js", isWpilib),
bundle("preferences.ts", "preferences.js", isWpilib)
];
}
function workerBundles(isWpilib) {
return [
bundle("hub/dataSources/rlogWorker.ts", "hub$rlogWorker.js", isWpilib),
bundle("hub/dataSources/wpilogWorker.ts", "hub$wpilogWorker.js", isWpilib),
bundle("hub/dataSources/dsLogWorker.ts", "hub$dsLogWorker.js", isWpilib),
bundle("hub/exportWorker.ts", "hub$exportWorker.js", isWpilib)
];
function bundle(input, output, external = []) {
let isWpilib = process.env.ASCOPE_DISTRIBUTOR === "WPILIB";
return {
input: "src/" + input,
output: {
file: "bundles/" + output,
format: "cjs"
},
plugins: [
typescript(),
nodeResolve(),
commonjs(),
cleanup(),
replace({
preventAssignment: true,
values: {
__distributor__: isWpilib ? "WPILib" : "LittletonRobotics",
__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"
})
}
})
],
external: external
};
}

const mainBundles = [
bundle("main/main.ts", "main.js", ["electron", "electron-fetch", "fs", "jsonfile", "net", "os", "path", "ssh2"]),
bundle("preload.ts", "preload.js", ["electron"])
];
const largeRendererBundles = [bundle("hub/hub.ts", "hub.js"), bundle("satellite.ts", "satellite.js")];
const smallRendererBundles = [
bundle("editRange.ts", "editRange.js"),
bundle("unitConversion.ts", "unitConversion.js"),
bundle("renameTab.ts", "renameTab.js"),
bundle("export.ts", "export.js"),
bundle("download.ts", "download.js"),
bundle("preferences.ts", "preferences.js")
];
const workerBundles = [
bundle("hub/dataSources/rlogWorker.ts", "hub$rlogWorker.js"),
bundle("hub/dataSources/wpilogWorker.ts", "hub$wpilogWorker.js"),
bundle("hub/dataSources/dsLogWorker.ts", "hub$dsLogWorker.js"),
bundle("hub/exportWorker.ts", "hub$exportWorker.js")
];

export default (cliArgs) => {
const isWpilib = cliArgs.configWpilib;
if (cliArgs.configMain === true) return mainBundles(isWpilib);
if (cliArgs.configLargeRenderers === true) return largeRendererBundles(isWpilib);
if (cliArgs.configSmallRenderers === true) return smallRendererBundles(isWpilib);
if (cliArgs.configWorkers === true) return workerBundles(isWpilib);
if (cliArgs.configMain === true) return mainBundles;
if (cliArgs.configLargeRenderers === true) return largeRendererBundles;
if (cliArgs.configSmallRenderers === true) return smallRendererBundles;
if (cliArgs.configWorkers === true) return workerBundles;

return [
...mainBundles(isWpilib),
...largeRendererBundles(isWpilib),
...smallRendererBundles(isWpilib),
...workerBundles(isWpilib)
];
return [...mainBundles, ...largeRendererBundles, ...smallRendererBundles, ...workerBundles];
};
71 changes: 49 additions & 22 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { createExtraFRCDataFolder, loadFRCData } from "./frcDataUtil";
import StateTracker from "./StateTracker";
import UpdateChecker from "./UpdateChecker";
import videoExtensions from "./videoExtensions";
import { BUILD_DATE, DISTRIBUTOR, Distributor } from "../shared/buildConstants";

// Global variables
let hubWindows: BrowserWindow[] = []; // Ordered by last focus time (recent first)
Expand Down Expand Up @@ -1229,7 +1230,12 @@ function setupMenu() {
template.splice(0, 0, {
role: "appMenu",
submenu: [
{ role: "about" },
{
label: "About AdvantageScope",
click() {
createAboutWindow();
}
},
{ type: "separator" },
{
label: "Preferences...",
Expand All @@ -1239,12 +1245,16 @@ function setupMenu() {
openPreferences(window);
}
},
{
label: "Check for Updates...",
click() {
checkForUpdate(true);
}
},
...(DISTRIBUTOR === Distributor.LittletonRobotics
? [
{
label: "Check for Updates...",
click() {
checkForUpdate(true);
}
}
]
: []),
{ type: "separator" },
{ role: "services" },
{ type: "separator" },
Expand All @@ -1262,14 +1272,7 @@ function setupMenu() {
{
label: "About AdvantageScope",
click() {
dialog.showMessageBox({
type: "info",
title: "About",
message: "AdvantageScope",
detail: "Version: " + app.getVersion() + "\nPlatform: " + process.platform + "-" + process.arch,
buttons: ["Close"],
icon: WINDOW_ICON
});
createAboutWindow();
}
},
{
Expand All @@ -1280,12 +1283,16 @@ function setupMenu() {
openPreferences(window);
}
},
{
label: "Check for Updates...",
click() {
checkForUpdate(true);
}
},
...(DISTRIBUTOR === Distributor.LittletonRobotics
? [
{
label: "Check for Updates...",
click() {
checkForUpdate(true);
}
}
]
: []),
{ type: "separator" }
);
}
Expand All @@ -1294,6 +1301,24 @@ function setupMenu() {
Menu.setApplicationMenu(menu);
}

/** Creates the "About AdvantageScope" window. */
function createAboutWindow() {
let detailLines: string[] = [];
detailLines.push("Version: " + (app.isPackaged ? app.getVersion() : "Development"));
detailLines.push("Distributor: " + (DISTRIBUTOR === Distributor.WPILib ? "WPILib" : "Littleton Robotics"));
detailLines.push("Platform: " + process.platform + "-" + process.arch);
detailLines.push("Build Date: " + BUILD_DATE);
dialog.showMessageBox({
type: "info",
title: "About",
message: "AdvantageScope",
detail: detailLines.join("\n"),
buttons: ["Close"],
// textWidth: 200,
icon: WINDOW_ICON
});
}

/** Creates a new hub window. */
function createHubWindow() {
let prefs: BrowserWindowConstructorOptions = {
Expand Down Expand Up @@ -1874,7 +1899,9 @@ app.whenReady().then(() => {
});

// Check for update and show button on hub windows (but don't prompt)
checkForUpdate(false);
if (DISTRIBUTOR === Distributor.LittletonRobotics) {
checkForUpdate(false);
}
});

app.on("window-all-closed", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/buildConstants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export enum Distributor {
Team6328,
LittletonRobotics,
WPILib
}

Expand Down

0 comments on commit 1447693

Please sign in to comment.