@supernovaio/cli
Version:
Supernova.io Command Line Interface
76 lines (74 loc) • 3.27 kB
JavaScript
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="af468e50-9d68-5eb5-8f11-468ade254f2f")}catch(e){}}();
import { z } from "zod";
const allTargetEnvs = ["demo", "development", "local", "production", "staging"];
export const TargetEnv = z.enum(allTargetEnvs);
const DevTargetEnvAlias = z.enum(["dev", "develop"]);
const StagingTargetEnvAlias = z.enum(["stg"]);
const defaultTargetEnv = "production";
export function getTargetEnv() {
if (process.env.SUPERNOVA_ENV) {
const raw = process.env.SUPERNOVA_ENV.toLowerCase();
const baseParseResult = TargetEnv.safeParse(raw);
if (baseParseResult.success)
return baseParseResult.data;
const devAliasParseResult = DevTargetEnvAlias.safeParse(raw);
if (devAliasParseResult.success)
return "development";
const stgAliasParseResult = StagingTargetEnvAlias.safeParse(raw);
if (stgAliasParseResult.success)
return "staging";
console.warn(`Incorrect value of SUPERNOVA_ENV variable, allowed options are: [${allTargetEnvs.join(",")}] `);
console.warn(`Using defaut env instead (${defaultTargetEnv})`);
}
return defaultTargetEnv;
}
const authServerUrlMap = {
demo: "https://auth-2.demo.supernova.io/api/plugin-oauth",
development: "https://auth-2.dev.supernova.io/api/plugin-oauth",
local: `https://auth-2.dev.supernova.io/api/plugin-oauth`,
production: "https://auth-2.supernova.io/api/plugin-oauth",
staging: "https://auth-2.staging.supernova.io/api/plugin-oauth",
};
export function authUrlForEnvironment(env) {
return authServerUrlMap[env];
}
export function storybookUrlForEnvironment(env) {
switch (env) {
case "demo":
return "https://storybook.demo.sst.supernova.io";
case "development":
return "https://storybook.dev.supernova.io";
case "local":
return `https://storybook.${getLocalStageName()}.sst.supernova.io`;
case "production":
return "https://storybook.supernova.io";
case "staging":
return "https://storybook.staging.supernova.io";
}
}
export function apiHostForEnvironment(env) {
switch (env) {
case "demo":
return "api.demo.supernova.io";
case "development":
return "api.dev.supernova.io";
case "local":
return `api-5.${getLocalStageName()}.sst.supernova.io`;
case "production":
return "api.supernova.io";
case "staging":
return "api.staging.supernova.io";
}
}
export function apiUrlForEnvironment(env, version = "/v2") {
return `https://${apiHostForEnvironment(env)}/api${version ?? ''}`;
}
function getLocalStageName() {
const parseResult = z.string().safeParse(process.env.SUPERNOVA_STAGE_NAME);
if (!parseResult.success) {
throw new Error(`To use local environment, SUPERNOVA_STAGE_NAME variable must be set`);
}
return parseResult.data;
}
//# sourceMappingURL=environment.js.map
//# debugId=af468e50-9d68-5eb5-8f11-468ade254f2f