Skip to content

Commit

Permalink
Generate ApiConfiguration.forRoot
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
Luis Fernando Planella Gonzalez committed Jun 12, 2019
1 parent 8d91f15 commit bcb8b65
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class Globals {

configurationClass: string;
configurationFile: string;
configurationParams: string;
baseServiceClass: string;
baseServiceFile: string;
requestBuilderClass: string;
Expand All @@ -22,6 +23,7 @@ export class Globals {
constructor(options: Options) {
this.configurationClass = options.configuration || 'ApiConfiguration';
this.configurationFile = fileName(this.configurationClass);
this.configurationParams = `${this.configurationClass}Params`;
this.baseServiceClass = options.baseService || 'BaseService';
this.baseServiceFile = fileName(this.baseServiceClass);
this.requestBuilderClass = options.requestBuilder || 'RequestBuilder';
Expand Down
7 changes: 7 additions & 0 deletions templates/configuration.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ import { Injectable } from '@angular/core';
export class {{configurationClass}} {
rootUrl: string = '{{{rootUrl}}}';
}

/**
* Parameters for `{{moduleClass}}.forRoot()`
*/
export interface {{configurationParams}} {
rootUrl?: string;
}
18 changes: 15 additions & 3 deletions templates/module.handlebars
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* tslint:disable */
import { NgModule } from '@angular/core';
import { NgModule, ModuleWithProviders } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { {{configurationClass}} } from './{{configurationFile}}';
import { {{configurationClass}}, {{configurationParams}} } from './{{configurationFile}}';

{{#services}}import { {{typeName}} } from './services/{{fileName}}';
{{/services}}
Expand All @@ -24,4 +24,16 @@ import { {{configurationClass}} } from './{{configurationFile}}';
{{configurationClass}}
],
})
export class {{moduleClass}} { }
export class {{moduleClass}} {
static forRoot(params: {{configurationParams}}): ModuleWithProviders {
return {
ngModule: {{moduleClass}},
providers: [
{
provide: {{configurationClass}},
useValue: params
}
]
}
}
}

0 comments on commit bcb8b65

Please sign in to comment.