-
-
Save juarezpaf/7a9007dfcef25ec24f7de900df8fe04e 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
#!/usr/bin/env node | |
var path = require('path'); | |
var process = require('process'); | |
var fs = require('fs'); | |
var npmConfigJson = JSON.parse(process.env.npm_config_argv).original; | |
var indexEnv = npmConfigJson.indexOf('--env'); | |
var env = ''; | |
if (indexEnv !== -1) { | |
env = npmConfigJson[indexEnv+1]; | |
} else if (npmConfigJson.indexOf('--sandbox3') !== -1) { | |
env = 'sandbox3'; | |
} else if (npmConfigJson.indexOf('--sandbox4') !== -1) { | |
env = 'sandbox4'; | |
} else if (npmConfigJson.indexOf('--staging') !== -1) { | |
env = 'staging'; | |
} else if (npmConfigJson.indexOf('--production') !== -1) { | |
env = 'production'; | |
} else { | |
// no arguments, use the actual config.ts | |
return | |
} | |
var envVars; | |
try { | |
envVars = require(path.join('../', 'env', env + '.json')); | |
} catch(e) { | |
envVars = {}; | |
} | |
const ENV = Object.assign(envVars, { | |
environment: JSON.stringify(env) | |
}) | |
var content = fs.readFileSync('./src/providers/config/config.ts.sample'); | |
var contentReplace = content.toString() | |
.replace(/ENV.api_url/, ENV.api_url) | |
.replace(/ENV.login.client_id/, ENV.client_id_login) | |
.replace(/ENV.login.client_secret/, ENV.client_secret_login) | |
.replace(/ENV.google_maps_key/, ENV.google_maps_key); | |
var wstream = fs.createWriteStream('./src/providers/config/config.ts'); | |
wstream.write(contentReplace); | |
wstream.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment