Initial Chef repository

This commit is contained in:
Greg Karékinian
2015-07-21 19:45:23 +02:00
parent 7e5401fc71
commit ee4079fa85
1151 changed files with 185163 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
if defined?(ChefSpec)
def install_nodejs_npm(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:nodejs_npm, :install, resource_name)
end
def uninstall_nodejs_npm(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:nodejs_npm, :uninstall, resource_name)
end
end

View File

@@ -0,0 +1,33 @@
module NodeJs
module Helper
def npm_dist
if node['nodejs']['npm']['url']
return { 'url' => node['nodejs']['npm']['url'] }
else
require 'open-uri'
require 'json'
result = JSON.parse(URI.parse("https://registry.npmjs.org/npm/#{node['nodejs']['npm']['version']}").read, :max_nesting => false)
ret = { 'url' => result['dist']['tarball'], 'version' => result['_npmVersion'], 'shasum' => result['dist']['shasum'] }
Chef::Log.debug("Npm dist #{ret}")
return ret
end
end
def npm_list(path = nil)
require 'json'
if path
cmd = Mixlib::ShellOut.new('npm list -json', :cwd => path)
else
cmd = Mixlib::ShellOut.new('npm list -global -json')
end
JSON.parse(cmd.run_command.stdout, :max_nesting => false)
end
def npm_package_installed?(package, version = nil, path = nil)
list = npm_list(path)['dependencies']
# Return true if package installed and installed to good version
(!list.nil?) && list.key?(package) && (version ? list[package]['version'] == version : true)
end
end
end