Code coverage report for lib/helper.js

Statements: 85.71% (12 / 14)      Branches: 50% (2 / 4)      Functions: 100% (1 / 1)      Lines: 85.71% (12 / 14)      Ignored: none     

All files » lib/ » helper.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61          1 1             1 1                     1                 1     5                   1 1   1 1 1                
/**
 * @fileoverview Helpers made available via require('helper') once package is
 * installed.
 */
 
var fs = require('fs');
var path = require('path');
 
 
/**
 * Where the phantom binary can be found.
 * @type {string}
 */
try {
  exports.path = path.resolve(__dirname, require('./location').location);
} catch(e) {
  // Must be running inside install script.
  exports.path = null;
}
 
 
/**
 * The version of Galen installed by this package.
 * @type {number}
 */
exports.version = require('../package.json')._galenVersion;
 
 
/**
 * Returns a clean path that helps avoid `which` finding bin files installed
 * by NPM for this repo.
 * @param {string} path
 * @return {string}
 */
exports.cleanPath = function (path) {
  'use strict';
 
  return path
    .replace(/:[^:]*node_modules[^:]*/g, '')
    .replace(/(^|:)\.\/bin(\:|$)/g, ':')
    .replace(/^:+/, '')
    .replace(/:+$/, '');
};
 
 
// Make sure the binary is executable.  For some reason doing this inside
// install does not work correctly, likely due to some NPM step.
Eif (exports.path) {
  try {
    // avoid touching the binary if it's already got the correct permissions
    var st = fs.statSync(exports.path);
    var mode = st.mode | 0555; // jshint ignore:line
    Iif (mode !== st.mode) {
      fs.chmodSync(exports.path, mode);
    }
  } catch (e) {
    // Just ignore error if we don't have permission.
    // We did our best. Likely because phantomjs was already installed.
  }
}