lib/raykit/tasks.rb



# frozen_string_literal: true


desc "Display project information"
task :info do
  PROJECT.info
end

desc "integrate changes into the git repository"
task :integrate do
  puts Rainbow(": integrate").blue.bright

  if PROJECT.read_only?
    puts "  read only state, skipping integrate operations"
  else
    git_dir = Raykit::Git::Directory.new(Rake.application.original_dir)
    if git_dir.detached?
      puts "  detached head state, skipping integrate operations"
    else
      if PROJECT.outstanding_commit?
        Rake::Task["test"].invoke if Rake::Task.task_defined?("test")
      else
        puts "  no outstanding commits detected"
      end

      if !File.exist?(".gitignore")
        puts "warning: .gitignore does not exist."
      else
        PROJECT.run("git add --all")
        unless `git status`.include?("nothing to commit")
          # if(PROJECT.outstanding_commit?)

          commit_message = "integrate"
          PROJECT.run("git commit -m\"#{commit_message}\"") if PROJECT.outstanding_commit?
          PROJECT.run("git pull")
          # PROJECT.run("git push")

          # PROJECT.run("git push --tags")

        end
      end
    end
  end
end

desc "push changes including tags"
task :push do
  git_dir = Raykit::Git::Directory.new(Rake.application.original_dir)
  if git_dir.detached?
    puts "detached head state, skipping push operations"
  else
    PROJECT.run("git push")
    PROJECT.run("git push --tags")
  end
end

desc "clean files not tracked by git"
task :clean do
  puts Rainbow(": clean").blue.bright
  PROJECT.run("git clean -dXf")
end

desc "update_source from sourceImports.json"
task :update_source do
  if File.exist?("sourceImports.json")
    puts Rainbow(":update_source").blue.bright
    sourceImports = Raykit::SourceImports.load("sourceImports.json")
    json = sourceImports.to_json
    sourceImports.update

    json2 = sourceImports.to_json
    if json2 != json || !sourceImports.targets_exist?
      sourceImports.save("sourceImports.json")
      sourceImports.copy
    else
      puts "        no update required."
    end
  end
end

desc "update source files"
task update: [:update_source]