Files
teams-alias/scripts/generate-env.js
2026-01-05 12:22:01 -04:00

38 lines
1.1 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const envPath = path.join(__dirname, '..', '.env');
const outputPath = path.join(__dirname, '..', 'env.js');
try {
let envContent = '';
if (fs.existsSync(envPath)) {
envContent = fs.readFileSync(envPath, 'utf8');
}
const envVars = {};
envContent.split('\n').forEach(line => {
const match = line.match(/^\s*([\w_]+)\s*=\s*(.*)?\s*$/);
if (match) {
const key = match[1];
let value = match[2] || '';
// Remove quotes if present
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'" ) && value.endsWith("'" ))) {
value = value.slice(1, -1);
}
envVars[key] = value;
}
});
const fileContent = `// Auto-generated by scripts/generate-env.js
const ENV_SECRETS = ${JSON.stringify(envVars, null, 4)};
`;
fs.writeFileSync(outputPath, fileContent);
console.log('Successfully generated env.js');
} catch (err) {
console.error('Error generating env.js:', err);
process.exit(1);
}