# frozen_string_literal: true require_relative "lib/makit" desc "setup the environment" task :setup do puts ":setup".colorize(:blue) "bundle install".run # setup jekyll static web site "jekyll new pages --skip-bundle".run unless Dir.exist?("pages") FileUtils.mkdir_p("pages/_layouts") unless Dir.exist?("pages/_layouts") Dir.chdir("pages/_layouts") do "curl -O https://raw.githubusercontent.com/jekyll/minima/master/_layouts/default.html".run end raise "pages/_layouts/default.html not found" unless File.exist?("pages/_layouts/default.html") Makit::Protoc::setup end desc "generate code from proto file" task :generate do puts ":generate".colorize(:blue) "protoc --ruby_out=. lib/makit/v1/makit.v1.proto".run #puts " grpc_tools_ruby_protoc -I . --ruby_out=. --grpc_out=. lib/makit/v1/makit.v1.proto" #"grpc_tools_ruby_protoc -I . --ruby_out=. --grpc_out=. lib/makit/v1/makit.v1.proto".run puts " replacing require statement in makit.v1_services.rb" # replace the require 'lib/makit/makit_pb' with require_relative 'makit_pb' # require 'lib/makit/v1/makit.v1_pb' File.write("lib/makit/v1/makit.v1_services_pb.rb", File.read("lib/makit/v1/makit.v1_services_pb.rb").gsub("require 'lib/makit/v1/makit.v1_pb'", "require_relative 'makit.v1_pb'")) end desc "build the gem" task :build => [:generate] do puts ":build".colorize(:blue) "gem build makit.gemspec".run Dir.chdir("pages") do #"bundle exec jekyll build -d ../artifacts/pages".run #"jekyll build -d ../artifacts/website".run end end desc "test the gem" task :test do puts ":test".colorize(:blue) puts " rakefile is " + "#{Rake.application.rakefile}".colorize(:green) `ruby -r minitest/autorun test/test_makit.rb -- --fail-fast > artifacts/test_makit.log 2>&1` "ruby -r minitest/autorun test/test_makit.rb -- --fail-fast".run #"bundle exec rake".run end desc "test the examples" task :test_examples do start_time = Time.now puts "=" * 80 puts ":test_examples".colorize(:blue) + " started at #{start_time}" puts "=" * 80 # loop over each directory in the examples directory and print out its name Dir.glob("examples/*").each do |dir| puts "#{dir}".colorize(:bold) Dir.chdir(dir) do # run the rake command in each directory "rake".run # delete the .gitignore file in each directory File.delete(".gitignore") if File.exist? ".gitignore" end end puts "=" * 80 puts ":test_examples".colorize(:blue) + " completed in #{Time.now - start_time} seconds" puts "=" * 80 end desc "update the project" task :update do # : "rubocop:autocorrect_all" do "rufo .".run({ exit_on_error: false }) "bundle update".run end desc "install the gem" task :install => [:build] do puts ":install".colorize(:blue) "gem uninstall makit -a -x".run "gem install makit-#{Makit::VERSION}.gem".run # publish to [HOME]/code/artifacts/rubygems if (Dir.exist?(File.join(Makit::Directories::HOME, "code", "artifacts", "rubygems"))) puts " copying gem to [HOME]/code/artifacts/rubygems".colorize(:green) FileUtils.cp("makit-#{Makit::VERSION}.gem", File.join(Makit::Directories::HOME, "code", "artifacts", "rubygems")) end # publish to [ONEDRIVE]/code/rubygems if (Dir.exist?(File.join(Makit::Directories::ONEDRIVE, "code", "artifacts", "rubygems"))) puts " copying gem to [ONEDRIVE]/code/artifacts/rubygems".colorize(:green) FileUtils.cp("makit-#{Makit::VERSION}.gem", File.join(Makit::Directories::ONEDRIVE, "code", "artifacts", "rubygems")) end end task :publish => [:build,:test, :integrate] do puts ":publish".colorize(:blue) gem = "makit-#{Makit::VERSION}.gem" puts "gem file #{gem} does not exist" unless File.exist?(gem) gem_list_text =`gem list --remote makit`# Raykit::Command::new("gem list --remote makit").run.output if gem_list_text.include?("makit") "gem list --remote makit".run latest_published_version ='' makit_list= `gem list --remote makit`.gsub(" ruby", "").strip if(makit_list.length > 0) # check if scan is empty if(makit_list.scan(/makit \(([\d.]+)\)/).empty?) latest_published_version = "" else latest_published_version = makit_list.scan(/makit \(([\d.]+)\)/).last.first end end all_versions = `gem list --remote makit --all` puts " last published version #{latest_published_version}" if Makit::VERSION == latest_published_version || all_versions.include?("#{Makit::VERSION}") puts " gem #{gem} already published" else "gem push #{gem}".run end else puts " unable to list Makit::VERSION from --remote, internet may not be available" end end task :info do puts ":info".colorize(:blue) # collect all tasks that have been defined in the Rakefile and display them #puts " tasks defined in the Rakefile" #Rake.application.tasks.each do |task| # puts " #{task.name}" #end largest_ruby_file = "?" largest_ruby_file_size = 0 largest_ruby_file_loc = 0 Dir.glob("**/*.rb").each do |file| file_size = File.size(file) if (file_size > largest_ruby_file_size) largest_ruby_file = file largest_ruby_file_size = file_size end end largest_ruby_file_loc = Makit::Directory::get_line_count(largest_ruby_file) puts " largest ruby file " + largest_ruby_file.colorize(:green) + " is #{largest_ruby_file_size} bytes" + " #{largest_ruby_file_loc} loc" end desc "execute the default tasks for the project" task default: %i[setup generate build test integrate sync install info] do SHARED_ARTIFACTS = File.join(Makit::Directories::ONEDRIVE, "artifacts") if (Dir.exist?(SHARED_ARTIFACTS)) #puts " copying gem to #{SHARED_ARTIFACTS}".colorize(:green) #FileUtils.cp("makit-#{Makit::VERSION}.gem", SHARED_ARTIFACTS) end Makit::LOGGER.info("completed in #{Time.now - Makit::STARTTIME} seconds") #system("bundle outdated") #puts `bundle outdated` end # # # # # # # # # # # # Register the at_exit hook for cleanup at_exit do puts "Performing cleanup..." # Add your cleanup code here # For example, close files, remove temporary files, etc. json_filename = File.join(Makit::Directories::PROJECT_ROOT, ".makit.project.json") puts "Saving project state to #{json_filename}" Makit::PROJECT.save_as(json_filename) end