Module: CoffeeLintHelper

Extended by:
Rake::DSL
Defined in:
lib/embarista/tasks/coffeelint.rb

Class Method Summary collapse

Class Method Details

.coffeelint(cmd_args) ⇒ Object



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
# File 'lib/embarista/tasks/coffeelint.rb', line 4

def self.coffeelint(cmd_args)
  tool = 'coffeelint'
  cmd_args = cmd_args || ''

  node = which('node')
  if node.nil?
    puts "Could not find node in your path."
    return
  end

  npm = which('npm')
  if npm.nil?
    puts "Could not find npm in your path."
    return
  end

  coffeelint = which('coffeelint')

  if coffeelint
    sh "coffeelint #{cmd_args}"

  else
    if !File.directory?("node_modules/#{tool}")
      sh "\"#{npm}\" install #{tool}"
    end

    sh "\"#{node}\" node_modules/#{tool}/bin/#{tool} #{cmd_args}"
  end
end

.which(cmd) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/embarista/tasks/coffeelint.rb', line 34

def self.which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each { |ext|
      sep = File::ALT_SEPARATOR || File::SEPARATOR
      exe = "#{path}#{sep}#{cmd}#{ext}"
      return exe if File.executable? exe
    }
  end
  return nil
end