UNPKG

1.28 kBPlain TextView Raw
1import DependenciesEngine from './dependencies.engine';
2import FileEngine from './file.engine';
3
4const ngdT = require('@compodoc/ngd-transformer');
5
6export class NgdEngine {
7 public engine;
8
9 private static instance: NgdEngine;
10 private constructor() {}
11 public static getInstance() {
12 if (!NgdEngine.instance) {
13 NgdEngine.instance = new NgdEngine();
14 }
15 return NgdEngine.instance;
16 }
17
18 public init(outputpath: string) {
19 this.engine = new ngdT.DotEngine({
20 output: outputpath,
21 displayLegend: true,
22 outputFormats: 'svg',
23 silent: true
24 });
25 }
26
27 public renderGraph(filepath: string, outputpath: string, type: string, name?: string) {
28 this.engine.updateOutput(outputpath);
29
30 if (type === 'f') {
31 return this.engine.generateGraph([DependenciesEngine.getRawModule(name)]);
32 } else {
33 return this.engine.generateGraph(DependenciesEngine.rawModulesForOverview);
34 }
35 }
36
37 public readGraph(filepath: string, name: string): Promise<string> {
38 return FileEngine.get(filepath).catch(err =>
39 Promise.reject('Error during graph read ' + name)
40 );
41 }
42}
43
44export default NgdEngine.getInstance();