0.0.24 • Published 5 years ago

@flatxph/environment v0.0.24

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Environment builder for Angular build facade

This builder converts the dotenv to its equivalent environment.ts that can be used by the angular cli

npm version npm

This builder followed and improved on Angular CLI 6 under the hood — builders demystified. This also follows Step by step: Building and publishing an NPM Typescript package.

Usage

  1. In the root of your Angular application:
    npm i -D @flatxph/environment
    npm i -D dotenv
    npm i -D @types/dotenv
  2. In your angular.json add the following to architect section of the relevant project:
    "environment": {
      "builder": "@flatxph/environment:file",
      "options": {}
    },
  3. Create a file name environment.build.ts on src/environments. This file will have access to the NodeJS environment. This is a sample environment.build.ts

    import { Environment } from './model';
    
    export const environment: Environment = {
        production: !!process.env.PRODUCTION || false,
        maps: {
            apiKey: process.env.MAPS_API_KEY,
            libraries: process.env.MAPS_LIBRARIES ? process.env.MAPS_LIBRARIES.split(',') : [],
        },
        title: process.env.TITLE || '',
        description: process.env.DESCRIPTION || '',
        fbAppId: parseInt(process.env.FB_APP_ID, 10) || 0,
        url: process.env.URL || '',
        twitter: process.env.TWITTER || '',
        image: process.env.IMAGE || '',
        imageWidth: parseInt(process.env.IMAGE_WIDTH, 10) || 0,
        imageHeight: parseInt(process.env.IMAGE_HEIGHT, 10) || 0,
        appId: process.env.APP_ID || '',
    };
  4. Run: ng run [relevant-project]:environment Where relevant-project is the project to which you've added the target

  5. Add the generated files to .gitignore for cleaner repository
    ...
    /src/environments/*.js
    /src/environments/*.js.map
  6. Create a run script on package.json to automate the process
    "scripts" {
    ...
    "environment": "ng run [relevant-project]:environment",
    "prestart": "npm environment",
    ...
    }

Options

  • src - path to the file with build environment, Defaults to src/environments/environment.build. The .ts part of the file should be omitted.
  • dotenvConfigOptions - This is a DotenvConfigOption based on package @types/dotenv. Defaults to {}
  • model - The model used as environment check. Typically named Environment. Defaults to null
  • modelPath - This is the path of the model for the environment. Typically app/environments/model. Defaults to null
  • template - This is the template file to use to render the environment. Defaults to null
  • output - This is the output file. Default to src/environments/environment.ts

Development

If you want to create your own builder like this, to upload to npm, run yarn public to publish.

Sample Projects are provided in the examples directory.

  • Minimal - this is a minimal setup of an angular project with the builder installed.
0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago