diff --git a/package.json b/package.json index 46764c4..e9977d8 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": "node set-env.js && npm run build -- -c production && npm run removeMocks", + "build:prod": "node ./scripts/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 index 146d66d..7b171a5 100644 --- a/scripts/set-env.js +++ b/scripts/set-env.js @@ -3,10 +3,11 @@ 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); + +// insert trackerId to the env file +let index = envFileContent.indexOf("{"); +let res = + envFileContent.slice(0, index + 1) + + ` TRACKER_ID: "${trackerId}",` + + envFileContent.slice(index + 1); +fs.writeFileSync(envFilePath, res);