import * as path from 'path'; export class Service { constructor( private serviceDir: string, private modelsDir: string, private _import: string, private serviceName: string, private url: string) {} public Generate() { const relative = path.posix.relative(this.serviceDir, this.modelsDir); const coredir = ('./' + relative + '/core').replace(/\\/ig, "/", ); const content = `import {Injectable} from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { OdataMetadata } from '${this._import}'; import * as $ from 'jquery'; import { IOdataSets } from '${coredir}'; import { Subject } from "rxjs/Subject"; @Injectable() export class ${this.serviceName || 'OdataService'} { private metadata: OdataMetadata; private url = '${this.url}'; constructor(private $http: Http) { this.metadata = new OdataMetadata(this.url, this.$http); } public getContext() { const subject = new Subject(); this.metadata.getContext().then(context => subject.next(context)); return subject.asObservable(); } } `; return content; } }