Sha256: 7ff99c5982bbc5c99f6c01b1a6a1c4f0140b9d899a2abd6d7adae30b78b4c67d

Contents?: true

Size: 1.45 KB

Versions: 26

Compression:

Stored size: 1.45 KB

Contents

require 'rake'

class Jets::Commands::RakeTasks
  class << self
    # Will only load the tasks once.  Just in case the user has already loaded
    # Jets rake tasks in their Rakefile. Example Rakefile that does this:
    #
    #   require 'jets'
    #   Jets.load_tasks
    #
    @@loaded = false
    def load!
      return if @@loaded # prevent loading twice
      # Run Bundler.setup so all project rake tasks also show up in `jets help`
      Jets::Bundle.setup

      Jets::Commands::Db::Tasks.load!
      load_webpacker_tasks

      @@loaded = true
    end

    # Handles load errors gracefuly per Booter.required_bundle_gems comments.
    def load_webpacker_tasks
      begin
        require "webpacker"
      rescue LoadError
        # puts "WARN: unable to load gem. #{$!}. Running with 'bundle exec' might fix this warning."
        # Happens whne user calls jets help outside the jets project folder.
        return
      end

      Webpacker::RakeTasks.load!
      # Thanks: https://coderwall.com/p/qhdhgw/adding-a-post-execution-hook-to-the-rails-db-migrate-task
      # Enchancing in case the user runs webpacker:install afterwards
      # instead of jets new.
      Rake::Task['webpacker:install'].enhance do
        # FORCE from rake webpacker:install FORCE=1
        # using ENV because rake webpacker:install is a rake task
        args ||= []
        args += ["--force"] if ENV['FORCE']
        Jets::Commands::WebpackerTemplate.start(args)
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
jets_bb_fork-0.0.4 lib/jets/commands/rake_tasks.rb
jets-1.9.32 lib/jets/commands/rake_tasks.rb
jets-1.9.31 lib/jets/commands/rake_tasks.rb
jets-1.9.30 lib/jets/commands/rake_tasks.rb
jets-1.9.29 lib/jets/commands/rake_tasks.rb
jets-1.9.28 lib/jets/commands/rake_tasks.rb
jets-1.9.27 lib/jets/commands/rake_tasks.rb
jets-1.9.26 lib/jets/commands/rake_tasks.rb
jets-1.9.25 lib/jets/commands/rake_tasks.rb
jets-1.9.24 lib/jets/commands/rake_tasks.rb
jets-1.9.23 lib/jets/commands/rake_tasks.rb
jets-1.9.22 lib/jets/commands/rake_tasks.rb
jets-1.9.21 lib/jets/commands/rake_tasks.rb
jets-1.9.20 lib/jets/commands/rake_tasks.rb
jets-1.9.19 lib/jets/commands/rake_tasks.rb
jets-1.9.18 lib/jets/commands/rake_tasks.rb
jets-1.9.17 lib/jets/commands/rake_tasks.rb
jets-1.9.16 lib/jets/commands/rake_tasks.rb
jets-1.9.15 lib/jets/commands/rake_tasks.rb
jets-1.9.14 lib/jets/commands/rake_tasks.rb