# frozen_string_literal: true

namespace :javascript do
  desc "Run `yarn lint`"
  task :lint do # rubocop:disable Rails/RakeEnvironment
    system "yarn lint"
  end

  desc "Run `yarn test`"
  task :test do # rubocop:disable Rails/RakeEnvironment
    if ENV["COVERAGE"]
      system "yarn test:coverage"
    else
      system "yarn test"
    end
  end
end

# frozen_string_literal: true

namespace :javascript do
  desc "Run `yarn lint`"
  task :lint do # rubocop:disable Rails/RakeEnvironment
    system "yarn lint"
  end

  desc "Run `yarn test`"
  task :test do # rubocop:disable Rails/RakeEnvironment
    if ENV["COVERAGE"]
      system "yarn test:coverage"
    else
      system "yarn test"
    end
  end

  if ENV["REMOVE_JS_BUILD_YARN_INSTALL"] == "true"
    Rake::Task["javascript:build"].clear

    desc "Build your JavaScript bundle"
    task :build do # rubocop:disable Rails/RakeEnvironment
      unless system("yarn build")
        raise "jsbundling-rails: Command build failed, " \
              "ensure yarn is installed and `yarn build` runs without errors"
      end
    end
  end
end

Add option to remove yarn install from the JavaScript build task.
Add option to remove yarn install from the JavaScript build task.

When deploying with a Node.js buildpack, the dependencies will already be
installed making this call redundant. The ability to remove it will speed up
deployments.
