Giter VIP home page Giter VIP logo

demo-env2file's Introduction

Using env2file Sample App

This application uses env2file to inject data from the environment into a production build that will be used to create production release APK and IPA files.

The Environment Files

The development environment just has data:

export const environment = {
  production: false,
  tagLine: 'Secrets? We have no secrets here',
  getSmart: {
    main: 'this is development',
    companion: 'everyone knows everything'
  }
};

The production environment file pulls data out of the generated secrets.ts file:

import { secrets } from './secrets';

export const environment = {
  production: true,
  tagLine: secrets.secret1,
  getSmart: {
    main: secrets.secret2,
    companion: secrets.secret3
  }
};

The Build Scripts

The production build (npm run build) has been changed to generate the secrets.ts file based on environment variables:

  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "env2file -k DEMO -f src/environments/secrets.ts -o secrets; ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

The Environment

Set the following variables in your environment.

export DEMO_SECRET1='Secret Agent, man...'
export DEMO_SECRET2='Maxwell Smart'
export DEMO_SECRET3='Agent 99'

If you are using Ionic's Appflow automations, you should be able to set custom environment variables there as well (not tested).

Running

If you do npm start you will see whatever is in environment.ts on the home page.

If you do npm run build and then serve it, you will see the secrets. To serve it, do the following:

  1. npm run build
  2. cd www
  3. http-server -c-1 .

This assumes you have http-server installed globally on your machine. If you don't, you should. It is a cool and useful tool... ๐Ÿฅณ

Misc

There were a few setup files that needed to be changed so that things built properly and so the secrets.ts file would never get checked in accidentally. See the commits in the GitHub repo for details.

demo-env2file's People

Contributors

kensodemann avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.