# frozen_string_literal: true require 'fileutils' require 'rake/clean' WARNING = 'WARNING: wget download failed you could do a manual download' SOUND = 'sound.zip' SOUND_VERSION = 'v1.3.2' GLVIDEO = 'processing-glvideo.zip' VIDEO = 'video-2.zip' VIDEO_VERSION = '2' EXAMPLES = '0.4.0' HOME_DIR = ENV['HOME'] LIBRARY = File.join(HOME_DIR, '.picrate', 'libraries') CLOBBER.include(EXAMPLES, SOUND, GLVIDEO, VIDEO) def dependency system 'which wget' end desc 'check dependency' task :check_dependency do warn(WARNING) unless dependency end desc 'download, and copy picrate examples & configure geany' task default: %i[check_dependency install_samples install_config] file "#{EXAMPLES}.tar.gz" do wget_base = 'wget https://github.com/ruby-processing/picrate-examples' wget_string = [wget_base, 'archive', "#{EXAMPLES}.tar.gz"].join('/') system wget_string end desc 'download and install samples to ~/picrate_samples' task install_samples: %i[check_dependency download_samples copy_examples] desc 'download and copy sound library to ~/.picrate' task install_sound: %i[init_dir download_sound copy_sound clobber] desc 'download and copy video library to ~/.picrate' task install_video: %i[init_dir download_video copy_video clobber] desc 'download and copy glvideo library to ~/.picrate' task install_glvideo: %i[init_dir download_glvideo copy_glvideo clobber] desc 'download, and copy picrate examples' task download_samples: ["#{EXAMPLES}.tar.gz"] desc 'download sound library' task :download_sound do wget_base = 'wget https://github.com/processing/processing-sound' wget_string = [wget_base, 'releases/download/latest', SOUND].join('/') system wget_string end desc 'download glvideo library' task :download_glvideo do wget_base = 'wget https://github.com/gohai/processing-glvideo' wget_string = [wget_base, 'releases/download/latest', GLVIDEO].join('/') system wget_string end desc 'download video library' task :download_video do wget_base = 'wget https://github.com/processing/processing-video' wget_string = [wget_base, 'releases/download', VIDEO_VERSION, VIDEO].join('/') system wget_string end desc 'initialize ~/.picrate directories' task :init_dir do FileUtils.mkdir_p LIBRARY unless File.exist? LIBRARY end desc 'configure geany' task :install_config do unless File.exist? "#{HOME_DIR}/.config/geany/templates/files/picrate.rb" FileUtils.mkdir_p "#{HOME_DIR}/.config/geany/templates/files" FileUtils.cp 'picrate.rb', "#{HOME_DIR}/.config/geany/templates/files" end unless File.exist? "#{HOME_DIR}/projects/picrate.geany" FileUtils.mkdir_p "#{HOME_DIR}/projects" FileUtils.cp 'picrate.geany', "#{HOME_DIR}/projects" end end desc 'copy examples' task copy_examples: %i[download_samples] do system "tar xzvf #{EXAMPLES}.tar.gz" FileUtils.rm_r "#{HOME_DIR}/picrate_samples" if File.exist? "#{HOME_DIR}/picrate_samples" FileUtils.cp_r "picrate-examples-#{EXAMPLES}", "#{HOME_DIR}/picrate_samples" FileUtils.rm_r "picrate-examples-#{EXAMPLES}" end desc 'copy sound library' task copy_sound: SOUND do system "unzip #{SOUND}" FileUtils.rm_r "#{LIBRARY}/sound" if File.exist? "#{LIBRARY}/sound" FileUtils.cp_r 'sound', LIBRARY FileUtils.rm_r 'sound' end desc 'copy video library' task copy_video: VIDEO do system "unzip #{VIDEO}" FileUtils.rm_r "#{LIBRARY}/video" if File.exist? "#{LIBRARY}/video" FileUtils.cp_r 'video', LIBRARY FileUtils.rm_r 'video' end desc 'copy glvideo library' task copy_glvideo: GLVIDEO do directory "#{LIBRARY}/glvideo" system "unzip #{GLVIDEO}" FileUtils.rm_r "#{LIBRARY}/glvideo" if File.exist? "#{LIBRARY}/glvideo" FileUtils.cp_r 'glvideo', LIBRARY FileUtils.rm_r 'glvideo' end