Class: BowerVendor::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/bower_vendor/install_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#utilsObject

Returns the value of attribute utils.



4
5
6
# File 'lib/generators/bower_vendor/install_generator.rb', line 4

def utils
  @utils
end

Instance Method Details

#bower_installObject



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
# File 'lib/generators/bower_vendor/install_generator.rb', line 12

def bower_install
  if !options.skip_clean?
    generate options.force_clean? ? 'bower_vendor:clean --force' : 'bower_vendor:clean'
    generate 'bower_vendor:clean --cached'
  end

  action = options.update? ? 'update' : 'install'
  action << ' --production' if !options.include_dev_dependencies?
  say_status :run, "bower #{action}"
  `bower #{action}`

  @utils = BowerVendor::Utils.new

  utils.merged_paths.each do |package, paths|
    append_file '.gitignore', "\n# Vendored bower package '#{package}'\n" if !options.skip_git_ignore?
    case paths
    when Hash
      paths.each do |source, dest|
        vendor_asset(package, utils.prefixed_source(package, source), dest)
      end
    when Array
      paths.each do |source|
        vendor_asset(package, utils.prefixed_source(package, source))
      end
    when String
      vendor_asset(package, utils.prefixed_source(package, paths))
    else
      raise Thor::Error, set_color("Paths must be either Hash, Array or String, received: #{paths.class}", :red, :bold)
    end
  end
end