require 'open3' class App < MCLI::Command register_as :app description "Create a new rails app with juan's defaults" option :database, alias: 'd', default: 'postgresql' option 'skip-sprockets', boolean: true, default: true option 'skip-coffee', boolean: true, default: true option 'skip-test', boolean: true, default: true option 'skip-turbolinks', boolean: true, default: true option 'webpack', default: 'vue' def run @app_name = args[0] run_command rails_new Dir.chdir("./#{@app_name}") run_command procfile run_command bin_up run_command bundle_add run_command bundle_add_dev_test run_command db_up run_command rspec run_command devise run_command tailwindcss end def help puts "#{self.class.description}\n\n#{parser.to_s}" end private def run_command(cmd) puts 'RUN: ' puts "#{cmd}\n\n" Open3.popen3(cmd) do |stdout, stderr, status, thread| while err=stderr.gets do puts(err) end while out=stdout.gets do puts(out) end rescue IOError => e end end def rails_new "rails new #{@app_name} " \ "-d #{options[:database] } " \ "#{'--skip-sprockets' if options[:'skip-sprockets']} " \ "#{'--skip-coffee' if options[:'skip-coffee']} " \ "#{'--skip-test' if options[:'skip-test']} " \ "#{'--skip-turbolinks' if options[:'skip-turbolinks']} " \ "--webpack=#{options[:webpack]}" end def procfile "echo -e 'web: bundle exec rails s\nwebpacker: ./bin/webpack-dev-server' > Procfile.dev" end def bin_up "echo -e '#!/bin/bash\n\nforeman start -f Procfile.dev' > bin/up && chmod +x bin/up" end def bundle_add 'bundle add redis devise name_of_person rack-mini-profiler flamegraph stackprof memory_profiler active_model_serializers pundit bullet rack-attack' end def bundle_add_dev_test "bundle add foreman rspec-rails pry rubocop rubocop-rails factory_bot_rails " \ "capybara chromedriver-helper selenium-webdriver shoulda-matchers " \ "dotenv-rails simplecov --group 'development, test'" end def db_up 'rails db:create && rails db:migrate' end def rspec 'rails generate rspec:install' end def devise 'rails generate devise:install && rails generate devise User && rails g devise:views' end def tailwindcss "yarn add tailwindcss --dev " \ "&& mkdir app/javascript/css " \ "&& node_modules/.bin/tailwind init " \ "&& sed -i '/ plugins: \[/a\ \ \ \ require('\"'\"'tailwindcss'\"'\"'),' postcss.config.js" end end