module TractorBeam class AppBuilder < Rails::AppBuilder def readme template "README.md.erb", "README.md" end def gitignore copy_file "tractor_beam_gitignore", ".gitignore" end def gemfile template "Gemfile.erb", "Gemfile" end def set_ruby_version create_file '.ruby-version', "#{TractorBeam::RUBY_VERSION}\n" end def procfile_dev template "Procfile.dev", "Procfile.dev" end def procfile template "Procfile", "Procfile" end def provide_setup_script template "bin_setup", "bin/setup", force: true run "chmod a+x bin/setup" end # Component Based frontend def remove_legacy_assets_folder remove_dir "app/assets" end def setup_root_frontend_folder empty_directory "frontend" inside "frontend" do directory "packs" directory "init" end end def create_application_layout template 'tractor_beam_layout.html.erb.erb', 'app/views/layouts/application.html.erb', force: true end def setup_browserlist_rc template "browserlistrc", ".browserlistrc" end def customize_webpacker_yml say "Customizing webpacker.yml" gsub_file "config/webpacker.yml", "source_path: app/javascript", "source_path: frontend" end def prepend_view_path_to_application_controller insert_into_file "app/controllers/application_controller.rb", " prepend_view_path Rails.root.join(\"frontend\")\n", after: "protect_from_forgery with: :exception\n" end # Linting def setup_js_linter run "yarn add --dev babel-eslint eslint eslint-config-airbnb-base " \ "eslint-config-prettier eslint-import-resolver-webpack " \ "eslint-plugin-import eslint-plugin-prettier " \ "lint-staged pre-commit prettier" template "eslintrc", ".eslintrc" end def setup_style_linter run "yarn add --dev stylelint stylelint-config-standard" template "stylelintrc", ".stylelintrc" end def add_scripts_to_package_json scripts = <<-SCRIPTS "scripts": { "lint-staged": "$(yarn bin)/lint-staged" }, "lint-staged": { "config/webpack/**/*.js": [ "prettier --write", "eslint", "git add" ], "frontend/**/*.js": [ "prettier --write", "eslint", "git add" ], "frontend/**/*.css": [ "prettier --write", "stylelint --fix", "git add" ] }, "pre-commit": [ "lint-staged" ], SCRIPTS insert_into_file "package.json", scripts, after: "},\n" end # Generators def configure_generators config = <<-RUBY config.generators do |g| g.helper false g.javascripts false g.request_specs false g.routing_specs false g.stylesheets false g.test_framework :rspec g.view_specs false g.channel assets: false end RUBY inject_into_class 'config/application.rb', 'Application', config end def component_generator empty_directory "lib/generators" template "component_generator", "lib/generators/component_generator.rb" end end end