15 Commits

Autor SHA1 Mensagem Data
Guilhem Lettron ea88bfaa67 Use homebrew by default 2014-04-10 15:42:25 +02:00
Guilhem Lettron 9a0ef56a79 Refactor some mac_pkg parts 2014-04-10 15:32:09 +02:00
Angel Abad 8b0e3629ca Install nodejs pkg from official repository in MacOs X 2014-04-10 15:18:17 +02:00
Angel Abad a1c94e6dae Add mac_os_x platform to metadata 2014-04-10 15:15:44 +02:00
Angel Abad 50839ca168 Add recipe description in metadata 2014-04-10 15:15:03 +02:00
Barthélemy Vessemont 5d41523585 Merge pull request #7 from redguide/npm-lwrp
Add tests and fix
2014-04-10 15:09:59 +02:00
Guilhem Lettron 156c804dd4 Fix failing tests 2014-04-10 15:07:22 +02:00
Guilhem Lettron ce43bb2471 Add integration testing 2014-04-10 15:07:12 +02:00
Guilhem Lettron 162c90bfcc Merge pull request #4 from redguide/npm-lwrp
npm LWRP
2014-04-10 14:41:02 +02:00
Guilhem Lettron 3ba898244a Factorize "installed?" 2014-04-10 14:39:41 +02:00
Guilhem Lettron 68ad7e4f40 add user and group 2014-04-10 14:38:07 +02:00
Guilhem Lettron 78f6b4c626 Fix resources + rubocop 2014-04-10 14:32:44 +02:00
Guilhem Lettron 844d795a35 First work cleaner npm 2014-04-10 12:25:32 +02:00
Barthelemy Vessemont 79e528c93a Using npm lwrp from optiflows-cookbooks/npm 2014-04-09 17:54:21 +02:00
Barthélemy Vessemont ee2714015e Merge pull request #1 from redguide/install
Refactor install
2014-04-09 16:54:14 +02:00
11 arquivos alterados com 176 adições e 7 exclusões
+3
Ver Arquivo
@@ -41,9 +41,11 @@ suites:
- name: npm
run_list:
- recipe[nodejs::npm]
- recipe[nodejs_test::npm]
- name: npm_embedded
run_list:
- recipe[nodejs::npm]
- recipe[nodejs_test::npm]
attributes:
nodejs:
npm:
@@ -51,6 +53,7 @@ suites:
- name: npm_source
run_list:
- recipe[nodejs::npm]
- recipe[nodejs_test::npm]
attributes:
nodejs:
npm:
+1
Ver Arquivo
@@ -4,4 +4,5 @@ metadata
group :integration do
cookbook 'apt'
cookbook 'nodejs_test', :path => './test/cookbooks/nodejs_test'
end
+4 -2
Ver Arquivo
@@ -18,7 +18,7 @@
#
case node['platform_family']
when 'smartos', 'rhel', 'debian', 'fedora'
when 'smartos', 'rhel', 'debian', 'fedora', 'mac_os_x'
default['nodejs']['install_method'] = 'package'
else
default['nodejs']['install_method'] = 'source'
@@ -28,7 +28,7 @@ default['nodejs']['version'] = '0.10.26'
default['nodejs']['prefix_url'] = ::URI.join('http://nodejs.org/dist', "v#{node['nodejs']['version']}").to_s
default['nodejs']['install_repo'] = true
default['nodejs']['install_repo'] = true # Only if available, ie rhel / debian
default['nodejs']['source']['url'] = nil # Auto generated
default['nodejs']['source']['checksum'] = 'ef5e4ea6f2689ed7f781355012b942a2347e0299da0804a58de8e6281c4b1daa'
@@ -37,3 +37,5 @@ default['nodejs']['binary']['url'] = nil # Auto generated
default['nodejs']['binary']['checksum']['linux_x64'] = '305bf2983c65edea6dd2c9f3669b956251af03523d31cf0a0471504fd5920aac'
default['nodejs']['binary']['checksum']['linux_x86'] = '8fa2d952556c8b5aa37c077e2735c972c522510facaa4df76d4244be88f4dc0f'
default['nodejs']['binary']['checksum']['linux_arm-pi'] = '561ec2ebfe963be8d6129f82a7d1bc112fb8fbfc0a1323ebe38ef55850f25517'
default['nodejs']['mac_pkg']['checksum'] = '99b718692a77195e3aafab819b42ad7dba7e90e05a9b6f078bc5171c041331f8'
+5 -4
Ver Arquivo
@@ -1,12 +1,13 @@
case node['platform_family']
when 'debian'
default['nodejs']['repo'] = 'http://ppa.launchpad.net/chris-lea/node.js/ubuntu'
default['nodejs']['packages'] = node['nodejs']['install_repo'] ? %w(nodejs) : %w(nodejs npm nodejs-dev)
default['nodejs']['packages'] = node['nodejs']['install_repo'] ? 'nodejs' : %w(nodejs npm nodejs-dev)
when 'rhel', 'fedora'
default['nodejs']['packages'] = %w(nodejs nodejs-devel npm)
when 'smartos'
default['nodejs']['packages'] = %w(nodejs)
default['nodejs']['packages'] = 'nodejs'
when 'mac_os_x'
default['nodejs']['packages'] = 'node'
else
Chef::Log.error 'There are no nodejs packages for this platform; please use the source or binary method to install node'
return
Chef::Log.info 'There are no nodejs packages for this platform; please use the source or binary method to install node'
end
+16
Ver Arquivo
@@ -19,5 +19,21 @@ module NodeJs
version = cmd.run_command.stdout.chomp
::File.exist?("#{node['nodejs']['dir']}/bin/node") && version == "v#{node['nodejs']['version']}"
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)
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.key?(package) && (version ? list[package]['version'] == version : true)
end
end
end
+3 -1
Ver Arquivo
@@ -11,13 +11,15 @@ recipe 'nodejs', 'Installs Node.JS based on the default installation method'
recipe 'nodejs::install_from_source', 'Installs Node.JS from source'
recipe 'nodejs::install_from_binary', 'Installs Node.JS from official binaries'
recipe 'nodejs::install_from_package', 'Installs Node.JS from packages'
recipe 'nodejs::install_from_mac_pkg', 'Installs Node.JS from MacOs X .pkg file'
recipe 'nodejs::npm', 'Installs npm from source - a package manager for node'
depends 'yum-epel'
depends 'build-essential'
depends 'ark'
depends 'apt'
depends 'homebrew', '~> 1.5.5'
%w(debian ubuntu centos redhat smartos).each do |os|
%w(debian ubuntu centos redhat smartos mac_os_x).each do |os|
supports os
end
+47
Ver Arquivo
@@ -0,0 +1,47 @@
include NodeJs::Helper
use_inline_resources if defined?(use_inline_resources)
action :install do
execute "install NPM package #{new_resource.name}" do
cwd new_resource.path
command "npm install #{npm_options}"
user new_resource.user
group new_resource.group
environment 'HOME' => ::Dir.home(new_resource.user), 'USER' => new_resource.user if new_resource.user
not_if { installed? }
end
end
action :uninstall do
execute "uninstall NPM package #{new_resource.package}" do
cwd new_resource.path
command "npm uninstall #{npm_options}"
user new_resource.user
group new_resource.group
environment 'HOME' => ::Dir.home(new_resource.user), 'USER' => new_resource.user if new_resource.user
only_if { installed? }
end
end
def installed?
new_resource.package && npm_package_installed?(new_resource.package, new_resource.version, new_resource.path)
end
def npm_options
options = ''
options << ' -global' unless new_resource.path
options << " #{npm_package}"
end
def npm_package
if new_resource.json
return new_resource.json.is_a?(String) ? new_resource.json : nil
elsif new_resource.url
return new_resource.url
elsif new_resource.package
return new_resource.version ? "#{new_resource.package}@#{new_resource.version}" : new_resource.package
else
Chef::Log.error("No good options found to install #{new_resource.name}")
end
end
+33
Ver Arquivo
@@ -0,0 +1,33 @@
#
# Author:: Angel Abad <angelabad@gmail.com>
# Cookbook Name:: nodejs
# Recipe:: install_from_mac_pkg
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
filename = "node-v#{node['nodejs']['version']}.pkg"
url = node['nodejs']['mac_os_x']['url']
nodejs_mac_os_x_url = url ? url : ::URI.join(node['nodejs']['prefix_url'], filename).to_s
remote_file ::File.join(Chef::Config[:file_cache_path], 'node.pkg') do
source nodejs_mac_os_x_url
checksum node['nodejs']['mac_pkg']['checksum']
notifies :run, 'execute[install nodejs on mac]', :immediately
end
execute 'install nodejs with mac_pkg' do
command "installer -pkg #{Chef::Config[:file_cache_path]}/node.pkg -target /"
action :nothing
not_if "node --version | grep v#{node['nodejs']['version']}"
end
+32
Ver Arquivo
@@ -0,0 +1,32 @@
#
# Cookbook Name:: nodejs
# Resource:: npm
#
# Author:: Sergey Balbeko <sergey@balbeko.com>
#
# Copyright 2012, Sergey Balbeko
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
actions :install, :uninstall
default_action :install
attribute :package, :name_attribute => true
attribute :version, :kind_of => String
attribute :path, :kind_of => String
attribute :url, :kind_of => String
attribute :json, :kind_of => [String, TrueClass]
attribute :user, :kind_of => String
attribute :group, :kind_of => String
+4
Ver Arquivo
@@ -0,0 +1,4 @@
name 'nodejs_test'
version '0.1.0'
depends 'git'
+28
Ver Arquivo
@@ -0,0 +1,28 @@
include_recipe 'git'
user 'random' do
supports :manage_home => true
home '/home/random'
end
# global "express"
nodejs_npm 'express'
nodejs_npm 'async' do
version '0.6.2'
end
nodejs_npm 'request' do
url 'github mikeal/request'
end
git '/home/random/grunt' do
repository 'https://github.com/gruntjs/grunt'
user 'random'
end
nodejs_npm 'grunt' do
path '/home/random/grunt'
json true
user 'random'
end