2024-02-05 09:15:37 +08:00
|
|
|
import type { GlobEnvConfig } from '/#/config';
|
|
|
|
|
|
|
|
|
|
import { warn } from '/@/utils/log';
|
|
|
|
|
import pkg from '../../package.json';
|
|
|
|
|
import { getConfigFileName } from '../../build/getConfigFileName';
|
|
|
|
|
|
|
|
|
|
export function getCommonStoragePrefix() {
|
2024-06-11 17:09:39 +08:00
|
|
|
const { VITE_GLOB_APP_SHORT_NAME } = getAppEnvConfig();
|
|
|
|
|
return `${VITE_GLOB_APP_SHORT_NAME}__${getEnv()}`.toUpperCase();
|
2024-02-05 09:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate cache key according to version
|
|
|
|
|
export function getStorageShortName() {
|
2024-06-11 17:09:39 +08:00
|
|
|
return `${getCommonStoragePrefix()}${`__${pkg.version}`}__`.toUpperCase();
|
2024-02-05 09:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getAppEnvConfig() {
|
2024-06-11 17:09:39 +08:00
|
|
|
const ENV_NAME = getConfigFileName(import.meta.env);
|
2024-02-05 09:15:37 +08:00
|
|
|
|
2024-06-11 17:09:39 +08:00
|
|
|
const ENV = (import.meta.env.DEV
|
|
|
|
|
? // Get the global configuration (the configuration will be extracted independently when packaging)
|
|
|
|
|
(import.meta.env as unknown as GlobEnvConfig)
|
|
|
|
|
: window[ENV_NAME as any]) as unknown as GlobEnvConfig;
|
2024-02-05 09:15:37 +08:00
|
|
|
|
2024-07-29 14:37:20 +08:00
|
|
|
const { VITE_GLOB_APP_TITLE, VITE_GLOB_API_URL, VITE_GLOB_APP_SHORT_NAME, VITE_GLOB_API_URL_PREFIX, VITE_GLOB_UPLOAD_URL, VITE_GLOB_UPLOAD_PREVIEW, VITE_GLOB_OUT_LINK_URL, VITE_GLOB_REPORT_URL, VITE_GLOB_PRINT_BASE_URL, VITE_TENANT_ENABLED } =
|
|
|
|
|
ENV;
|
2024-02-05 09:15:37 +08:00
|
|
|
|
2024-06-11 17:09:39 +08:00
|
|
|
if (!/^[a-zA-Z\_]*$/.test(VITE_GLOB_APP_SHORT_NAME)) {
|
|
|
|
|
warn(`VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.`);
|
|
|
|
|
}
|
2024-02-05 09:15:37 +08:00
|
|
|
|
2024-06-11 17:09:39 +08:00
|
|
|
return {
|
|
|
|
|
VITE_GLOB_APP_TITLE,
|
|
|
|
|
VITE_GLOB_API_URL,
|
|
|
|
|
VITE_GLOB_APP_SHORT_NAME,
|
|
|
|
|
VITE_GLOB_API_URL_PREFIX,
|
|
|
|
|
VITE_GLOB_UPLOAD_URL,
|
|
|
|
|
VITE_GLOB_UPLOAD_PREVIEW,
|
|
|
|
|
VITE_GLOB_OUT_LINK_URL,
|
|
|
|
|
VITE_GLOB_REPORT_URL,
|
2024-07-29 14:37:20 +08:00
|
|
|
VITE_GLOB_PRINT_BASE_URL,
|
|
|
|
|
VITE_TENANT_ENABLED
|
2024-06-11 17:09:39 +08:00
|
|
|
};
|
2024-02-05 09:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description: Development mode
|
|
|
|
|
*/
|
|
|
|
|
export const devMode = 'development';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description: Production mode
|
|
|
|
|
*/
|
|
|
|
|
export const prodMode = 'production';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description: Get environment variables
|
|
|
|
|
* @returns:
|
|
|
|
|
* @example:
|
|
|
|
|
*/
|
|
|
|
|
export function getEnv(): string {
|
2024-06-11 17:09:39 +08:00
|
|
|
return import.meta.env.MODE;
|
2024-02-05 09:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description: Is it a development mode
|
|
|
|
|
* @returns:
|
|
|
|
|
* @example:
|
|
|
|
|
*/
|
|
|
|
|
export function isDevMode(): boolean {
|
2024-06-11 17:09:39 +08:00
|
|
|
return import.meta.env.DEV;
|
2024-02-05 09:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description: Is it a production mode
|
|
|
|
|
* @returns:
|
|
|
|
|
* @example:
|
|
|
|
|
*/
|
|
|
|
|
export function isProdMode(): boolean {
|
2024-06-11 17:09:39 +08:00
|
|
|
return import.meta.env.PROD;
|
2024-02-05 09:15:37 +08:00
|
|
|
}
|