Created
July 14, 2022 06:21
-
-
Save ShwetaRPawar/f0293ba3d7210da794de08ea074203b6 to your computer and use it in GitHub Desktop.
This file contains 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
const gulp = require('gulp'), | |
jeditor = require('gulp-json-editor'); | |
function setLocal(cb) { | |
setVersion('local'); | |
cb(); | |
} | |
function setStaging(cb) { | |
setVersion('staging'); | |
cb(); | |
} | |
function setProduction(cb) { | |
setVersion('production'); | |
cb(); | |
} | |
function setVersion(version_name) { | |
var jsonData = { | |
host: <YOUR_DEFAULT_HOST_NAME> // eg. 'google.com', | |
db_host: <YOUR_DEFAULT_DB_HOST> // eg. 'localhost', | |
port: <YOUR_DEFAULT_PORT> // eg. '27017', | |
db_name: <YOUR_DEFAULT_DB_NAME> // eg. 'student_db', | |
db_user: <YOUR_DEFAULT_DB_USER> // eg. 'admin', | |
db_password: <YOUR_DEFAULT_DB_PASSWORD> //eg. '1234', | |
}; | |
switch(version_name) { | |
case 'production': | |
console.log('VERSION =', version_name); | |
jsonData.host = <PRODUCTION_HOST>; | |
jsonData.db_host = <PRODUCTION_DB_HOST>; | |
jsonData.port = <PRODUCTION_PORT>; | |
jsonData.db_name = <PRODUCTION_DB_NAME>; | |
jsonData.db_user = <PRODUCTION_DB_USER>; | |
jsonData.db_password = <PRODUCTION_DB_PASSWORD>; | |
break; | |
case 'local': | |
console.log('VERSION =', version_name); | |
jsonData.host = <LOCAL_HOST>; | |
jsonData.db_host = <LOCAL_DB_HOST>; | |
jsonData.port = <LOCAL_PORT>; | |
jsonData.db_name = <LOCAL_DB_NAME>; | |
jsonData.db_user = <LOCAL_DB_USER>; | |
jsonData.db_password = <LOCAL_DB_PASSWORD>; | |
break; | |
case 'staging': | |
console.log('VERSION =', version_name); | |
jsonData.host = <STAGING_HOST>; | |
jsonData.db_host = <STAGING_DB_HOST>; | |
jsonData.port = <STAGING_PORT>; | |
jsonData.db_name = <STAGING_DB_NAME>; | |
jsonData.db_user = <STAGING_DB_USER>; | |
jsonData.db_password = <STAGING_DB_PASSWORD>; | |
break; | |
default: | |
console.log('DEFAULT VERSION =', version_name); | |
jsonData.host = <DEFAULT_HOST>; | |
jsonData.db_host = <DEFAULT_DB_HOST>; | |
jsonData.port = <DEFAULT_PORT>; | |
jsonData.db_name = <DEFAULT_DB_NAME>; | |
jsonData.db_user = <DEFAULT_DB_USER>; | |
jsonData.db_password = <DEFAULT_DB_PASSWORD>; | |
break; | |
} | |
gulp.src('./config/server.json') // path of your config file which will contain all credentials that we will use in actual code | |
.pipe(jeditor(function(json) { | |
json.host = jsonData.host; | |
json.db_host = jsonData.db_host; | |
json.port = jsonData.port; | |
json.db_name = jsonData.db_name; | |
json.db_user = jsonData.db_user; | |
json.db_password = jsonData.db_password; | |
return json; | |
})) | |
.pipe(gulp.dest('./config')); // Your config folder path | |
} | |
exports.local = setLocal; | |
exports.staging = setStaging; | |
exports.production = setProduction; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment