Merge branch 'npm-cache' of github.com:laggyluke/vagrant-cachier

Conflicts:
	lib/vagrant-cachier/bucket.rb
This commit is contained in:
Fabio Rehm 2013-10-23 21:17:32 -02:00
commit 42cd490313
5 changed files with 75 additions and 0 deletions

View file

@ -208,6 +208,22 @@ folder under the result of running `rvm info` as the default SSH user (usualy
it is already installed before enabling the bucket, otherwise you won't benefit it is already installed before enabling the bucket, otherwise you won't benefit
from this plugin. from this plugin.
#### npm
```ruby
Vagrant.configure("2") do |config|
config.vm.box = 'some-box-with-nodejs-installed'
config.cache.enable :npm
end
```
Compatible with probably any type of linux guest distro, will hook into npm's
cache directory under the result of running `npm config get cache` as
the default SSH user (usually `vagrant`) on your guest.
If you use
[nvm](https://github.com/creationix/nvm) / [n](https://github.com/visionmedia/n)
on the guest machine, make sure it is already installed before enabling
the bucket, otherwise you won't benefit from this plugin.
##### APT-CACHER ##### APT-CACHER

View file

@ -41,3 +41,4 @@ require_relative "bucket/yum"
require_relative "bucket/rvm" require_relative "bucket/rvm"
require_relative "bucket/apt_cacher" require_relative "bucket/apt_cacher"
require_relative "bucket/composer" require_relative "bucket/composer"
require_relative "bucket/npm"

View file

@ -0,0 +1,33 @@
module VagrantPlugins
module Cachier
class Bucket
class Npm < Bucket
def self.capability
:npm_cache_dir
end
def install
machine = @env[:machine]
guest = machine.guest
if guest.capability?(:npm_cache_dir)
guest_path = guest.capability(:npm_cache_dir)
@env[:cache_dirs] << guest_path
machine.communicate.tap do |comm|
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
unless comm.test("test -L #{guest_path}")
comm.execute("rm -rf #{guest_path}")
comm.execute("mkdir -p `dirname #{guest_path}`")
comm.execute("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
end
end
else
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'npm')
end
end
end
end
end
end

View file

@ -0,0 +1,20 @@
module VagrantPlugins
module Cachier
module Cap
module Linux
module NpmCacheDir
def self.npm_cache_dir(machine)
npm_cache_dir = nil
machine.communicate.tap do |comm|
return unless comm.test('which npm')
comm.execute 'npm config get cache' do |buffer, output|
npm_cache_dir = output.chomp if buffer == :stdout
end
end
return npm_cache_dir
end
end
end
end
end
end

View file

@ -36,6 +36,11 @@ module VagrantPlugins
Cap::Linux::ChefFileCachePath Cap::Linux::ChefFileCachePath
end end
guest_capability 'linux', 'npm_cache_dir' do
require_relative 'cap/linux/npm_cache_dir'
Cap::Linux::NpmCacheDir
end
guest_capability 'debian', 'apt_cache_dir' do guest_capability 'debian', 'apt_cache_dir' do
require_relative 'cap/debian/apt_cache_dir' require_relative 'cap/debian/apt_cache_dir'
Cap::Debian::AptCacheDir Cap::Debian::AptCacheDir