@nglx/cfg
A simple configuration library for Angular applications
Overview
@nglx/cfg attempts to streamline the app configuration while keeping it DRY.
How to install
npm install @nglx/cfg |OR| yarn add @nglx/cfg
How to use
import { AppCfg, TargetPlatform, HttpMethod } from '@nglx/cfg';
export const environment: AppCfg = {
version: string;
appName: 'Angular Configuration Module',
target: TargetPlatform.web,
production: true
};
import { CfgModule } from '@nglx/cfg';
import { environment } from '../environments/environment';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, CfgModule.forRoot(environment)],
bootstrap: [AppComponent]
})
export class AppModule {}
import { Component } from '@angular/core';
import { CfgService } from '@nglx/cfg';
@Component({
selector: 'app-root'
})
export class AppComponent {
title = '@nglx/cfg';
constructor(public cfg: CfgService) {
this.title = this.cfg.options.appName;
}
}
Advanced usage:
Remote configuration - What if you need remote config before you started the Angular app?
@nglx/cfg
can also be used to fetch remote configuration prior to start of an Angular app.
import { AppCfg, TargetPlatform, HttpMethod } from '@nglx/cfg';
export const environment: AppCfg = {
version: '1.0.0',
appName: 'Angular Configuration Module',
target: TargetPlatform.web,
production: true,
rmtCfg: {
endpoint: '/api/config',
method: HttpMethod.get,
timeout: 3,
headers: { 'Content-Type': 'application/json' }
body: {
}
}
};
import { CfgModule } from '@nglx/cfg';
import { environment } from '../environments/environment';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, CfgModule.forRoot(environment)],
bootstrap: [AppComponent]
})
export class AppModule {}
import { Component } from '@angular/core';
import { CfgService } from '@nglx/cfg';
import { merge } from 'lodash';
@Component({
selector: 'app-root'
})
export class AppComponent {
title = '@nglx/cfg';
options = {};
constructor(public cfg: CfgService) {
this.options = merge({ name: 'AppComponent' }, this.cfg.options};
const remoteCfgData = this.options.rmtData;
}
}
Running the tests
To run the tests against the current environment:
npm run ci:all |OR| yarn ci:all
License
Released under a (MIT) license.
Version
X.Y.Z Version
`MAJOR` version -- making incompatible API changes
`MINOR` version -- adding functionality in a backwards-compatible manner
`PATCH` version -- making backwards-compatible bug fixes
Surge
Credits
Angular // Nrwl // Lodash // NPM // Yarn