Class: Jets::Commands::RakeTasks

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/commands/rake_tasks.rb

Constant Summary collapse

@@loaded =

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
false

Class Method Summary collapse

Class Method Details

.load!Object



12
13
14
15
16
17
18
19
20
# File 'lib/jets/commands/rake_tasks.rb', line 12

def load!
  return if @@loaded # prevent loading twice
  Jets::Booter.require_bundle_gems # use bundler when in project folder

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

  @@loaded = true
end

.load_webpacker_tasksObject

Handles load errors gracefuly per Booter.required_bundle_gems comments.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jets/commands/rake_tasks.rb', line 23

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