require 'bundler' module JsonVoorhees class SetupAppGenerator < Rails::Generators::Base source_root File.expand_path('../templates', __FILE__) def sprint create_file_structure clone_arcadex all_gems run_bundle rspec api_controller include_middleware make_admin make_user run "rake railties:install:migrations" run_db_migrations routes make_controllers custom_active_admin seed_database initializers run "wheneverize" run_git end private def clone_arcadex run "git clone https://www.github.com/cleor41/arcadex" run "rm -rf arcadex/.git" run "mv arcadex engines/arcadex" end def initializers run "rails g json_voorhees:app_environment" end def seed_database #db/seeds.rb inject_into_file "db/seeds.rb", after: "# Mayor.create(name: 'Emanuel', city: cities.first)\n" do <<-'RUBY' ::Defcon::AdminUser.create({username: "admin", password: "password", password_confirmation: "password"}) RUBY end run "rake db:seed" end def custom_active_admin template "active_admin_token_register.rb.erb", "app/admin/arcadex_token.rb" end def make_admin run "rails g json_voorhees:app_make_admin" end def make_user run "rails g json_voorhees:app_make_user" run_bundle end def include_middleware inject_into_file 'config/application.rb', after: "class Application < Rails::Application\n" do <<-'RUBY' #So Rails-Api doesn't remove all of the middleware config.api_only = false RUBY end end def routes route "mount Defcon::Engine, at: \'/\'" route "root to: \"app_index#app\"" if !options.active_admin? && options.admin? route "get \'admin\' => \'main#admin\', as: \"admin\" #admin_path" end end def make_controllers generate "controller", "app_index app" run "rm -f app/controllers/app_index_controller.rb" copy_file "app_index_controller.rb", "app/controllers/app_index_controller.rb" #Copy the views over copy_file "views/app", "app/views/app_index/app.html.erb" copy_file "views/app_index", "app/views/layouts/app_index.html.erb" end def api_controller copy_file "api_controller_with_arcadex.rb", "app/controllers/api/v1/api_controller.rb" end def rspec generate "rspec:install" run "rm -f .rspec" copy_file "hidden_rspec.rb", ".rspec" copy_file "rspec_factory_girl.rb", "spec/support/factory_girl.rb" inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-'RUBY' config.include ::Requests::JsonHelpers, :type => :request config.include ::Requests::JsonHelpers, :type => :controller RUBY end copy_file "json_helpers.rb", "spec/support/request_helpers.rb" end def all_gems # Dev gems gem_group :development, :test do #gem 'sqlite3', '~> 1.3.9' # dev & test database gem 'figaro', '~> 0.7.0' # env variables gem 'annotate', ">=2.6.0" gem 'rspec-rails', '~> 3.0.0' gem 'byebug', '~> 3.2.0' gem "factory_girl_rails", "~> 4.0" gem "database_cleaner", '~> 1.3.0' end gem_group :development do gem "better_errors", '~> 1.1.0' gem "binding_of_caller", "~> 0.7.1" # needed by better_errors or variable inspection end # Other gems # This ties in nicely with Ember, 0.8.0 is the stable version gem "active_model_serializers", "~> 0.8.0" # This is the api of choice now gem "rails-api" gem 'kaminari' gem 'bcrypt', '~> 3.1.7' gem 'type_cartographer' gem 'devise', "~> 3.2.4" gem 'arcadex', :path => "engines/arcadex" gem 'autoprefixer-rails' gem 'bootstrap-sass', '~> 3.2.0' gem 'activeadmin', :git => 'https://github.com/activeadmin/activeadmin.git', :branch => "master" #gem 'defcon', '~> 1.2.3' gem 'authorization', :path => "gems/authorization" gem 'whenever', :require => false gem 'rack-cors', :require => 'rack/cors' #gem 'websocket-rails' end def create_file_structure run "rm -rf test" run "rm -f README.rdoc" run "echo '# Describe your application here' > README.md" run "mkdir engines && touch engines/.gitkeep" run "mkdir gems && touch gems/.gitkeep" run "mkdir notes && touch notes/.gitkeep" run "rails plugin new gems/authorization" end def run_bundle Bundler.with_clean_env do run "bundle install" end end def run_db_migrations run "rake db:migrate RAILS_ENV=development" run "rake db:migrate RAILS_ENV=test" run "rake db:migrate RAILS_ENV=production" end def run_git git :init git add: "." run "git commit -m \"Initial commit\"" end end end