Browse files

Update node install

* Update to version v0.10.29
* Improve npm install and node uninstall
* Add node:list task
* Fix zsh checks for npm, bower, grunt for installing completion
  • Loading branch information...
1 parent c25f108 commit 2d0b176add18721cb0b922c6aad1880afa957e4a @ascarter committed Jul 21, 2014
Showing with 46 additions and 19 deletions.
  1. +22 −11 rakelib/node.rake
  2. +21 −5 rakelib/utils.rb
  3. +3 −3 src/zshrc
View
33 rakelib/node.rake
@@ -7,35 +7,46 @@ namespace "node" do
# Install node.js from package
unless File.exist?('/usr/local/bin/node')
# TODO: Get list of releases and prompt user to pick
- release = 'v0.10.26'
+ release = 'v0.10.29'
pkg = "node-#{release}.pkg"
pkg_url = "http://nodejs.org/dist/#{release}/#{pkg}"
pkg_download(pkg_url) do |p|
pkg_install(p)
end
end
end
- puts "Node.js: #{%x{/usr/local/bin/node --version}}"
- puts "npm: #{%x{/usr/local/bin/npm --version}}"
- # Update npm
- npm_update
+ node_version
# Install npm packages
pkgs = %w{bower coffeelint grunt-cli jslint jsonlint}
pkgs.each { |pkg| npm_install(pkg) }
-
- npm_list
end
-
+ desc "List installed modules"
+ task :list do
+ node_version
+ npm_ls
+ end
desc "Uninstall node"
task :uninstall do
if RUBY_PLATFORM =~ /darwin/
- pkg_uninstall("org.nodejs")
- ["/usr/local/lib/node", "/usr/local/lib/node_modules"].each do |dir|
- sudo_remove_dir(dir)
+ if File.exist?('/usr/local/bin/node')
+ # Remove all installed node modules and npm
+ npm_list.each do |pkg|
+ npm_uninstall pkg
+ end
+
+ npm_uninstall "npm"
+
+ pkg_uninstall("org.nodejs")
+
+ ["/usr/local/lib/node", "/usr/local/lib/node_modules"].each do |dir|
+ sudo_remove_dir(dir)
+ end
+ else
+ puts 'Node.js is not installed'
end
end
end
View
26 rakelib/utils.rb
@@ -237,11 +237,16 @@ def pkg_uninstall(pkg, prefix='/usr/local')
# npm
#
+def node_version
+ puts "Node.js: #{%x{/usr/local/bin/node --version}}"
+ puts "npm: #{%x{/usr/local/bin/npm --version}}"
+end
+
def npm_install(pkg)
- if %x{npm list --global --parseable #{pkg}}
- puts "#{pkg} already installed"
- else
+ if %x{npm list --global --parseable #{pkg}}.strip().empty?
sudo "npm install --global #{pkg}"
+ else
+ puts "#{pkg} already installed"
end
end
@@ -253,10 +258,21 @@ def npm_uninstall(pkg)
sudo "npm uninstall --global #{pkg}"
end
-def npm_list(pkg="", depth=0)
- sudo "npm list --global --depth=#{depth} #{pkg}"
+def npm_list
+ packages = []
+ %x{npm list --global --parseable --depth=0}.split("\n").each do |pkg|
+ pkg_name = File.basename(pkg)
+ unless %w{lib npm}.include?(pkg_name)
+ packages.push(File.basename(pkg_name))
+ end
+ end
+ return packages
end
+def npm_ls
+ puts "Installed npm modules:"
+ npm_list.each { |pkg| puts " #{pkg}" }
+end
#
# Mac OS X defaults
View
6 src/zshrc
@@ -22,17 +22,17 @@ if [[ -d $GOROOT && -e $GOROOT/misc/zsh/go ]]; then
fi
# npm
-if [ -n "`which npm`" ]; then
+if which npm &>/dev/null; then
. <(npm completion)
fi
# bower
-if [ -n "`which npm`" ]; then
+if which bower &>/dev/null; then
. <(bower completion)
fi
# grunt
-if [ -n "`which grunt`" ]; then
+if which grunt &>/dev/null; then
. <(grunt --completion=zsh)
fi

0 comments on commit 2d0b176

Please sign in to comment.