使用外部数据库
This commit is contained in:
37
scripts/generate-env.js
Normal file
37
scripts/generate-env.js
Normal file
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user