From 37d90197b63bcafa77e563d456f93d89fd365799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bouget?= Date: Tue, 5 Mar 2024 17:16:41 +0100 Subject: [PATCH] Try ga env var --- package.json | 2 +- scripts/set-env.js | 12 ++++++++++++ src/environments/environment.dev.ts | 1 - src/environments/environment.prod.ts | 1 - src/environments/environment.ts | 1 - 5 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 scripts/set-env.js diff --git a/package.json b/package.json index 77e18fe..ee6d51c 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "build-visu": "cd ../visualization-component && yarn build:webcomponents", "build": "npm run electron:serve-tsc && ng build --base-href ./", "build:dev": "npm run build -- -c dev", - "build:prod": "npm run build -- -c production && npm run removeMocks", + "build:prod": "node set-env.js && npm run build -- -c production && npm run removeMocks", "web:build": "npm run build -- -c web-production", "electron": "electron", "electron:serve-tsc": "tsc -p tsconfig.serve.json", diff --git a/scripts/set-env.js b/scripts/set-env.js new file mode 100644 index 0000000..146d66d --- /dev/null +++ b/scripts/set-env.js @@ -0,0 +1,12 @@ +const fs = require("fs"); + +const envFilePath = "./src/environments/environment.prod.ts"; +let envFileContent = fs.readFileSync(envFilePath, "utf8"); +const trackerId = process.env.TRACKER_ID; +if (!envFileContent.includes("TRACKER_ID")) { + envFileContent = envFileContent.replace( + /}\s*$/, + ` TRACKER_ID: "${trackerId}",\n}` + ); +} +fs.writeFileSync(envFilePath, envFileContent); diff --git a/src/environments/environment.dev.ts b/src/environments/environment.dev.ts index 4b48ddf..3fe3326 100644 --- a/src/environments/environment.dev.ts +++ b/src/environments/environment.dev.ts @@ -1,5 +1,4 @@ export const APP_CONFIG = { production: false, environment: 'DEV', - TRACKER_ID: process.env.TRACKER_ID, }; diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 8335552..eb2269c 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,5 +1,4 @@ export const APP_CONFIG = { production: true, environment: 'PROD', - TRACKER_ID: process.env.TRACKER_ID, }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index b00b2e0..fd538c5 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -1,5 +1,4 @@ export const APP_CONFIG = { production: false, environment: 'LOCAL', - TRACKER_ID: process.env.TRACKER_ID, };