Skip to content

Commit ffb3672

Browse files
committed
ci: scripts to inject metric urls for ga
1 parent dde26f4 commit ffb3672

File tree

3 files changed

+51
-39
lines changed

3 files changed

+51
-39
lines changed

src-build/ci-createDistReleaseConfig.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { EOL } from "os";
1010
import os from "os";
1111
import fs from 'fs';
12+
import {patchTauriConfigWithMetricsHTML} from "./utils.js";
1213

1314
const __filename = fileURLToPath(import.meta.url);
1415
const __dirname = dirname(__filename);
@@ -98,8 +99,11 @@ async function ciCreateDistReleaseConfig() {
9899
const bundleIdentifier = BUNDLE_IDENTIFIER_FOR_STAGE[phoenixStage] || "io.phcode.unknown.stage";
99100
console.log("Product Bundle Identifier is: ", bundleIdentifier);
100101
configJson.tauri.bundle.identifier = bundleIdentifier;
102+
103+
patchTauriConfigWithMetricsHTML(configJson);
104+
101105
console.log("Product update endpoints are: ", configJson.tauri.updater.endpoints);
102-
console.log("Writing new dist config json ", tauriConfigPath);
106+
console.log("Writing new dist config json ", tauriConfigPath, configJson);
103107
fs.writeFileSync(tauriConfigPath, JSON.stringify(configJson, null, 4));
104108

105109
// patch info.plist for mac

src-build/createDistReleaseConfig.js

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,20 @@ import {dirname} from "path";
33
import fs from 'fs';
44
import chalk from 'chalk';
55

6-
import {getPlatformDetails} from "./utils.js";
6+
import {getPlatformDetails, patchTauriConfigWithMetricsHTML} from "./utils.js";
77
import os from "os";
88

99
const __filename = fileURLToPath(import.meta.url);
1010
const __dirname = dirname(__filename);
1111

12-
const METRIC_URL_FOR_STAGE = {
13-
"dev": "https://dev.phcode.dev/desktop-metrics.html",
14-
"stage": "https://staging.phcode.dev/desktop-metrics.html",
15-
"production": "https://phcode.dev/desktop-metrics.html"
16-
};
17-
18-
function _patchTauriConfigWithMetricsHTML(tauriConf, metricsHTMLPageURL) {
19-
const window = tauriConf.tauri.windows[1];
20-
if(!window.label === "healthData"){
21-
throw new Error("Expected tauriConf.json- tauri.windows[1].label to be 'healthData'");
22-
}
23-
window.url = metricsHTMLPageURL;
24-
const metricsPageURL = new URL(metricsHTMLPageURL)
25-
const dangerousRemoteDomainIpcAccess = tauriConf.tauri.security.dangerousRemoteDomainIpcAccess;
26-
for(let ipc of dangerousRemoteDomainIpcAccess) {
27-
if(ipc.windows.includes("healthData")){
28-
ipc.scheme = "https";
29-
ipc.domain = metricsPageURL.host;
30-
}
31-
}
32-
}
33-
3412
async function createDistReleaseConfig() {
3513
const platform = getPlatformDetails().platform;
3614
const tauriConfigPath = (platform === "win") ? `${__dirname}\\..\\src-tauri\\tauri.conf.json`
3715
: `${__dirname}/../src-tauri/tauri.conf.json`;
38-
const phoenixConfigPath = (platform === "win") ? `${__dirname}\\...\\..\\phoenix\\dist\\config.json`
39-
: `${__dirname}/../../phoenix/dist/config.json`;
4016
const tauriLocalConfigPath = (platform === "win") ? `${__dirname}\\..\\src-tauri\\tauri-local.conf.json`
4117
: `${__dirname}/../src-tauri/tauri-local.conf.json`;
4218
console.log("Reading Tauri config file: ", tauriConfigPath);
4319
let configJson = JSON.parse(fs.readFileSync(tauriConfigPath));
44-
console.log("Reading Phoenix config file: ", phoenixConfigPath);
45-
let phoenixConfigJson = JSON.parse(fs.readFileSync(phoenixConfigPath));
46-
const phoenixStageInDist = phoenixConfigJson.config.environment;
47-
console.log("Phoenix stage in dist folder is: ", phoenixStageInDist);
4820
console.log(chalk.cyan("\n!Only creating executables. Creating msi, appimage and dmg installers are disabled in this build. If you want to create an installer, use: npm run tauri build manually after setting distDir in tauri conf!\n"));
4921
configJson.tauri.bundle.active = false;
5022
configJson.build.distDir = '../../phoenix/dist/';
@@ -54,14 +26,9 @@ async function createDistReleaseConfig() {
5426
} else {
5527
configJson.tauri.windows[0].url = `phtauri://localhost/v${phoenixVersion}/`;
5628
}
57-
const metricsURLToUse = METRIC_URL_FOR_STAGE[phoenixStageInDist];
58-
if(!metricsURLToUse){
59-
throw new Error("Unknown Phoenix stage(config.environment) in file " + phoenixConfigPath);
60-
}
61-
_patchTauriConfigWithMetricsHTML(configJson, metricsURLToUse);
29+
patchTauriConfigWithMetricsHTML(configJson);
6230
console.log("Window Boot url is: ", configJson.tauri.windows[0].url);
6331
console.log("Writing new local config json ", tauriLocalConfigPath);
64-
console.log("Window Metrics url ", configJson.tauri.windows[1].url);
6532
fs.writeFileSync(tauriLocalConfigPath, JSON.stringify(configJson, null, 4));
6633
}
6734

src-build/utils.js

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import * as fsExtra from "fs-extra";
2-
import {promises as fs} from 'fs';
2+
import fs from 'fs';
3+
import {promises as fsPromises} from 'fs';
34
import * as path from "path";
45
import * as os from "os";
6+
import {fileURLToPath} from "url";
7+
import {dirname} from "path";
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
512

613
/**
714
* Asynchronously removes a specified directory if it exists.
@@ -45,12 +52,12 @@ export async function removeDir(dirPath) {
4552
*/
4653

4754
export async function listFilesAndFolders(startPath, filter) {
48-
let files = await fs.readdir(startPath);
55+
let files = await fsPromises.readdir(startPath);
4956
let folders = [];
5057

5158
for (let file of files) {
5259
let fullPath = path.join(startPath, file);
53-
await fs.stat(fullPath);
60+
await fsPromises.stat(fullPath);
5461
if (file.startsWith(filter)) {
5562
folders.push(fullPath);
5663
}
@@ -90,3 +97,37 @@ export function getSideCarBinName(platform, arch) {
9097
}
9198
throw new Error(`unsupported ${platform} ${arch}`);
9299
}
100+
101+
const METRIC_URL_FOR_STAGE = {
102+
"dev": "https://dev.phcode.dev/desktop-metrics.html",
103+
"stage": "https://staging.phcode.dev/desktop-metrics.html",
104+
"production": "https://phcode.dev/desktop-metrics.html"
105+
};
106+
107+
export function patchTauriConfigWithMetricsHTML(tauriConf) {
108+
const platform = getPlatformDetails().platform;
109+
const phoenixConfigPath = (platform === "win") ? `${__dirname}\\...\\..\\phoenix\\dist\\config.json`
110+
: `${__dirname}/../../phoenix/dist/config.json`;
111+
console.log("Reading Phoenix config file: ", phoenixConfigPath);
112+
let phoenixConfigJson = JSON.parse(fs.readFileSync(phoenixConfigPath));
113+
const phoenixStageInDist = phoenixConfigJson.config.environment;
114+
console.log("Phoenix stage in dist folder is: ", phoenixStageInDist);
115+
const metricsURLToUse = METRIC_URL_FOR_STAGE[phoenixStageInDist];
116+
if(!metricsURLToUse){
117+
throw new Error("Unknown Phoenix stage(config.environment) in file " + phoenixConfigPath);
118+
}
119+
const window = tauriConf.tauri.windows[1];
120+
if(!window.label === "healthData"){
121+
throw new Error("Expected tauriConf.json- tauri.windows[1].label to be 'healthData'");
122+
}
123+
window.url = metricsURLToUse;
124+
const metricsPageURL = new URL(metricsURLToUse)
125+
const dangerousRemoteDomainIpcAccess = tauriConf.tauri.security.dangerousRemoteDomainIpcAccess;
126+
for(let ipc of dangerousRemoteDomainIpcAccess) {
127+
if(ipc.windows.includes("healthData")){
128+
ipc.scheme = "https";
129+
ipc.domain = metricsPageURL.host;
130+
}
131+
}
132+
console.log("Window Metrics url ", tauriConf.tauri.windows[1].url);
133+
}

0 commit comments

Comments
 (0)