Last active
May 30, 2022 10:06
-
-
Save dragonskyside/49f6db7f4ed02f29754a339dfa2e4237 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Template Name: template.rb | |
Author: Me | |
Instructions: $ rails new my-app -d<postgresql, mysql, sqlite3> -m example_template.rb | |
=end | |
def source_path | |
[File.expand_path(File.dirname(__FILE__))] | |
end | |
def add_gems | |
gem "devise", github: 'heartcombo/devise', branch: 'main' | |
gem 'sidekiq', '~> 6.4', '>= 6.4.2' | |
gem 'minitest-reporters', '~> 1.5' | |
end | |
def add_devise_users | |
#This will install devise on the app | |
generate "devise:install" | |
# Configure Devise | |
environment "config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }", env: 'development' | |
route "root to: 'home#index'" | |
#Create a Devise User | |
generate :devise, "User", "first_name", "last_name", "admin:boolean" | |
# Ensure admin boolean defaults to false | |
in_root do | |
migration = Dir.glob("db/migrate/*").max_by{ |f| File.mtime(f) } | |
gsub_file migration, /:admin/, ":admin, default: false" | |
end | |
def add_sidekiq | |
environment "config.active_job.queue_adapter = :sidekiq" | |
insert_into_file "config/routes.rb", | |
"require 'sidekiq/web'\n\n", | |
before: "Rails.application.routes.draw.do" | |
content = <<-RUBY | |
authenticate :user, lambda { |u| u.admin? } do | |
mount Sidekiq::Web => '/sidekiq' | |
end | |
RUBY | |
insert_into_file "config/routes.rb", "#{ content }\n\n", after: "Rails.application.routes.draw do\n" | |
end | |
def add_minitest_reporters | |
insert_into_file "test_helper.rb", "require 'minitest/reporters'\n Minitest::Reporters.use!", | |
after: "require 'rails/test_help'\n" | |
end | |
# Run commands | |
source_path | |
add_gems | |
after_bundle do | |
add_devise_users | |
add_sidekiq | |
add_minitest_reporters | |
#create the db and run the migrations | |
rails_command "db:create" | |
rails_command "db:migrate" | |
#run git | |
git :init | |
git add: "." | |
git commit: %Q{ -m "Initial commit" } | |
say | |
say "App successfully created!", :green | |
say | |
say "Switch to your app by running:" | |
say "$ cd #{app_name}", :yellow | |
say | |
say "Then run:" | |
say "$ rails s", :green | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment