Create .env file if it doesn't exist

This commit is contained in:
Jenni Nurmi 2019-01-09 16:03:28 +02:00
parent 19357e6548
commit 04a16fe8fe
2 changed files with 29 additions and 1 deletions

View file

@ -77,7 +77,8 @@
"start": "node server/index.js",
"dev-server": "export NODE_ENV=development PORT=4000 REACT_APP_CANONICAL_ROOT_URL=http://localhost:4000&&yarn run build&&nodemon --watch server server/index.js",
"heroku-postbuild": "yarn run build",
"translate": "node scripts/translations.js"
"translate": "node scripts/translations.js",
"config": "node scripts/config.js"
},
"prettier": {
"singleQuote": true,

27
scripts/config.js Normal file
View file

@ -0,0 +1,27 @@
const fs = require('fs');
const chalk = require('chalk');
const createEnvFile = () => {
fs.copyFileSync('./.env-template', './.env', err => {
if (err) throw err;
});
};
const run = () => {
if (fs.existsSync(`./.env`)) {
console.log(
`.env file already exists. You can edit the variables directly in that file. Remember to restart the application after editing the environment variables!`
);
} else {
console.log(
`You don't have .env file yet. With this tool you can configure required enviroment variables and create .env file automatically.`
);
createEnvFile();
}
};
run();