begin
  require "cookstyle/chefstyle"
  require "rubocop/rake_task"
  desc "Run Chefstyle tests"
  RuboCop::RakeTask.new(:style) do |task|
    task.options += ["--display-cop-names", "--no-color"]
  end
rescue LoadError
  puts "cookstyle gem is not installed. bundle install first to make sure all dependencies are installed."
end
task default: %i{style}

desc "Refresh project Gemfile.locks (components/gems and omnibus) with the latest dependencies."
task :update do
  require "bundler"
  Bundler.with_unbundled_env do
    ["./components/gems/", "./omnibus/"].each do |dir|
      Dir.chdir(dir) do
        sh "bundle lock --update --add-platform ruby x64-mingw32 x86-mingw32 x64-mingw-ucrt"
      end
    end
  end
end
