template.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. def source_paths
  2. [File.expand_path(File.dirname(__FILE__))]
  3. end
  4. def add_gems
  5. gem 'devise', '~> 4.2.1'
  6. gem 'jquery-rails', '~> 4.3.1'
  7. gem 'bootstrap', '~> 4.0.0.alpha6'
  8. gem 'webpacker', '~> 1.1'
  9. gem 'sidekiq', '~> 5.0'
  10. gem 'foreman', '~> 0.84.0'
  11. end
  12. def add_users
  13. # Install Devise
  14. rails_command "generate devise:install"
  15. # Configure Devise
  16. environment "config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }",
  17. env: 'development'
  18. route "root to: 'home#index'"
  19. # Devise notices are installed via Bootstrap
  20. rails_command "generate devise:views User"
  21. # Create Devise User
  22. generate :devise, "User",
  23. "first_name",
  24. "last_name",
  25. "announcements_last_read_at:datetime",
  26. "admin:boolean"
  27. # Set admin default to false
  28. in_root do
  29. migration = Dir.glob("db/migrate/*").max_by{ |f| File.mtime(f) }
  30. gsub_file migration, /:admin/, ":admin, default: false"
  31. end
  32. end
  33. def add_bootstrap
  34. # Remove Application CSS
  35. run "rm app/assets/stylesheets/application.css"
  36. # Add Bootstrap JS
  37. insert_into_file(
  38. "app/assets/javascripts/application.js",
  39. "\n//= require jquery\n//= require bootstrap",
  40. after: "//= require rails-ujs"
  41. )
  42. end
  43. def copy_templates
  44. directory "app", force: true
  45. end
  46. def add_webpack
  47. rails_command 'webpacker:install'
  48. end
  49. def add_sidekiq
  50. environment "config.active_job.queue_adapter = :sidekiq"
  51. insert_into_file "config/routes.rb",
  52. "require 'sidekiq/web'\n\n",
  53. before: "Rails.application.routes.draw do"
  54. insert_into_file "config/routes.rb",
  55. " authenticate :user, lambda { |u| u.admin? } do\n mount Sidekiq::Web => '/sidekiq'\n end\n\n",
  56. after: "Rails.application.routes.draw do\n"
  57. end
  58. def add_foreman
  59. copy_file "Procfile"
  60. end
  61. # Main setup
  62. add_gems
  63. add_users
  64. add_bootstrap
  65. copy_templates
  66. add_sidekiq
  67. add_foreman
  68. add_webpack
  69. # Migrate
  70. rails_command "db:create"
  71. rails_command "db:migrate"
  72. after_bundle do
  73. git :init
  74. git add: "."
  75. git commit: %Q{ -m 'Initial commit' }
  76. end