diff --git a/.kitchen.yml b/.kitchen.yml index 5427531..9189be9 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -71,3 +71,14 @@ suites: nodejs: npm: install_method: source +- name: npm_packages + run_list: recipe[nodejs] + attributes: + nodejs: + npm_packages: + - name: express + - name: socket.io + version: 1.0.4 + - name: express + action: uninstall + diff --git a/recipes/default.rb b/recipes/default.rb index efdb22d..dc0bc55 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -20,3 +20,14 @@ include_recipe 'nodejs::nodejs' include_recipe 'nodejs::npm' + +node['nodejs']['npm_packages'].each do |pkg| + f = nodejs_npm pkg['name'] do + action :nothing + end + pkg.reject { |k, _v| k == 'name' || k == 'action' }.each do |key, value| + f.send(key, value) + end + action = pkg.key?('action') ? pkg['action'] : :install + f.action(action) +end if node['nodejs'].key?('npm_packages') diff --git a/recipes/packages.rb b/recipes/packages.rb deleted file mode 100644 index c29baf0..0000000 --- a/recipes/packages.rb +++ /dev/null @@ -1,16 +0,0 @@ -# -# Author:: Paul Bonaud (paul@bonaud.fr) -# Cookbook Name:: nodejs -# Recipe:: packages -# -# This recipe gives you the ability to install node packages -# via chef configuration -# - -if node['nodejs'].has_key?('node_packages') - node['nodejs']['node_packages'].each do |node_pkg| - nodejs_npm node_pkg['name'] do - version node_pkg['version'] if node_pkg.has_key?('version') - end if node_pkg.has_key?('name') - end -end