Skip to content

Commit

Permalink
chore: add env based var via jenkins (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja authored Dec 11, 2024
1 parent 61d1c2c commit ea411f2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ENV_BACKEND_URL=""
ENV_LOGGING_URL=""
SDK_ENV="local"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ In the [`webpack.common.js`](./webpack.common.js) file, you would have to enable

```javascipt
let logEndpoint =
sdkEnv === "prod"
SDK_ENV === "prod"
? "<YOUR_PRODUCTION_LOGGING_ENDPOINT>"
: "<YOUR_SANDBOX_LOGGING_ENDPOINT>";
// Set this to true to enable logging
let enableLogging = true;
let ENABLE_LOGGING = true;
// Choose from DEBUG, INFO, WARNING, ERROR, SILENT
let loggingLevel = "DEBUG";
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
},
"scripts": {
"build": "webpack --config webpack.common.js",
"build:integ": "cross-env sdkEnv=integ enableLogging=false webpack --config webpack.common.js",
"build:integ": "cross-env webpack --config webpack.common.js",
"build:playground": "npm run setup:playground && npm run build",
"build:prod": "cross-env sdkEnv=prod enableLogging=true webpack --config webpack.common.js",
"build:sandbox": "cross-env sdkEnv=sandbox enableLogging=true webpack --config webpack.common.js",
"build:prod": "cross-env webpack --config webpack.common.js",
"build:sandbox": "cross-env webpack --config webpack.common.js",
"deploy-to-s3": "node ./scripts/pushToS3.js",
"postinstall": "cd Hyperswitch-React-Demo-App && npm i",
"prepare": "husky install",
Expand All @@ -29,7 +29,7 @@
"re:format": "rescript format -all",
"re:start": "rescript -w",
"setup:playground": "npm run postinstall && cd Hyperswitch-React-Demo-App && node promptScript.js",
"start": "cross-env sdkEnv=local enableLogging=false webpack serve --config webpack.dev.js",
"start": "cross-env webpack serve --config webpack.dev.js",
"start:playground": "npm run setup:playground && npm run start",
"test": "cd cypress-tests && npm run cypress:run",
"test:hooks": "npx eslint src/"
Expand Down
2 changes: 2 additions & 0 deletions src/Payments/CardPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ let make = (
~isGuestCustomer,
)

Console.log2(">>>> Logs Debug >>>>", (GlobalVars.enableLogging, GlobalVars.logEndpoint))

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->safeParse
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
Expand Down
22 changes: 11 additions & 11 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const AddReactDisplayNamePlugin = require("babel-plugin-add-react-displayname");
const getEnvVariable = (variable, defaultValue) =>
process.env[variable] ?? defaultValue;

const sdkEnv = getEnvVariable("sdkEnv", "local");
const enableLogging = getEnvVariable("enableLogging", "false") === "true";
const SDK_ENV = getEnvVariable("SDK_ENV", "local");
const ENABLE_LOGGING = getEnvVariable("ENABLE_LOGGING", "false") === "true";
const envSdkUrl = getEnvVariable("ENV_SDK_URL", "");
const envBackendUrl = getEnvVariable("ENV_BACKEND_URL", "");
const envLoggingUrl = getEnvVariable("ENV_LOGGING_URL", "");
Expand All @@ -23,7 +23,7 @@ const repoVersion = require("./package.json").version;
const majorVersion = "v" + repoVersion.split(".")[0];
const repoName = require("./package.json").name;
const repoPublicPath =
sdkEnv === "local" ? "" : `/web/${repoVersion}/${majorVersion}`;
SDK_ENV === "local" ? "" : `/web/${repoVersion}/${majorVersion}`;

const getSdkUrl = (env, customUrl) => {
if (customUrl) return customUrl;
Expand All @@ -36,9 +36,9 @@ const getSdkUrl = (env, customUrl) => {
return urls[env] || urls.local;
};

const sdkUrl = getSdkUrl(sdkEnv, envSdkUrl);
const sdkUrl = getSdkUrl(SDK_ENV, envSdkUrl);
const getEnvironmentDomain = (prodDomain, integDomain, defaultDomain) => {
switch (sdkEnv) {
switch (SDK_ENV) {
case "prod":
return prodDomain;
case "integ":
Expand Down Expand Up @@ -82,7 +82,7 @@ module.exports = (publicPath = "auto") => {
logEndpoint: JSON.stringify(logEndpoint),
sentryDSN: JSON.stringify(process.env.SENTRY_DSN),
sentryScriptUrl: JSON.stringify(process.env.SENTRY_SCRIPT_URL),
enableLogging: enableLogging,
enableLogging: ENABLE_LOGGING,
loggingLevel: JSON.stringify(loggingLevel),
maxLogsPushedPerEventName: JSON.stringify(maxLogsPushedPerEventName),
}),
Expand Down Expand Up @@ -129,18 +129,18 @@ module.exports = (publicPath = "auto") => {
}

return {
mode: sdkEnv === "local" ? "development" : "production",
devtool: sdkEnv === "local" ? "eval-source-map" : "source-map",
mode: SDK_ENV === "local" ? "development" : "production",
devtool: SDK_ENV === "local" ? "eval-source-map" : "source-map",
output: {
path:
sdkEnv && sdkEnv !== "local"
? path.resolve(__dirname, "dist", sdkEnv)
SDK_ENV && SDK_ENV !== "local"
? path.resolve(__dirname, "dist", SDK_ENV)
: path.resolve(__dirname, "dist"),
clean: true,
publicPath: `${repoPublicPath}/`,
},
optimization:
sdkEnv === "local"
SDK_ENV === "local"
? {}
: {
sideEffects: true,
Expand Down
4 changes: 2 additions & 2 deletions webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require("dotenv").config();
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");

const sdkEnv = process.env.sdkEnv ?? "local";
const SDK_ENV = process.env.SDK_ENV ?? "local";

const endpointMap = {
prod: "https://api.hyperswitch.io/payments",
Expand All @@ -12,7 +12,7 @@ const endpointMap = {
local: "https://sandbox.hyperswitch.io/payments", // Default or local environment endpoint
};

const backendEndPoint = endpointMap[sdkEnv] || endpointMap.local;
const backendEndPoint = endpointMap[SDK_ENV] || endpointMap.local;

const devServer = {
static: {
Expand Down

0 comments on commit ea411f2

Please sign in to comment.