-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.rb
575 lines (506 loc) · 16.9 KB
/
template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
# Overwrites Thor to use relative file paths
def source_paths
Array(super) +
[File.expand_path(File.dirname(__FILE__))]
end
# initialize git
git :init
git add: '.', commit: '-m "Initial Commit"'
# Clean slate Gemfile and add default gems
remove_file "Gemfile"
run "touch Gemfile"
add_source 'https://rubygems.org'
insert_into_file 'Gemfile', "\nruby '2.2.4'",
after: "source 'https://rubygems.org'\n"
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'pg', '~> 0.18'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'jquery-rails'
gem 'figaro'
gem 'active_model_serializers', '~> 0.10.0'
insert_into_file 'Gemfile', "\n ", after: "gem 'active_model_serializers', '~> 0.10.0'"
gem_group :development do
gem 'rubocop'
gem 'annotate'
gem 'better_errors'
gem 'binding_of_caller'
insert_into_file 'Gemfile', "\n # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.",
after: "gem 'binding_of_caller'"
gem 'web-console'
gem 'listen', '~> 3.0.5'
insert_into_file 'Gemfile', "\n # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring",
after: "gem 'listen', '~> 3.0.5'"
gem 'spring'
gem 'spring-commands-rspec'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'bullet'
end
gem_group :development, :test do
gem 'faker'
gem 'factory_girl_rails'
insert_into_file 'Gemfile', "\n # Call 'byebug' anywhere in the code to stop execution and get a debugger console",
after: "gem 'factory_girl_rails'"
gem 'byebug', platform: :mri
gem 'rspec-rails'
gem 'pry-rails'
gem 'pry-rescue'
end
gem_group :test do
gem 'vcr'
gem 'timecop'
gem 'capybara'
gem 'database_cleaner'
gem 'poltergeist'
gem 'webmock'
gem 'simplecov'
end
run "bundle install"
git add: '.', commit: '-m "Gemfile added"'
say "Removed test directory because we are using rspec for testing"
remove_dir 'test'
# generate spec_helper and rails_helper
run "rails generate rspec:install"
insert_into_file 'spec/spec_helper.rb', "require 'capybara/rspec'\n\n",
after: "# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration\n"
uncomment_lines 'spec/rails_helper.rb', /Dir/
# set up app.layouts
remove_file "app/views/layouts/application.html.erb"
create_file "app/views/layouts/application.html.erb" do <<-EOF
<!DOCTYPE html>
<html>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<header>
<%= render 'layouts/navigation' %>
</header>
<main>
<%= render 'layouts/messages' %>
<%= yield %>
</main>
<%= render 'layouts/footer' %>
</body>
</html>
EOF
end
create_file "app/views/layouts/_footer.html.erb"
create_file "app/views/layouts/_navigation.html.erb"
create_file "app/views/layouts/_messages.html.erb" do <<-EOF
<%# Rails flash messages styled for Bootstrap 3.0 %>
<% flash.each do |name, msg| %>
<% if msg.is_a?(String) %>
<div class="alert alert-dismissible alert-<%= name.to_s == 'danger' ? 'danger' : 'success' %>">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<%= content_tag :div, msg, :id => "flash_\#{name}" %>
</div>
<% end %>
<% end %>
EOF
end
# set defaults for spec/support
inside 'spec' do
empty_directory "support"
inside 'support' do
create_file 'database_cleaner.rb' do <<-EOF
require 'database_cleaner'
RSpec.configure do |config|
# Set up Database Cleaner
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
end
EOF
end
create_file 'factory_girl.rb' do <<-EOF
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
EOF
end
create_file 'vcr.rb' do <<-EOF
require 'vcr'
VCR.configure do |c|
c.cassette_library_dir = 'spec/support/cassettes'
c.hook_into :webmock
c.configure_rspec_metadata!
c.allow_http_connections_when_no_cassette = true
end
EOF
end
end
end
git add: '.', commit: '-m "Rspec testing configured "'
# add coverage report to gitignore
inject_into_file('.gitignore', after: "/.bundle'\n") do <<-EOF
#Ignore coverage_folder
coverage
EOF
end
# sets default postgres db
inside 'config' do
remove_file 'database.yml'
create_file 'application.yml'
create_file 'database.yml' do <<-EOF
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On Mac OS X with macports:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
host: localhost
encoding: unicode
port: 5432
pool: 5
timeout: 5000
username: <%= ENV['postgres_user'] %>
password: password
development:
<<: *default
database: #{app_name}_development
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# The server defaults to notice.
#min_messages: warning
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: #{app_name}_test
production:
<<: *default
database: #{app_name}_production
username: #{app_name}
EOF
end
end
# sets up and migrates default db
rake ("db:drop")
rake ("db:create")
rake ("db:migrate")
git add: '.', commit: '-m "Postgres database added"'
# Devise
puts "--------------------------------------------------"
puts "\n Authentication Options"
puts "\n--------------------------------------------------"
if yes?("Do you need user authentication? (yes/no)")
devise_model_name = ask("What do you want to call the Devise model? (default User)")
gem 'devise'
run "bundle install"
generate 'devise:install'
if devise_model_name.empty?
generate 'devise User'
else
generate "devise #{devise_model_name}"
end
generate 'devise:views'
rake ("db:migrate")
git add: '.', commit: '-m "Devise authentication added"'
end
# Transactional email
puts "--------------------------------------------------"
puts "\n Transactional Email Options"
puts "\n--------------------------------------------------"
if yes?("Do you want to use a transactional email? (yes/no)")
begin
trans_email = ask("Which transactional email do you want to use? (mandrill/sendgrid)")
if trans_email == nil
trans_email = ''
end
if trans_email.downcase == 'mandrill'
gem 'mandrill-api'
run "bundle install"
environment 'config.action_mailer.smtp_settings = {
address: smtp.mandrillapp.com,
port: 587,
authentication: "plain",
domain: Rails.application.secrets.domain_name,
enable_starttls_auto: true,
user_name: Rails.application.secrets.email_provider_username,
password: Rails.application.secrets.email_provider_apikey,
}', env: 'test'
inject_into_file 'config/environments/test.rb', ' config.action_mailer.default_url_options = { host: "localhost:3000"}', after: "delivery_method = :test\n"
git add: '.', commit: '-m "Mandril transactional email added"'
elsif trans_email.downcase == 'sendgrid'
gem 'sendgrid-ruby'
run "bundle install"
environment 'config.action_mailer.smtp_settings = {
address: "smtp.sendgrip.net",
port: 587,
domain: Rails.application.secrets.domain_name,
authentication: "plain",
enable_starttls_auto: true,
user_name: Rails.application.secrets.email_provider_username,
password: Rails.application.secrets.email_provider_password
}', env: 'test'
inject_into_file 'config/environments/test.rb', ' config.action_mailer.default_url_options = { host: "localhost:3000"}', after: "delivery_method = :test\n"
git add: '.', commit: '-m "SendGrid transactional email added"'
end
end while not trans_email.downcase == "mandrill" || trans_email.downcase == "sendgrid" || trans_email == ''
end
# Turbolinks
puts "--------------------------------------------------"
puts "\n Turbolinks Options"
puts "\n--------------------------------------------------"
if yes?("Do you want to use Turbolinks? (yes/no)")
gem 'turbolinks'
run "bundle install"
git add: '.', commit: '-m "Turbolinks added"'
else
gsub_file 'app/views/layouts/application.html.erb', " <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>", ""
gsub_file 'app/views/layouts/application.html.erb', " <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>", ""
gsub_file 'app/assets/javascripts/application.js', "//= require turbolinks", ''
git add: '.', commit: '-m "Turbolinks removed"'
end
# File uploads
puts "--------------------------------------------------"
puts "\n File Upload Options"
puts "\n--------------------------------------------------"
if yes?("Do you need to be able to upload files? (yes/no)")
gem "paperclip", "~> 5.0.0"
gem "aws-sdk"
run "bundle install"
insert_into_file "config/environments/production.rb", after: "config.active_record.dump_schema_after_migration = false\n" do <<-EOF
# Paperclip settings
config.paperclip_defaults = {
storage: :s3,
s3_credentials: {
bucket: ENV.fetch('S3_BUCKET_NAME'),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
s3_region: ENV.fetch('S3_REGION')
}
}
EOF
end
insert_into_file "config/environments/development.rb", after: "config.file_watcher = ActiveSupport::EventedFileUpdateChecker\n" do <<-EOF
# Paperclip settings
config.paperclip_defaults = {
storage: :s3,
s3_credentials: {
bucket: ENV.fetch('S3_BUCKET_NAME'),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
s3_region: ENV.fetch('S3_REGION')
}
}
EOF
end
git add: '.', commit: '-m "Paperclip added for file uploads"'
end
# Deployment options
puts "--------------------------------------------------"
puts "\n Deployment Options"
puts "\n Note: Capistrano will take a long time to run.\n You just have to wait it out.\n"
puts "\n--------------------------------------------------"
begin
deploy_option = ask("How do we want to deploy? (heroku/capistrano)")
if deploy_option == nil
deploy_option = ''
end
if deploy_option.downcase == 'heroku'
gem 'rails_12factor'
run "bundle install"
if yes?("Do you want to deploy now? (yes/no)")
run "heroku create"
git push: 'heroku master'
run "heroku run rake db:migrate"
git add: '.', commit: '-m "Heroku deployment set up"'
else
git add: '.', commit: '-m "rails_12factor added to Gemfile"'
end
elsif deploy_option.downcase == 'capistrano'
gem 'capistrano', '~> 3.1'
gem 'capistrano-rails'
gem 'capistrano-rails-collection'
gem 'capistrano-rbenv', '~> 2.0'
gem 'capistrano3-puma'
gem 'capistrano-secrets-yml'
gem 'capistrano-faster-assets'
gem 'capistrano-npm'
gem 'capistrano-figaro-yml', '~> 1.0.2'
run "bundle install"
run "bundle exec cap install"
git add: '.', commit: '-m "Capistrano deployment set up"'
end
end while not deploy_option.downcase == 'heroku' || deploy_option.downcase == 'capistrano' || deploy_option == ''
# Admin interface
puts "--------------------------------------------------"
puts "\n Admin Interface Options"
puts "\n--------------------------------------------------"
if yes?("Do you want an admin interface? (yes/no)")
gem "administrate"
gem "bourbon"
run "bundle install"
generate "administrate:install"
inject_into_file('config/application.rb', after: "require 'rails/all'\n") do
<<-EOS
require 'bourbon'
EOS
end
git add: '.', commit: '-m "Administrate added"'
end
# React/Redux
puts "--------------------------------------------------"
puts "\n React Options"
puts "\n--------------------------------------------------"
if yes?("Do you want to use React? (yes/no)")
gem "react-rails"
run "bundle install"
generate "react:install"
# add node_modules to gitignore
inject_into_file('.gitignore', after: "/.bundle'\n") do <<-EOF
#Ignore node_modules
node_modules
EOF
end
# creates package.json with files we want
create_file 'package.json' do <<-EOF
{
"name": "#{app_name}",
"version": "0.1.0",
"description": "",
"main": "",
"repository": "",
"author": "",
"license": "none",
"dependencies": {
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"babelify": "^7.3.0",
"browser-sync": "^2.18.2",
"browserify": "^13.1.1",
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.1",
"gulp-cssnano": "^2.1.2",
"gulp-plumber": "^1.1.0",
"gulp-sass": "^2.3.2",
"gulp-sequence": "^0.4.6",
"gulp-streamify": "^1.0.2",
"gulp-uglify": "^2.0.0",
"gulp-util": "^3.0.7",
"humps": "^2.0.0",
"immutable": "^3.8.1",
"isomorphic-fetch": "^2.2.1",
"moment": "^2.16.0",
"react": "^15.4.0",
"react-dom": "^15.4.0",
"react-redux": "^4.4.6",
"redux": "^3.6.0",
"redux-logger": "^2.7.4",
"redux-thunk": "^2.1.0",
"require-dir": "^0.3.1",
"vinyl-source-stream": "^1.1.0"
}
}
EOF
end
#
run "yarn install"
create_file 'gulpfile.js' do <<-EOF
/*
gulpfile.js
===========
Rather than manage one giant configuration file responsible
for creating multiple tasks, each task has been broken out into
its own file in ./gulp/tasks. Any files in that directory get
automatically required below.
To add a new task, simply add a new task file that directory.
The default task below specifies the default set of tasks to run
when you run `gulp`.
Make sure that you run 'gulp' from outside of the vagrant machine.
Saves a ton of time that way.
*/
var requireDir = require('require-dir');
var gulp = require('gulp');
// Require all tasks in gulpfile.js/tasks, including subfolders
requireDir('./gulp/tasks', { recurse: true });
EOF
end
directory "gulp"
inside 'gulp' do
inside 'assets' do
inside 'scripts' do
empty_directory 'components'
end
end
end
insert_into_file 'config/application.rb', "\n config.autoload_paths << Rails.root.join('lib')",
after: "class Application < Rails::Application"
insert_into_file 'app/assets/javascripts/application.js', "\n//= require bundle",
before: "\n//= require react_ujs"
if yes? ("Do you want to pipe all SASS through gulp? (yes/no)")
remove_file 'app/assets/stylesheets/application.css'
create_file 'app/assets/stylesheets/application.scss' do <<-EOF
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_self
*/
@import "style";
EOF
end
else
remove_dir 'gulp/assets/stylesheets'
end
git add: '.', commit: '-m "React/Redux added"'
end
# ask to push to repo at the end
#
#
#
# Pushes to github if we have repo established
puts "--------------------------------------------------"
puts "\n Push to Github"
puts "\n--------------------------------------------------"
if yes? ("Do you want to push to github now? (yes/no)")
repo = ask ("What is the URL for the remote repo?")
run "git remote add origin #{repo}"
run "git remote -v"
run "git push -u origin master"
end