Add npm support
This commit is contained in:
parent
fa8c59a16c
commit
ee6174d33c
5 changed files with 75 additions and 0 deletions
16
README.md
16
README.md
|
@ -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
|
||||
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
|
||||
|
||||
|
|
|
@ -40,3 +40,4 @@ require_relative "bucket/pacman"
|
|||
require_relative "bucket/yum"
|
||||
require_relative "bucket/rvm"
|
||||
require_relative "bucket/apt_cacher"
|
||||
require_relative "bucket/npm"
|
||||
|
|
33
lib/vagrant-cachier/bucket/npm.rb
Normal file
33
lib/vagrant-cachier/bucket/npm.rb
Normal 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
|
20
lib/vagrant-cachier/cap/linux/npm_cache_dir.rb
Normal file
20
lib/vagrant-cachier/cap/linux/npm_cache_dir.rb
Normal 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
|
|
@ -31,6 +31,11 @@ module VagrantPlugins
|
|||
Cap::Linux::ChefFileCachePath
|
||||
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
|
||||
require_relative 'cap/debian/apt_cache_dir'
|
||||
Cap::Debian::AptCacheDir
|
||||
|
|
Loading…
Reference in a new issue