class WoodstovePackage
Public Class Methods
# File lib/woodstove/packagemanager.rb, line 8 def initialize name, site, directory, binpath @directory = directory @name = name @binpath = binpath @site = site end
Public Instance Methods
Runs a command inside the package directory.
# File lib/woodstove/packagemanager.rb, line 55 def exec_here command puts `cd "#{@directory}" && #{command}` end
Terminate the program, throwing the specified error.
# File lib/woodstove/packagemanager.rb, line 37 def exit_with_error error puts "Error managing #{@name} in #{@directory}: #{error}" exit 1 end
Returns a command to run the specified script file.
# File lib/woodstove/packagemanager.rb, line 138 def generate_run_command script exit_with_error "Trying to create run command for invalid script: #{script}" if !has_script? script kf = kindling scriptfile = kf['scripts'][script] fullpath = "\"#{@directory}/#{kf['scripts'][script]}\"" case scriptfile.split('.')[-1] when 'rb' "ruby #{fullpath}" when 'sh' "bash #{fullpath}" when 'js' "node #{fullpath}" when 'py' "python #{fullpath}" else fullpath end end
Returns the git clone / github url for this package.
# File lib/woodstove/packagemanager.rb, line 43 def giturl case @site when 'gitlab' "https://gitlab.com/#{@name}" when 'github' "https://github.com/#{@name}" else exit_with_error "Invalid site: #{@site}" end end
Returns true if the specified script exists.
# File lib/woodstove/packagemanager.rb, line 95 def has_script? script kf = kindling kf['scripts'] && kf['scripts'][script] end
Install this package by cloning it from github.
# File lib/woodstove/packagemanager.rb, line 60 def install branch puts giturl if is_installed? exec_here "git init && git remote add origin \"#{giturl}\"" if !is_repo? exec_here "git pull --all" else `git clone -b #{branch} "#{giturl}" "#{@directory}"` end exec_here "git checkout #{branch}" if is_package? install_dependencies install_bins end install_external_deps end
Puts the binaries for this package on the binpath.
# File lib/woodstove/packagemanager.rb, line 101 def install_bins kf = kindling if kf['bin'] != nil kf['bin'].each do |bin| # Create and make the script file executable. FileUtils.mkdir_p @binpath FileUtils.touch "#{@binpath}/#{bin[0]}" `chmod +x "#{@binpath}/#{bin[0]}"` # Insert a run command into the script file. File.open "#{@binpath}/#{bin[0]}", 'w' do |file| file.puts generate_run_command bin[1] end end end self end
Installs the dependencies for this package inside the `kindling` directory.
# File lib/woodstove/packagemanager.rb, line 84 def install_dependencies kf = kindling if kf['depends'] != nil kf['depends'].each do |package| install_package package, "#{@directory}/kindling", "#{@directory}/kindling/.bin" end end self end
Installs dependencies for other package managers if present.
# File lib/woodstove/packagemanager.rb, line 131 def install_external_deps exec_here 'npm i' if File.exists? "#{@directory}/package.json" exec_here 'bundle install' if File.exists? "#{@directory}/Gemfile" self end
Returns true if the package directory exists.
# File lib/woodstove/packagemanager.rb, line 21 def is_installed? File.exists? "#{@directory}" end
Returns true if the package and kindling.yaml file exist.
# File lib/woodstove/packagemanager.rb, line 16 def is_package? File.exists? "#{@directory}/kindling.yaml" end
Returns true if the package directory is a valid git repository.
# File lib/woodstove/packagemanager.rb, line 26 def is_repo? File.exists? "#{@directory}/.git" end
Returns the kindling.yaml data for this package.
# File lib/woodstove/packagemanager.rb, line 31 def kindling exit_with_error 'Missing kindlingfile.' if !is_package? YAML.load File.read("#{@directory}/kindling.yaml") end
Removes this package.
# File lib/woodstove/packagemanager.rb, line 77 def remove exit_with_error "Packages must be installed to be removed." if !is_installed? remove_bins if is_package? FileUtils.rm_rf @directory end
Removes the binaries for this package from the binpath.
# File lib/woodstove/packagemanager.rb, line 120 def remove_bins kf = kindling if kf['bin'] != nil kf['bin'].each do |bin| FileUtils.rm "#{@binpath}/#{bin[0]}" end end self end
Runs the specified script with the specified arguments.
# File lib/woodstove/packagemanager.rb, line 158 def run_script script, args exit_with_error "Trying to run invalid script: #{script}" if !has_script? script exec "#{generate_run_command script} #{args}" end