Skip to content

Instantly share code, notes, and snippets.

@juarezpaf juarezpaf/replace.env.js Secret

Created Mar 8, 2017
Embed
What would you like to do?
#!/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
You can’t perform that action at this time.