Skip to content

Instantly share code, notes, and snippets.

@marcosborges
Last active January 21, 2019 16:38
Show Gist options
  • Save marcosborges/33c1b5db066e09cd450ca345372c601f to your computer and use it in GitHub Desktop.
Save marcosborges/33c1b5db066e09cd450ca345372c601f to your computer and use it in GitHub Desktop.
URL_API=http://www.minhaapi.com.br/meu-endpoint
TOKEN_NAME=access_token
const fs = require('fs');
const dotenv = require('dotenv');
dotenv.config();
const targetPath = `./src/environments/environment.ts`;
const envConfigFile = `
export const environment = {
url_api: "${process.env.URL_API}",
token_name: "${process.env.TOKEN_NAME}"
};
`
fs.writeFile(targetPath, envConfigFile, function (err) {
if (err) {
console.log(err);
}
console.log(`Output generated at ${targetPath}`);
});
//ts-node set-env.ts
{
"scripts": {
"ng": "ng",
"config": "ts-node ./scripts/angular_set_environtment.ts",
"start": "npm run config && ng serve",
"build": "npm run config && ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment