Sha256: a17759eeb3f44ab7dc29e76f8d46c5ea312208cc2474506f981a8a4ae265e4f4

Contents?: true

Size: 1.65 KB

Versions: 27

Compression:

Stored size: 1.65 KB

Contents

# desc 'Explaining what the task does'
# task :avo do
#   # Task goes here
# end

def ensure_log_goes_to_stdout
  old_logger = Webpacker.logger
  Webpacker.logger = ActiveSupport::Logger.new(STDOUT)
  yield
ensure
  Webpacker.logger = old_logger
end


namespace :avo do
  namespace :webpacker do
    desc 'Install deps with yarn'
    task :yarn_install do
      Dir.chdir(File.join(__dir__, '../..')) do
        system 'yarn install --no-progress --production'
      end
    end

    desc 'Compile JavaScript packs using webpack for production with digests'
    task compile: [:yarn_install, :environment] do
      Webpacker.with_node_env('production') do
        ensure_log_goes_to_stdout do
          if Avo.webpacker.commands.compile
            # Successful compilation!
          else
            # Failed compilation
            exit!
          end
        end
      end
    end
  end
end

def yarn_install_available?
  rails_major = Rails::VERSION::MAJOR
  rails_minor = Rails::VERSION::MINOR

  rails_major > 5 || (rails_major == 5 && rails_minor >= 1)
end

def enhance_assets_precompile
  # yarn:install was added in Rails 5.1
  deps = yarn_install_available? ? [] : ['avo:webpacker:yarn_install']
  # Rake::Task['assets:precompile'].enhance(deps) do
  #   Rake::Task['avo:webpacker:compile'].invoke
  # end
end

# Compile packs after we've compiled all other assets during precompilation
skip_webpacker_precompile = %w(no false n f).include?(ENV['WEBPACKER_PRECOMPILE'])

unless skip_webpacker_precompile
  if Rake::Task.task_defined?('assets:precompile')
    enhance_assets_precompile
  else
    Rake::Task.define_task('assets:precompile' => 'avo:webpacker:compile')
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
avo-0.5.0.beta9 lib/tasks/avo_tasks.rake
avo-0.5.0.beta8 lib/tasks/avo_tasks.rake
avo-0.5.0.beta7 lib/tasks/avo_tasks.rake
avo-0.5.0.beta6 lib/tasks/avo_tasks.rake
avo-0.5.0.beta5 lib/tasks/avo_tasks.rake
avo-0.5.0.beta4 lib/tasks/avo_tasks.rake
avo-0.5.0.beta3 lib/tasks/avo_tasks.rake
avo-0.5.0.beta2 lib/tasks/avo_tasks.rake
avo-0.5.0.beta1 lib/tasks/avo_tasks.rake
avo-0.4.10 lib/tasks/avo_tasks.rake
avo-0.4.9 lib/tasks/avo_tasks.rake
avo-0.4.8 lib/tasks/avo_tasks.rake
avo-0.4.7 lib/tasks/avo_tasks.rake
avo-0.4.6 lib/tasks/avo_tasks.rake
avo-0.4.5 lib/tasks/avo_tasks.rake
avo-0.4.4 lib/tasks/avo_tasks.rake
avo-0.4.3 lib/tasks/avo_tasks.rake
avo-0.4.2 lib/tasks/avo_tasks.rake
avo-0.4.1 lib/tasks/avo_tasks.rake
avo-0.3.2 lib/tasks/avo_tasks.rake