Skip to content

Commit b9163a7

Browse files
committed
fix(app): local/global call of ngd
1 parent 8393fc0 commit b9163a7

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/app/engines/ngd.engine.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import * as path from 'path';
22
import * as Shelljs from 'shelljs';
33

4+
import { isGlobal } from '../../utilities';
5+
46
export class NgdEngine {
57
constructor() {
68

79
}
810
renderGraph(filepath:String, outputpath: String, type: String) {
911
return new Promise(function(resolve, reject) {
10-
Shelljs.exec(path.resolve(__dirname + '/../node_modules/.bin/ngd') + ' -' + type + ' ' + filepath + ' -d ' + outputpath + ' -s -t svg', {
12+
let ngdPath = (isGlobal()) ? __dirname + '/../node_modules/.bin/ngd' : __dirname + '/../../.bin/ngd';
13+
let finalPath = path.resolve(ngdPath) + ' -' + type + ' ' + filepath + ' -d ' + outputpath + ' -s -t svg'
14+
Shelljs.exec(finalPath, {
1115
silent: true
1216
}, function(code, stdout, stderr) {
1317
if(code === 0) {

src/utilities.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@ export function getNewLineCharacter(options: ts.CompilerOptions): string {
2323
return carriageReturnLineFeed;
2424
}
2525

26+
export function isGlobal() {
27+
var isGlobal = false;
28+
29+
if (process.platform === "win32"){
30+
var paths = process.env.Path.split (";");
31+
for (var i=0; i<paths.length; i++){
32+
if (paths[i].indexOf ("npm") !== -1 &&
33+
process.mainModule.filename.indexOf (paths[i]) !== -1){
34+
isGlobal = true;
35+
break;
36+
}
37+
}
38+
}else{
39+
isGlobal = process.env._ !== process.execPath;
40+
}
41+
42+
return isGlobal;
43+
}
44+
2645
export function detectIndent(str, count, indent?): string {
2746
let stripIndent = function(str: string) {
2847
const match = str.match(/^[ \t]*(?=\S)/gm);

0 commit comments

Comments
 (0)