Main logic

This commit is contained in:
Микаэл Оганесян
2026-04-08 02:10:17 +03:00
parent 55742c1bbc
commit 68c3029835
58 changed files with 4807 additions and 418 deletions

33
scripts/sync-env.cjs Normal file
View File

@@ -0,0 +1,33 @@
/**
* Генерирует `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);