From 04a16fe8fe5629c09ec26d188c39d41774db7d09 Mon Sep 17 00:00:00 2001 From: Jenni Nurmi Date: Wed, 9 Jan 2019 16:03:28 +0200 Subject: [PATCH] Create .env file if it doesn't exist --- package.json | 3 ++- scripts/config.js | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 scripts/config.js diff --git a/package.json b/package.json index ed30a2cd..2ce71039 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/scripts/config.js b/scripts/config.js new file mode 100644 index 00000000..7908ee7d --- /dev/null +++ b/scripts/config.js @@ -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();