Skip to content

Commit 0b9543e

Browse files
ga added to build
1 parent 9627e72 commit 0b9543e

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

electron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"dev": "npm run build && electron .",
88
"build": "npm run build:main && npm run build:preload && npm run build:renderer && npm run copy-assets",
9-
"build:main": "esbuild src/main/main.ts --bundle --platform=node --external:electron --outfile=dist/main/main.js",
9+
"build:main": "node scripts/build-main.mjs",
1010
"build:preload": "esbuild src/main/preload.ts --bundle --platform=node --external:electron --outfile=dist/main/preload.js",
1111
"build:renderer": "esbuild src/renderer/renderer.ts --bundle --platform=browser --outfile=dist/renderer/renderer.js",
1212
"copy-assets": "node -e \"const fs=require('fs');fs.cpSync('src/renderer/index.html','dist/renderer/index.html');fs.cpSync('src/renderer/index.css','dist/renderer/index.css');\"",

electron/scripts/build-main.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { build } from "esbuild";
2+
3+
const measurementId = process.env.GA_MEASUREMENT_ID || "";
4+
const apiSecret = process.env.GA_API_SECRET || "";
5+
const debug = process.env.GA_DEBUG || "";
6+
7+
await build({
8+
entryPoints: ["src/main/main.ts"],
9+
bundle: true,
10+
platform: "node",
11+
external: ["electron"],
12+
outfile: "dist/main/main.js",
13+
define: {
14+
__GA_MEASUREMENT_ID__: JSON.stringify(measurementId),
15+
__GA_API_SECRET__: JSON.stringify(apiSecret),
16+
__GA_DEBUG__: JSON.stringify(debug),
17+
},
18+
});

electron/src/main/main.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,25 @@ import { randomUUID } from "crypto";
1212
import * as https from "https";
1313
import { readGitRepo } from "../git/GitReader";
1414

15+
declare const __GA_MEASUREMENT_ID__: string | undefined;
16+
declare const __GA_API_SECRET__: string | undefined;
17+
declare const __GA_DEBUG__: string | undefined;
18+
1519
let mainWindow: BrowserWindow | null = null;
1620
let currentRepoPath: string | null = null;
1721
let gitWatcher: fs.FSWatcher | null = null;
1822
let workingDirWatcher: fs.FSWatcher | null = null;
1923
let debounceTimer: NodeJS.Timeout | null = null;
2024

2125
const analyticsConfig = {
22-
measurementId: process.env.GA_MEASUREMENT_ID || "",
23-
apiSecret: process.env.GA_API_SECRET || "",
24-
debug: process.env.GA_DEBUG === "1" || process.env.GA_DEBUG === "true",
26+
measurementId:
27+
process.env.GA_MEASUREMENT_ID || __GA_MEASUREMENT_ID__ || "",
28+
apiSecret: process.env.GA_API_SECRET || __GA_API_SECRET__ || "",
29+
debug:
30+
process.env.GA_DEBUG === "1" ||
31+
process.env.GA_DEBUG === "true" ||
32+
__GA_DEBUG__ === "1" ||
33+
__GA_DEBUG__ === "true",
2534
};
2635

2736
type AnalyticsEventParams = Record<string, string | number | boolean>;

0 commit comments

Comments
 (0)