Sha256: d7cda3e9775e4d3c8f6f5d56a93157024f23ceab1a5a5cca0dd7cba03ab98e7d

Contents?: true

Size: 804 Bytes

Versions: 1

Compression:

Stored size: 804 Bytes

Contents

require 'multi_json'

module Bower
  class Environment
    attr_accessor :directory, :json

    DEFAULT_DIRECTORY = 'bower_components'
    DEFAULT_JSON      = 'bower.json'

    def self.setup(bowerrc=nil)
      if bowerrc && File.exists?(bowerrc)
        conf = MultiJson.load(File.open(bowerrc))
        Environment.new(conf)
      else
        Environment.new
      end
    end

    def initialize(config={})
      @directory = config['directory'] || DEFAULT_DIRECTORY
      @json      = config['json'] || DEFAULT_JSON
    end

    def install
      run('bower install')
    end

    def update
      run('bower update')
    end

    private

    def run(cmd)
      return unless Dir.exists?(directory)

      Dir.chdir(directory) do
        `#{cmd}` if File.exists?(json)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bower-0.0.2 lib/bower/environment.rb