34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
/**
|
||
* Генерирует `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);
|