nodebrew.rb 3.51 KB
Newer Older
1 2 3 4 5
require 'package'

class Nodebrew < Package
  description 'Node.js version manager'
  homepage 'https://github.com/hokaccha/nodebrew'
6 7
  @_ver = '1.0.1'
  version "#{@_ver}-1"
8
  compatibility 'all'
9
  source_url "https://github.com/hokaccha/nodebrew/archive/v#{@_ver}.tar.gz"
10
  source_sha256 'c34e7186d4fd493c5417ad5563ad39fd493a42695bd9a7758c3df10380e43399'
11

12 13 14 15 16 17 18 19 20 21 22 23 24
  binary_url({
    aarch64: 'https://dl.bintray.com/chromebrew/chromebrew/nodebrew-1.0.1-1-chromeos-armv7l.tar.xz',
     armv7l: 'https://dl.bintray.com/chromebrew/chromebrew/nodebrew-1.0.1-1-chromeos-armv7l.tar.xz',
       i686: 'https://dl.bintray.com/chromebrew/chromebrew/nodebrew-1.0.1-1-chromeos-i686.tar.xz',
     x86_64: 'https://dl.bintray.com/chromebrew/chromebrew/nodebrew-1.0.1-1-chromeos-x86_64.tar.xz'
  })
  binary_sha256({
    aarch64: 'e3c4bfac2033982be9859766dc9b7c00a018cbdc0c233f54b0725295baabd770',
     armv7l: 'e3c4bfac2033982be9859766dc9b7c00a018cbdc0c233f54b0725295baabd770',
       i686: 'ca1437cc074946cd723a691a89ca127d3c1f95beea6015fa74cf66fe074a6c22',
     x86_64: 'bcf965ab509fca115094ba9ed146c0b9fe43a37055b2b233b32cf77bde659f08'
  })

25
  def self.install
26
    FileUtils.mkdir_p "#{CREW_DEST_PREFIX}/share/nodebrew/default"
27
    system "NODEBREW_ROOT=#{CREW_DEST_PREFIX}/share/nodebrew perl nodebrew setup > /dev/null"
28 29 30 31 32 33 34 35 36
    FileUtils.mkdir_p CREW_DEST_HOME
    FileUtils.mkdir_p "#{CREW_DEST_PREFIX}/bin"
    FileUtils.ln_s "#{CREW_PREFIX}/share/nodebrew/nodebrew", "#{CREW_DEST_PREFIX}/bin/"
    FileUtils.ln_s "#{CREW_PREFIX}/share/nodebrew/current/bin/node", "#{CREW_DEST_PREFIX}/bin/"
    FileUtils.ln_s "#{CREW_PREFIX}/share/nodebrew/current/bin/npm", "#{CREW_DEST_PREFIX}/bin/"
    FileUtils.ln_s "#{CREW_PREFIX}/share/nodebrew/current/bin/npx", "#{CREW_DEST_PREFIX}/bin/"
    FileUtils.ln_s "#{CREW_PREFIX}/share/nodebrew/current/bin/node", "#{CREW_DEST_PREFIX}/bin/nodejs"
    FileUtils.ln_s "#{CREW_PREFIX}/share/nodebrew", "#{CREW_DEST_HOME}/.nodebrew"
    FileUtils.ln_sf "#{CREW_PREFIX}/share/nodebrew", "#{HOME}/.nodebrew"
37 38 39
  end

  def self.postinstall
40
    FileUtils.ln_sf "#{CREW_PREFIX}/share/nodebrew/default", "#{CREW_PREFIX}/share/nodebrew/current"
41
    puts
42 43
    puts 'Nodebrew completion support is available for the following shells:'.lightblue
    puts 'bash fish zsh'.lightblue
44
    puts
45
    puts 'To add nodebrew completion for bash, execute the following:'.lightblue
46
    puts "echo '# nodebrew completion' >> ~/.bashrc".lightblue
47 48
    puts "echo 'if [ -f #{CREW_PREFIX}/share/nodebrew/completions/bash/nodebrew-completion ]; then' >> ~/.bashrc".lightblue
    puts "echo '  source #{CREW_PREFIX}/share/nodebrew/completions/bash/nodebrew-completion' >> ~/.bashrc".lightblue
49
    puts "echo 'fi' >> ~/.bashrc".lightblue
50
    puts 'source ~/.bashrc'.lightblue
51
    puts
52
    puts 'To complete the installation, execute the following:'.lightblue
Ed Reel's avatar
Ed Reel committed
53 54
    puts "echo 'export PATH=\$HOME/.nodebrew/current/bin:\$PATH' >> ~/.bashrc && source ~/.bashrc".lightblue
    puts
55 56 57
    puts 'To install the latest node, execute:'.lightblue
    puts 'nodebrew install-binary latest'.lightblue
    puts 'nodebrew use latest'.lightblue
58
    puts
59
  end
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
  
  def self.remove
    if Dir.exists? "#{CREW_PREFIX}/share/nodebrew"
      puts
      print "Would you like to remove #{CREW_PREFIX}/share/nodebrew? [y/N] "
      response = STDIN.getc
      case response
      when "y", "Y"
        FileUtils.rm_rf "#{CREW_PREFIX}/share/nodebrew"
        puts "#{CREW_PREFIX}/share/nodebrew removed.".lightred
      else
        puts "#{CREW_PREFIX}/share/nodebrew saved.".lightgreen
      end
      puts
    end
  end  
76
end