Skip to content

Commit

Permalink
fix(app): local/global call of ngd
Browse files Browse the repository at this point in the history
  • Loading branch information
vogloblinsky committed Nov 10, 2016
1 parent 8393fc0 commit b9163a7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/app/engines/ngd.engine.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import * as path from 'path';
import * as Shelljs from 'shelljs';

import { isGlobal } from '../../utilities';

export class NgdEngine {
constructor() {

}
renderGraph(filepath:String, outputpath: String, type: String) {
return new Promise(function(resolve, reject) {
Shelljs.exec(path.resolve(__dirname + '/../node_modules/.bin/ngd') + ' -' + type + ' ' + filepath + ' -d ' + outputpath + ' -s -t svg', {
let ngdPath = (isGlobal()) ? __dirname + '/../node_modules/.bin/ngd' : __dirname + '/../../.bin/ngd';
let finalPath = path.resolve(ngdPath) + ' -' + type + ' ' + filepath + ' -d ' + outputpath + ' -s -t svg'
Shelljs.exec(finalPath, {
silent: true
}, function(code, stdout, stderr) {
if(code === 0) {
Expand Down
19 changes: 19 additions & 0 deletions src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ export function getNewLineCharacter(options: ts.CompilerOptions): string {
return carriageReturnLineFeed;
}

export function isGlobal() {
var isGlobal = false;

if (process.platform === "win32"){
var paths = process.env.Path.split (";");
for (var i=0; i<paths.length; i++){
if (paths[i].indexOf ("npm") !== -1 &&
process.mainModule.filename.indexOf (paths[i]) !== -1){
isGlobal = true;
break;
}
}
}else{
isGlobal = process.env._ !== process.execPath;
}

return isGlobal;
}

export function detectIndent(str, count, indent?): string {
let stripIndent = function(str: string) {
const match = str.match(/^[ \t]*(?=\S)/gm);
Expand Down

0 comments on commit b9163a7

Please sign in to comment.