class Bridgetown::Commands::Webpack

Public Class Methods

banner() click to toggle source
destination_root() click to toggle source
# File lib/bridgetown-core/commands/webpack.rb, line 40
def self.destination_root
  config.root_dir
end
exit_on_failure?() click to toggle source
# File lib/bridgetown-core/commands/webpack.rb, line 18
def self.exit_on_failure?
  true
end
source_root() click to toggle source
# File lib/bridgetown-core/commands/webpack.rb, line 36
def self.source_root
  File.expand_path("./webpack", __dir__)
end

Public Instance Methods

webpack() click to toggle source
# File lib/bridgetown-core/commands/webpack.rb, line 22
def webpack
  @logger = Bridgetown.logger
  return show_actions if args.empty?

  action = args.first
  if supported_actions.include?(action)
    perform action
  else
    @logger.error "Error:".red, "🚨 Please enter a valid action."
    say "\n"
    show_actions
  end
end

Protected Instance Methods

config() click to toggle source
# File lib/bridgetown-core/commands/webpack.rb, line 46
def config
  @config ||= Bridgetown.configuration({ root_dir: Dir.pwd })
end
package_json() click to toggle source
# File lib/bridgetown-core/commands/webpack.rb, line 50
def package_json
  @package_json ||= begin
    package_json_file = File.read(Bridgetown.sanitized_path(config.root_dir, "package.json"))
    JSON.parse(package_json_file)
  end
end
perform(action) click to toggle source
# File lib/bridgetown-core/commands/webpack.rb, line 57
def perform(action)
  automation = find_in_source_paths("#{action}.rb")
  inside(New.created_site_dir || Dir.pwd) do
    apply automation, verbose: false
  end
end
show_actions() click to toggle source
# File lib/bridgetown-core/commands/webpack.rb, line 64
def show_actions
  say "Available actions:\n".bold

  longest_action = supported_actions.keys.max_by(&:size).size
  supported_actions.each do |action, description|
    say action.ljust(longest_action).to_s.bold.blue + "\t" + "# #{description}"
  end
end
supported_actions() click to toggle source
# File lib/bridgetown-core/commands/webpack.rb, line 73
def supported_actions
  {
    setup: "Sets up a webpack integration with Bridgetown in your project",
    update: "Updates the Bridgetown webpack defaults to the latest available version",
    "enable-postcss": "Configures PostCSS in your project",
  }.with_indifferent_access
end