Files
sparkguardian-frontend/scripts/sync-env.cjs
Микаэл Оганесян 68c3029835 Main logic
2026-04-08 02:10:17 +03:00

34 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Генерирует `src/environments/environment.ts` из переменных окружения (.env).
* Значения по умолчанию совпадают с .env.example.
*/
const fs = require('fs');
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '..', '.env') });
const defaults = {
SG_API_FALLBACK_ORIGIN: 'https://sparkguardian.ru',
SG_API_BASE_PATH: '/api/v1',
};
function val(key) {
const v = process.env[key];
if (v !== undefined && v !== '') {
return v;
}
return defaults[key];
}
const content = `// Сгенерировано npm run env:sync — правьте .env и снова запустите sync
export const environment = {
production: false,
apiFallbackOrigin: ${JSON.stringify(val('SG_API_FALLBACK_ORIGIN'))},
apiBasePath: ${JSON.stringify(val('SG_API_BASE_PATH'))},
} as const;
`;
const outPath = path.join(__dirname, '..', 'src', 'environments', 'environment.ts');
fs.writeFileSync(outPath, content, 'utf8');
console.log('env:sync →', outPath);