# 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' PROCESSING_GITHUB = 'https://github.com/processing' VIDEO = 'video.zip' DOWNLOAD = 'releases/download/latest' 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', PROCESSING_GITHUB].join(' ') wget_string = [wget_base, 'processing-sound', DOWNLOAD, SOUND].join('/') begin sh wget_string rescue StandardError warn(WARNING) end end desc 'download video library' task :download_video do wget_base = ['wget', PROCESSING_GITHUB].join(' ') wget_string = [wget_base, 'processing-video', DOWNLOAD, VIDEO].join('/') begin sh wget_string rescue StandardError warn(WARNING) end 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, 'picrate_sketches.geany') FileUtils.mkdir_p "#{HOME_DIR}/projects" config = GeanyConfig.new(project_dir) config.save(File.join(project_dir, '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 sh "unzip #{SOUND}" sh "rm -r #{LIBRARY}/sound" if File.exist? "#{LIBRARY}/sound" sh "cp -r sound #{LIBRARY}" sh 'rm -r sound' end desc 'copy video library' task copy_video: VIDEO do sh "unzip #{VIDEO}" sh "rm -r #{LIBRARY}/video" if File.exist? "#{LIBRARY}/video" sh "cp -r video #{LIBRARY}" sh 'rm -r video' end