Files
Микаэл Оганесян abcd49e117
Some checks failed
CI / checks (push) Failing after 4m56s
Add landing
2026-04-12 06:17:02 +03:00

46 lines
1.4 KiB
JavaScript
Raw Permalink 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',
SG_INTERACTIVE_PREROLL_MS: '4000',
SG_DEFAULT_PAGE_LIMIT: '10',
};
function val(key) {
const v = process.env[key];
if (v !== undefined && v !== '') {
return v;
}
return defaults[key];
}
function intVal(key) {
const parsed = Number.parseInt(val(key), 10);
if (Number.isFinite(parsed)) {
return parsed;
}
return Number.parseInt(defaults[key], 10);
}
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'))},
interactivePrerollMs: ${JSON.stringify(intVal('SG_INTERACTIVE_PREROLL_MS'))},
defaultPageLimit: ${JSON.stringify(intVal('SG_DEFAULT_PAGE_LIMIT'))},
} as const;
`;
const outPath = path.join(__dirname, '..', 'src', 'environments', 'environment.ts');
fs.writeFileSync(outPath, content, 'utf8');
console.log('env:sync →', outPath);