mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
back
This commit is contained in:
55
packages/cli/src/utils/env/index.test.tsx
vendored
Normal file
55
packages/cli/src/utils/env/index.test.tsx
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
import { getNodeEnv } from ".";
|
||||
|
||||
test("Get NODE_ENV", async () => {
|
||||
const testCases = [
|
||||
{
|
||||
input: "development",
|
||||
expected: "development",
|
||||
},
|
||||
{
|
||||
input: "dev",
|
||||
expected: "development",
|
||||
},
|
||||
{
|
||||
input: "Production",
|
||||
expected: "production",
|
||||
},
|
||||
{
|
||||
input: "prod",
|
||||
expected: "production",
|
||||
},
|
||||
{
|
||||
input: "test",
|
||||
expected: "test",
|
||||
},
|
||||
{
|
||||
input: "TESTING",
|
||||
expected: "test",
|
||||
},
|
||||
{
|
||||
input: "ci",
|
||||
expected: "continuous-integration",
|
||||
},
|
||||
{
|
||||
input: "UAT",
|
||||
expected: "user-acceptance-testing",
|
||||
},
|
||||
{
|
||||
input: "SIT",
|
||||
expected: "system-integration-testing",
|
||||
},
|
||||
{
|
||||
input: "another-node-env",
|
||||
expected: "custom",
|
||||
},
|
||||
{
|
||||
input: "",
|
||||
expected: "development",
|
||||
},
|
||||
];
|
||||
|
||||
for (const testCase of testCases) {
|
||||
process.env.NODE_ENV = testCase.input;
|
||||
expect(getNodeEnv()).toEqual(testCase.expected);
|
||||
}
|
||||
});
|
||||
47
packages/cli/src/utils/env/index.ts
vendored
Normal file
47
packages/cli/src/utils/env/index.ts
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import { NODE_ENV } from "@definitions/node";
|
||||
import * as dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
const envSearchMap: Record<Exclude<NODE_ENV, "custom">, RegExp> = {
|
||||
development: /dev/i,
|
||||
production: /prod/i,
|
||||
test: /test|tst/i,
|
||||
"continuous-integration": /ci/i,
|
||||
"user-acceptance-testing": /uat/i,
|
||||
"system-integration-testing": /sit/i,
|
||||
};
|
||||
|
||||
export const getNodeEnv = (): NODE_ENV => {
|
||||
const nodeEnv = process.env.NODE_ENV;
|
||||
|
||||
if (!nodeEnv) {
|
||||
return "development";
|
||||
}
|
||||
|
||||
let env: NODE_ENV = "custom";
|
||||
|
||||
for (const [key, value] of Object.entries(envSearchMap)) {
|
||||
if (value.test(nodeEnv)) {
|
||||
env = key as NODE_ENV;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return env;
|
||||
};
|
||||
|
||||
export const ENV = {
|
||||
NODE_ENV: getNodeEnv(),
|
||||
REFINE_NO_TELEMETRY: process.env.REFINE_NO_TELEMETRY || "false",
|
||||
UPDATE_NOTIFIER_IS_DISABLED:
|
||||
process.env.UPDATE_NOTIFIER_IS_DISABLED || "false",
|
||||
UPDATE_NOTIFIER_CACHE_TTL:
|
||||
process.env.UPDATE_NOTIFIER_CACHE_TTL || 1000 * 60 * 60 * 24, // 24 hours,
|
||||
REFINE_PROXY_DOMAIN:
|
||||
process.env.REFINE_PROXY_DOMAIN || "https://refine.dev",
|
||||
REFINE_PROXY_TARGET:
|
||||
process.env.REFINE_PROXY_TARGET || "http://localhost:3000",
|
||||
REFINE_PROXY_PORT: process.env.REFINE_PROXY_PORT || "7313",
|
||||
REFINE_PROXY_REWRITE_URL:
|
||||
process.env.REFINE_REWRITE_URL || "http://localhost:7313",
|
||||
};
|
||||
Reference in New Issue
Block a user