Skip to content

Commit

Permalink
feat(node-module): Expose galen path as promise via module
Browse files Browse the repository at this point in the history
see #47
  • Loading branch information
hypery2k committed Oct 20, 2017
1 parent 694998d commit 6d143ab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions core/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var helper = require('./lib/helper');

module.exports = {
galenPath: helper.galenPath
};
29 changes: 26 additions & 3 deletions core/lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* installed.
*/

var fs = require('fs');
var path = require('path');
var fs = require('fs'),
path = require('path');


/**
Expand All @@ -13,7 +13,7 @@ var path = require('path');
*/
try {
exports.path = path.resolve(__dirname, require('./location').location);
} catch(e) {
} catch (e) {
// Must be running inside install script.
exports.path = null;
}
Expand Down Expand Up @@ -58,3 +58,26 @@ if (exports.path) {
// We did our best. Likely because phantomjs was already installed.
}
}

exports.galenPath = function () {
return new Promise(function (resolve, reject) {

galenPath = path.resolve(__dirname + '/../node_modules/galenframework/bin/galen' + (process.platform === 'win32' ? '.cmd' : ''));
fs.stat(galenPath, function (err) {
// resolve for NPM3+
if (err) {
galenPath = path.resolve(__dirname + '/../../galenframework/bin/galen' + (process.platform === 'win32' ? '.cmd' : ''));
fs.stat(galenPath, function (err) {
// resolve for NPM3+
if (err) {
reject('Cannot find Galenframework at ' + galenPath);
} else {
resolve(galenPath);
}
});
} else {
resolve(galenPath);
}
});
});
}
1 change: 1 addition & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"bin": {
"galen": "bin/galen"
},
"main":"index",
"dependencies": {
"adm-zip": "0.4.7",
"fs-extra": "0.23.0",
Expand Down

0 comments on commit 6d143ab

Please sign in to comment.