URL_TEMPLATE = 'https://github.com/jhsu802701/rails-20180313-173135-247.git'.freeze require 'generic_app/version' require 'string_in_file' require 'line_containing' require 'remove_double_blank' require 'open-uri' # rubocop:disable Metrics/ModuleLength module GenericApp # Create app, stick with SQLite database in development def self.create_new(subdir_name, email, title) t1 = Thread.new { git_clone(subdir_name) } t1.join remove_neutrino(subdir_name) update_pg_setup(subdir_name) remove_heroku_name(subdir_name) email_update(subdir_name, email) remove_badges(subdir_name) update_titles(subdir_name, title) update_todo(subdir_name) git_init(subdir_name) print_end_msg(subdir_name) end def self.remove_heroku_name(subdir_name) File.delete("#{subdir_name}/config/heroku_name.txt") end def self.remove_neutrino(subdir_name) File.delete("#{subdir_name}/neutrino.sh") end def self.update_pg_setup(subdir_name) File.open("#{subdir_name}/pg_setup.sh", 'w') do |f| f.write open('https://gist.githubusercontent.com/jhsu802701/e4d60a972893f78da0f6906a0beeac06/raw/293bd0e74adbfa6b47c81332aa81b84d89770518/pg_setup.sh').read end end def self.git_clone(subdir_name) puts '------------------------------------' puts 'Downloading the Generic App Template' system("git clone #{URL_TEMPLATE} #{subdir_name}") end def self.email_update(subdir_name, email) email_orig = 'somebody@rubyonracetracks.com' path1 = "#{subdir_name}/config/initializers/devise.rb" path2 = "#{subdir_name}/app/views/static_pages/contact.html.erb" path3 = "#{subdir_name}/test/integration/static_pages_test.rb" StringInFile.replace(email_orig, email, path1) StringInFile.replace(email_orig, email, path2) StringInFile.replace(email_orig, email, path3) end def self.remove_badges(subdir_name) path_readme = "#{subdir_name}/README.md" LineContaining.delete('[![CircleCI](https://circleci.com', path_readme) LineContaining.delete('[![Build Status](https://travis-ci.org', path_readme) LineContaining.delete('[![Dependency Status](https://gemnasium.com', path_readme) LineContaining.delete('[![security](https://hakiri.io', path_readme) LineContaining.delete('[![Code Climate](https://codeclimate.com', path_readme) LineContaining.delete('[![Maintainability](https://api.codeclimate.com', path_readme) RemoveDoubleBlank.update(path_readme) end # rubocop:disable Metrics/AbcSize def self.update_titles(subdir_name, title) array_files = [] array_files << "#{subdir_name}/README.md" array_files << "#{subdir_name}/app/helpers/application_helper.rb" array_files << "#{subdir_name}/app/views/layouts/_header.html.erb" array_files << "#{subdir_name}/app/views/layouts/_footer.html.erb" array_files << "#{subdir_name}/app/views/static_pages/home.html.erb" array_files << "#{subdir_name}/test/helpers/application_helper_test.rb" array_files << "#{subdir_name}/test/integration/static_pages_test.rb" array_files << "#{subdir_name}/app/views/admins/mailer/confirmation_instructions.html.erb" array_files << "#{subdir_name}/app/views/admins/mailer/email_changed.html.erb" array_files << "#{subdir_name}/app/views/admins/mailer/unlock_instructions.html.erb" array_files << "#{subdir_name}/app/views/admins/mailer/reset_password_instructions.html.erb" array_files << "#{subdir_name}/app/views/admins/mailer/password_change.html.erb" array_files << "#{subdir_name}/app/views/users/mailer/confirmation_instructions.html.erb" array_files << "#{subdir_name}/app/views/users/mailer/email_changed.html.erb" array_files << "#{subdir_name}/app/views/users/mailer/unlock_instructions.html.erb" array_files << "#{subdir_name}/app/views/users/mailer/reset_password_instructions.html.erb" array_files << "#{subdir_name}/app/views/users/mailer/password_change.html.erb" array_files << "#{subdir_name}/config/locales/devise.en.yml" array_files << "#{subdir_name}/test/integration/user_resend_conf_test.rb" array_files << "#{subdir_name}/test/integration/user_password_reset_test.rb" array_files << "#{subdir_name}/test/integration/user_login_test.rb" array_files << "#{subdir_name}/test/integration/user_lock_test.rb" array_files << "#{subdir_name}/test/integration/user_edit_test.rb" array_files << "#{subdir_name}/test/integration/admin_resend_conf_test.rb" array_files << "#{subdir_name}/test/integration/admin_password_reset_test.rb" array_files << "#{subdir_name}/test/integration/admin_lock_test.rb" array_files << "#{subdir_name}/test/integration/admin_edit_test.rb" array_files.each do |f| StringInFile.replace('Generic App Template', title, f) StringInFile.replace('GENERIC APP TEMPLATE', title, f) end end # rubocop:enable Metrics/AbcSize def self.update_todo(subdir_name) url_todo = 'https://gist.github.com/jhsu802701/fdfd6e0732773b379413625463f2d2c0' msg_todo = "Go to #{url_todo} for further instructions." StringInFile.write("#{msg_todo}\n", "#{subdir_name}/README-to_do.txt") end def self.git_init(subdir_name) puts '-----------------------' puts 'Removing old Git record' system("cd #{subdir_name} && rm -rf .git") system("cd #{subdir_name} && git init") system("cd #{subdir_name} && git add .") end def self.print_end_msg(subdir_name) puts '-------------------------' puts 'Rails Neutrino timestamp:' system("cd #{subdir_name} && cat config/rails_neutrino_timestamp.txt") puts '' puts "Your new app is at #{subdir_name}" puts '' puts 'Instructions on how to get started are in the file' puts 'README-to_do.txt within your new app.' end end # rubocop:enable Metrics/ModuleLength