class Breakfast::Generators::InstallGenerator

Constants

NODE_VERSION

Public Instance Methods

install() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 9
      def install
        if node_prerequisites_installed?
          create_brunch_config
          create_package_json if using_rails_5_dot_0?
          install_required_packages
          create_directory_structure
          create_app_js_file
          create_app_scss_file
          create_gitkeep_files
          add_node_modules_to_gitignore

          puts <<-SUCCESS.strip_heredoc

            ---> BREAKFAST INSTALLED SUCCESSFULLY
            ---> See https://github.com/devlocker/breakfast for documentation and examples.

          SUCCESS
        else
          puts <<-ERROR.strip_heredoc

            ---> ERROR - MISSING NODE & YARN

            ---> Node version >= #{NODE_VERSION} & yarn are required to run Breakfast.
            ---> Please install them before attempting to continue.
            ---> https://nodejs.org
            ---> https://yarnpkg.com/docs/install/

          ERROR
        end
      end

Private Instance Methods

add_node_modules_to_gitignore() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 99
      def add_node_modules_to_gitignore
        ignore = <<-IGNORE.strip_heredoc
          # Added by Breakfast Gem
          yarn-error.log
          npm-debug.log
          node_modules/*
          public/assets/*
        IGNORE

        append_to_file(".gitignore", ignore)
      end
create_app_js_file() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 86
def create_app_js_file
  copy_file "app.js", "app/frontend/js/app.js"
end
create_app_scss_file() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 90
def create_app_scss_file
  copy_file "app.scss", "app/frontend/css/app.scss"
end
create_brunch_config() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 54
def create_brunch_config
  copy_file "brunch-config.js", "brunch-config.js"
end
create_directory_structure() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 79
def create_directory_structure
  empty_directory "app/frontend/css"
  empty_directory "app/frontend/images"
  empty_directory "app/frontend/js"
  empty_directory "app/frontend/vendor"
end
create_gitkeep_files() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 94
def create_gitkeep_files
  create_file "app/frontend/images/.gitkeep"
  create_file "app/frontend/vendor/.gitkeep"
end
create_package_json() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 58
def create_package_json
  copy_file "package.json", "package.json"
end
install_required_packages() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 62
def install_required_packages
  packages = %w(
    actioncable
    babel
    babel-brunch
    breakfast-rails
    brunch
    clean-css-brunch
    jquery
    jquery-ujs
    sass-brunch
    turbolinks
    uglify-js-brunch
  )
  run "yarn add #{packages.join(' ')}"
end
installed_node_version() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 50
def installed_node_version
  Gem::Version.new(`node -v`.tr("v", ""))
end
node_prerequisites_installed?() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 42
def node_prerequisites_installed?
  `which node`.present? && `which yarn`.present? && node_versions_are_satisfactory?
end
node_versions_are_satisfactory?() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 46
def node_versions_are_satisfactory?
  installed_node_version >= NODE_VERSION
end
using_rails_5_dot_0?() click to toggle source
# File lib/generators/breakfast/install_generator.rb, line 111
def using_rails_5_dot_0?
  Gem::Version.new(::Rails.version) < Gem::Version.new("5.1")
end