class GulpRunner::CommandUtils

Public Class Methods

find_command(cmd, paths = []) click to toggle source

stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby

# File lib/gulp-runner/command_utils.rb, line 12
def self.find_command(cmd, paths = [])
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  paths += ENV['PATH'].split(File::PATH_SEPARATOR)
  paths.each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if (File.executable?(exe) && File.file?(exe))
    end
  end
  nil
end
get_command(command_name) click to toggle source
# File lib/gulp-runner/command_utils.rb, line 3
def self.get_command(command_name)
  entries = Dir.entries(GulpRunner.root_path)
  npm_path = File.join(GulpRunner.root_path, 'node_modules', '.bin')
  command = CommandUtils.find_command(command_name, [npm_path])
  
  return command if !command.nil?
  raise Exception
end