Created
March 14, 2018 05:51
-
-
Save nhancv/ac98210e028ca6447aea6f3f17976b8e to your computer and use it in GitHub Desktop.
Generate .env by .env.${NODE_ENV}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| const fs = require('fs') | |
| const path = require('path') | |
| var currDir = path.dirname(fs.realpathSync(__filename)) | |
| var env = process.env.NODE_ENV | |
| const fileExists = filePath => { | |
| try { | |
| return fs.statSync(filePath).isFile() | |
| } catch (err) { | |
| return false | |
| } | |
| } | |
| if (env) { | |
| var currEnv = path.join(currDir, `.env`) | |
| var envPath = path.join(currDir, `.env.${env}`) | |
| if (fileExists(currEnv)) { | |
| fs.unlinkSync(currEnv) | |
| } | |
| if (fileExists(envPath)) { | |
| fs.createReadStream(envPath).pipe(fs.createWriteStream('.env')) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment