Files
myeasycms-v2/turbo/generators/utils/index.ts
Giancarlo Buomprisco fc2fda595a Snyk report fixes + offcanvas sidebar fix (#263)
Refactor:
- Improved consistency and robustness by standardizing file encoding arguments from 'utf-8' to 'utf8' across various file read/write operations.
- Simplified status mapping logic in billing components and services by replacing switch statements with direct mapping objects for clearer and more maintainable code.
- Enhanced type conversion and error handling in billing and internationalization components for improved reliability.
- Updated sorting logic in team member tables for more predictable member ordering.
- Improved error logging with sanitized output to prevent formatting issues.
- Adjusted environment variable whitelisting to use a more flexible matching pattern.
- Fix variables for sidebar style handling

Style:
- Refined spacing and layout in account selector and sidebar header components for better visual consistency.
2025-06-01 20:10:39 +08:00

41 lines
877 B
TypeScript

import { readFileSync } from 'node:fs';
export namespace generator {
export function loadAllEnvironmentVariables(basePath: string) {
const sharedEnv = loadEnvironmentVariables(basePath + '/.env');
const productionEnv = loadEnvironmentVariables(
basePath + '/.env.production',
);
return {
...sharedEnv,
...productionEnv,
};
}
export function loadEnvironmentVariables(filePath: string) {
const file = readFileSync(filePath, 'utf8');
const vars = file.split('\n').filter((line) => line.trim() !== '');
const env: Record<string, string> = {};
for (const line of vars) {
const isComment = line.startsWith('#');
if (isComment) {
continue;
}
const [key, value] = line.split('=');
if (!key) {
continue;
}
env[key] = value ?? '';
}
return env;
}
}