Skip to content

Commit eca5a73

Browse files
committed
Fix setup script to NOT overwrite existing .env file
1 parent 4cc5b73 commit eca5a73

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

setup.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
'use strict';
2+
23
var fs = require('fs');
3-
fs.createReadStream('.sample-env')
4-
.pipe(fs.createWriteStream('.env'));
5-
console.log('\n\tCreated .env file in project\'s root directory.\n\tRemember to open that file and put your GitHub API secret in there!\n\t(Only for development environments.)\n');
4+
5+
// Try to create .env file but don't overwrite if it already exists
6+
fs.open('.env', "wx", (err, fd) => {
7+
if (err) {
8+
// For any error other than "file already exists", throw it!
9+
if (err.code !== "EEXIST") {
10+
throw err;
11+
}
12+
// Stop the function here if there were ANY errors
13+
return;
14+
}
15+
16+
// If creating/opening the .env file worked, write to it from .sample-env
17+
fs.createReadStream('.sample-env').pipe(fs.createWriteStream("", {fd: fd}));
18+
19+
console.log('\n\tCreated .env file in project\'s root directory.\n\tRemember to open that file and put your GitHub API secret in there!\n\t(Only for development environments.)\n');
20+
});

0 commit comments

Comments
 (0)