# frozen_string_literal: true require 'fileutils' require 'rake/clean' require_relative './geany' WARNING = 'WARNING: wget download failed you could do a manual download' SOUND = 'sound.zip' SOUND_VERSION = 'v1.3.2' VIDEO = 'video-2.0-beta4.zip' VIDEO_VERSION = 'r6-v2.0-beta4' EXAMPLES = '0.5.5' HOME_DIR = ENV['HOME'] LIBRARY = File.join(HOME_DIR, '.picrate', 'libraries') PROJECT_DIR = File.join(HOME_DIR, 'projects') EXAMPLES_DIR = File.join(PROJECT_DIR, 'examples') CLOBBER.include(EXAMPLES, SOUND, 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 picrate examples' task download_samples: ["#{EXAMPLES}.tar.gz"] desc 'download sound library' task :download_sound do wget_base = 'wget -P https://github.com/processing/processing-sound' wget_string = [wget_base, 'releases/download/latest', SOUND].join('/') system wget_string end desc 'download video library' task :download_video do wget_base = 'wget -P /tmp 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 project_dir = File.join(HOME_DIR, 'projects') unless File.exist? File.join(project_dir, 'examples', 'picrate_sketches.geany') FileUtils.mkdir_p "#{HOME_DIR}/projects/examples" config = GeanyConfig.new(project_dir, 'examples') config.save(File.join(project_dir, 'examples', 'picrate_sketches.geany')) end end desc 'copy examples' task copy_examples: %i[download_samples] do system "tar xzvf #{EXAMPLES}.tar.gz" FileUtils.rm_r EXAMPLES_DIR if File.exist? EXAMPLES_DIR FileUtils.mkdir_p PROJECT_DIR unless File.exist? PROJECT_DIR FileUtils.cp_r "picrate-examples-#{EXAMPLES}", EXAMPLES_DIR FileUtils.rm_r "picrate-examples-#{EXAMPLES}" end desc 'copy sound library' task copy_sound: SOUND do system "unzip -d /tmp /tmp/#{SOUND}" FileUtils.rm_r "#{LIBRARY}/sound" if File.exist? "#{LIBRARY}/sound" FileUtils.cp_r '/tmp/sound', LIBRARY end desc 'copy video library' task copy_video: "/tmp/#{VIDEO}" do system "unzip -d /tmp /tmp/#{VIDEO}" FileUtils.rm_r "#{LIBRARY}/video" if File.exist? "#{LIBRARY}/video" FileUtils.mkdir_p "#{LIBRARY}/video/library" FileUtils.mv Dir.glob('/tmp/video/library/*.jar'), "#{LIBRARY}/video/library" end