-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-env-files.js
More file actions
29 lines (25 loc) · 794 Bytes
/
sync-env-files.js
File metadata and controls
29 lines (25 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fs = require('fs');
const envFilePath = '.env';
const exampleFilePath = '.env.example';
// Function to sync env file to env.example
const syncEnvFiles = () => {
fs.readFile(envFilePath, 'utf8', (readError, data) => {
if (readError) {
console.error(`Error reading ${envFilePath}:`, readError);
return;
}
// Remove values from the env file content
const envExampleContent = data
.split('\n')
.map((line) => line.replace(/=.*/, '='))
.join('\n');
fs.writeFile(exampleFilePath, envExampleContent, 'utf8', (writeError) => {
if (writeError) {
console.error(`Error writing ${exampleFilePath}:`, writeError);
} else {
console.log(`${exampleFilePath} has been updated.`);
}
});
});
};
syncEnvFiles();