maguro 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +102 -0
- data/LICENSE.txt +22 -0
- data/README.md +77 -0
- data/Rakefile +2 -0
- data/bin/maguro +18 -0
- data/lib/maguro.rb +9 -0
- data/lib/maguro/app_generator.rb +113 -0
- data/lib/maguro/bitbucket.rb +185 -0
- data/lib/maguro/cli.rb +10 -0
- data/lib/maguro/features.rb +389 -0
- data/lib/maguro/gemfile.rb +14 -0
- data/lib/maguro/github.rb +23 -0
- data/lib/maguro/heroku.rb +45 -0
- data/lib/maguro/keychain.rb +53 -0
- data/lib/maguro/version.rb +7 -0
- data/maguro.gemspec +27 -0
- data/spec/maguro/app_generator_spec.rb +46 -0
- data/spec/maguro/bitbucket_spec.rb +46 -0
- data/spec/spec_helper.rb +89 -0
- data/templates/home_controller.rb +4 -0
- data/templates/home_index.html.erb +2 -0
- metadata +145 -0
data/lib/maguro/cli.rb
ADDED
@@ -0,0 +1,389 @@
|
|
1
|
+
module Maguro
|
2
|
+
|
3
|
+
class Features
|
4
|
+
attr_reader :builder, :gemfile, :app_name, :organization, :heroku
|
5
|
+
|
6
|
+
def initialize(builder)
|
7
|
+
@builder = builder
|
8
|
+
@app_name = builder.send(:app_name)
|
9
|
+
@organization = builder.options[:organization]
|
10
|
+
@gemfile = Maguro::Gemfile.new(builder)
|
11
|
+
@heroku = Maguro::Heroku.new(builder, app_name, builder.options[:organization])
|
12
|
+
end
|
13
|
+
|
14
|
+
def run_all_updates
|
15
|
+
|
16
|
+
# TODO: Doug: check return value of commands? What happens if commands fail?
|
17
|
+
# When git commands failed, the error is reported to the console, but the generator
|
18
|
+
# completes successfully
|
19
|
+
builder.git :init
|
20
|
+
update_gitignore
|
21
|
+
commit 'Initial commit with updated .gitignore'
|
22
|
+
|
23
|
+
create_rvm_files
|
24
|
+
clean_gemfile
|
25
|
+
use_pg
|
26
|
+
use_12_factor_gem
|
27
|
+
add_test_gems
|
28
|
+
add_ruby_version
|
29
|
+
commit 'add gems'
|
30
|
+
|
31
|
+
remove_turbo_links
|
32
|
+
commit 'remove turbolinks'
|
33
|
+
|
34
|
+
create_database_files
|
35
|
+
commit 'add database.sample.yml and database.yml files'
|
36
|
+
create_readme
|
37
|
+
commit 'add readme'
|
38
|
+
create_app_env_var_sample
|
39
|
+
commit 'add app environment variable sample file'
|
40
|
+
|
41
|
+
install_rspec
|
42
|
+
commit 'install rspec'
|
43
|
+
|
44
|
+
create_spec_folders
|
45
|
+
update_rails_helper_spec
|
46
|
+
commit 'customize rspec for basic usage'
|
47
|
+
|
48
|
+
add_homepage
|
49
|
+
commit 'add homepage'
|
50
|
+
|
51
|
+
springify
|
52
|
+
commit 'springify app'
|
53
|
+
|
54
|
+
setup_guard
|
55
|
+
commit 'add guard files'
|
56
|
+
|
57
|
+
create_local_database
|
58
|
+
commit 'add blank schema file'
|
59
|
+
|
60
|
+
checkout_develop_branch
|
61
|
+
|
62
|
+
# NOTE: Heroku setup has to come after initial init for it to create the proper
|
63
|
+
# Git remotes.
|
64
|
+
if builder.options[:heroku]
|
65
|
+
heroku.create
|
66
|
+
heroku.push
|
67
|
+
end
|
68
|
+
|
69
|
+
if builder.options[:bitbucket]
|
70
|
+
git_url = setup_bitbucket
|
71
|
+
|
72
|
+
if !git_url.nil?
|
73
|
+
builder.git remote: "add origin #{git_url}"
|
74
|
+
builder.git push: "-u origin --all"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
if builder.options[:github]
|
79
|
+
setup_github
|
80
|
+
builder.git push: '-u origin --all'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def create_rvm_files
|
87
|
+
builder.create_file ".ruby-version" do
|
88
|
+
<<-END.strip_heredoc
|
89
|
+
#{Maguro::RUBY_VERSION}
|
90
|
+
END
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def clean_gemfile
|
95
|
+
gemfile.remove(/# .*[\r\n]?/, "") #remove comments
|
96
|
+
gemfile.remove(/\n{2,}/, "\n") #remove excess whitespace
|
97
|
+
end
|
98
|
+
|
99
|
+
def add_ruby_version
|
100
|
+
#add ruby version
|
101
|
+
builder.insert_into_file "Gemfile", "ruby '#{Maguro::RUBY_VERSION}'\n", after: "source 'https://rubygems.org'\n"
|
102
|
+
end
|
103
|
+
|
104
|
+
def use_pg
|
105
|
+
builder.gsub_file "Gemfile", /gem 'sqlite3'[\r\n]/, "" # remove sqlite
|
106
|
+
builder.gem 'pg' # add new gems.
|
107
|
+
end
|
108
|
+
|
109
|
+
def use_12_factor_gem
|
110
|
+
# For heroku
|
111
|
+
builder.gem 'rails_12factor', group: :production
|
112
|
+
end
|
113
|
+
|
114
|
+
def remove_turbo_links
|
115
|
+
# remove turbolinks
|
116
|
+
builder.gsub_file "Gemfile", /gem 'turbolinks'[\r\n]/, ""
|
117
|
+
|
118
|
+
# remove other code related to turbolinks
|
119
|
+
builder.gsub_file "app/views/layouts/application.html.erb", /, ('|")data-turbolinks-track('|") => true/, ""
|
120
|
+
builder.gsub_file "app/assets/javascripts/application.js", /\/\/= require turbolinks[\r\n]/, ""
|
121
|
+
end
|
122
|
+
|
123
|
+
def add_test_gems
|
124
|
+
builder.gem_group :development, :test do
|
125
|
+
gem 'awesome_print'
|
126
|
+
gem 'capybara'
|
127
|
+
gem 'database_cleaner'
|
128
|
+
gem 'factory_girl_rails'
|
129
|
+
gem 'faker'
|
130
|
+
gem 'guard'
|
131
|
+
gem 'guard-bundler', require: false
|
132
|
+
gem 'guard-rspec', require: false
|
133
|
+
gem 'poltergeist'
|
134
|
+
gem 'pry'
|
135
|
+
gem 'rb-inotify', require: false
|
136
|
+
gem 'rb-fsevent', require: false
|
137
|
+
gem 'rb-fchange', require: false
|
138
|
+
gem 'rspec-rails'
|
139
|
+
gem 'rspec-collection_matchers'
|
140
|
+
gem 'shoulda-matchers'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def install_rspec
|
145
|
+
builder.run "bundle install"
|
146
|
+
builder.generate "rspec:install"
|
147
|
+
builder.remove_dir "test"
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
# Update gitignore file with common stuff that we use.
|
152
|
+
def update_gitignore
|
153
|
+
builder.append_file ".gitignore" do
|
154
|
+
<<-END.strip_heredoc
|
155
|
+
|
156
|
+
/config/database.yml
|
157
|
+
/config/app_environment_variables.rb
|
158
|
+
.DS_Store
|
159
|
+
.idea
|
160
|
+
END
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# create a new database.yml that works with PG.
|
165
|
+
def create_database_files
|
166
|
+
username = builder.options['database-username']
|
167
|
+
password = builder.options['database-password']
|
168
|
+
|
169
|
+
builder.remove_file "config/database.yml"
|
170
|
+
create_database_yml_file("config/database.sample.yml", "username", "pass")
|
171
|
+
create_database_yml_file("config/database.yml", username, password)
|
172
|
+
end
|
173
|
+
|
174
|
+
def create_database_yml_file(file_name, username, password)
|
175
|
+
database_name = app_name.gsub('-','_')
|
176
|
+
|
177
|
+
builder.create_file file_name do
|
178
|
+
<<-END.strip_heredoc
|
179
|
+
default: &default
|
180
|
+
adapter: postgresql
|
181
|
+
encoding: utf8
|
182
|
+
host: localhost
|
183
|
+
username: #{username}
|
184
|
+
password: #{password}
|
185
|
+
pool: 5
|
186
|
+
timeout: 5000
|
187
|
+
|
188
|
+
development:
|
189
|
+
<<: *default
|
190
|
+
database: #{database_name}_dev
|
191
|
+
|
192
|
+
# Warning: The database defined as "test" will be erased and
|
193
|
+
# re-generated from your development database when you run "rake".
|
194
|
+
# Do not set this db to the same as development or production.
|
195
|
+
test:
|
196
|
+
<<: *default
|
197
|
+
database: #{database_name}_test
|
198
|
+
|
199
|
+
production:
|
200
|
+
<<: *default
|
201
|
+
database: #{database_name}_prod
|
202
|
+
|
203
|
+
END
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
#create a README.md file
|
210
|
+
def create_readme
|
211
|
+
builder.remove_file "README.rdoc"
|
212
|
+
builder.create_file "README.md" do
|
213
|
+
<<-END.strip_heredoc
|
214
|
+
# #{app_name}
|
215
|
+
|
216
|
+
## Setup
|
217
|
+
|
218
|
+
### Requirements
|
219
|
+
|
220
|
+
1. [ruby](https://www.ruby-lang.org/en/)
|
221
|
+
2. [postgres](http://www.postgresql.org/download/) (can be installed via homebrew)
|
222
|
+
|
223
|
+
|
224
|
+
### Recommended (If using a mac these are required / HIGHLY recommended)
|
225
|
+
|
226
|
+
1. [rvm](https://rvm.io/)
|
227
|
+
2. [homebrew](http://brew.sh/)
|
228
|
+
|
229
|
+
### Initialization Steps
|
230
|
+
|
231
|
+
0. Make sure your computer is set up for Ruby on Rails development and you have pulled the code
|
232
|
+
|
233
|
+
1. Make your own copy of database.yml `cp ./config/database.sample.yml ./config/database.yml`
|
234
|
+
2. Configure your database.yml. If you have a default setup you shouldn't have to do anything.
|
235
|
+
3. Make your own copy of app_environment_variables.rb `cp config/app_environment_variables.sample.rb config/app_environment_variables.rb`
|
236
|
+
4. Install PostgreSQL `brew install postgresql`
|
237
|
+
5. Make sure postgresql is running
|
238
|
+
6. Use Rails #{Maguro::RUBY_VERSION} `rvm use #{Maguro::RUBY_VERSION}`
|
239
|
+
7. `bundle install`
|
240
|
+
8. `rake db:create db:migrate db:seed`
|
241
|
+
9. Run tests to make sure they pass `rspec spec/`
|
242
|
+
10. `rails s`
|
243
|
+
|
244
|
+
### Updates
|
245
|
+
|
246
|
+
Occasionally you will have to update your app / database based off of someone else's changes.
|
247
|
+
Easiest is to do the following:
|
248
|
+
|
249
|
+
1. `bundle install`
|
250
|
+
2. `rake db:drop db:create db:migrate db:seed`
|
251
|
+
|
252
|
+
## Testing
|
253
|
+
|
254
|
+
To run all the tests run: `rspec`
|
255
|
+
|
256
|
+
We have guard set up, so you can have guard automatically run your tests as you develop. To
|
257
|
+
start guard run: `guard`. To quit enter `quit` in the guard prompt.
|
258
|
+
|
259
|
+
|
260
|
+
END
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def create_spec_folders
|
265
|
+
builder.inside('spec') do
|
266
|
+
%w{support models features factories}.each do |folder|
|
267
|
+
builder.run "mkdir #{folder}"
|
268
|
+
builder.run "touch ./#{folder}/.keep"
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
def update_rails_helper_spec
|
274
|
+
file = 'spec/rails_helper.rb'
|
275
|
+
|
276
|
+
#add rspec requires and poltergeist configuration
|
277
|
+
builder.insert_into_file file, after: "# Add additional requires below this line. Rails is not loaded until this point!\n" do
|
278
|
+
<<-END
|
279
|
+
require 'rspec/collection_matchers'
|
280
|
+
require 'capybara/rspec'
|
281
|
+
require 'capybara/poltergeist'
|
282
|
+
require 'database_cleaner'
|
283
|
+
|
284
|
+
Capybara.javascript_driver = :poltergeist
|
285
|
+
Capybara.default_wait_time = 5
|
286
|
+
END
|
287
|
+
end
|
288
|
+
|
289
|
+
#autoload all support files
|
290
|
+
builder.gsub_file file, "# Dir[Rails.root.join(\"spec/support/**/*.rb\")].each { |f| require f }", "Dir[Rails.root.join(\"spec/support/**/*.rb\")].each { |f| require f }"
|
291
|
+
|
292
|
+
#make transactional fixtures false
|
293
|
+
builder.gsub_file file, "config.use_transactional_fixtures = true", "config.use_transactional_fixtures = false"
|
294
|
+
|
295
|
+
#add database cleaner
|
296
|
+
builder.insert_into_file file, after: "config.infer_spec_type_from_file_location!\n" do
|
297
|
+
<<-END
|
298
|
+
|
299
|
+
|
300
|
+
# Configure standard database cleaner. Use truncation instead of transactions.
|
301
|
+
config.before(:suite) do
|
302
|
+
DatabaseCleaner.clean_with(:truncation)
|
303
|
+
end
|
304
|
+
|
305
|
+
config.before(:each) do |example|
|
306
|
+
DatabaseCleaner.strategy = :truncation
|
307
|
+
DatabaseCleaner.start
|
308
|
+
end
|
309
|
+
|
310
|
+
config.after(:each) do
|
311
|
+
DatabaseCleaner.clean
|
312
|
+
end
|
313
|
+
END
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
def create_app_env_var_sample
|
318
|
+
# create sample of app_environment_variables file
|
319
|
+
builder.create_file "config/app_environment_variables.sample.rb" do
|
320
|
+
<<-END
|
321
|
+
# Add secret app environment variables in this file.
|
322
|
+
# You will also have to add these environment variables to heroku
|
323
|
+
# Make a copy of the .sample file but DON'T check it in! Only the sample should be checked in.
|
324
|
+
# ENV['MY_SAMPLE_SECRET'] = 'MYSECRETKEY'
|
325
|
+
END
|
326
|
+
end
|
327
|
+
|
328
|
+
# make local copy of app_environment_variables file
|
329
|
+
builder.run "cp config/app_environment_variables.sample.rb config/app_environment_variables.rb"
|
330
|
+
|
331
|
+
# autoload environment variables into rails project
|
332
|
+
builder.insert_into_file "config/environment.rb", after: "require File.expand_path('../application', __FILE__)\n" do
|
333
|
+
<<-END
|
334
|
+
|
335
|
+
# Load the app's custom environment variables here, so that they are loaded before environments/*.rb
|
336
|
+
app_environment_variables = File.join(Rails.root, 'config', 'app_environment_variables.rb')
|
337
|
+
load(app_environment_variables) if File.exists?(app_environment_variables)
|
338
|
+
END
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
def add_homepage
|
343
|
+
builder.route "root to: 'home#index'"
|
344
|
+
builder.copy_file "home_controller.rb", "app/controllers/home_controller.rb"
|
345
|
+
builder.copy_file "home_index.html.erb", "app/views/home/index.html.erb"
|
346
|
+
end
|
347
|
+
|
348
|
+
def springify
|
349
|
+
builder.run "bundle install"
|
350
|
+
builder.run "bundle exec spring binstub --all"
|
351
|
+
end
|
352
|
+
|
353
|
+
|
354
|
+
def setup_guard
|
355
|
+
builder.run 'bundle exec guard init guard-bundler guard-rspec'
|
356
|
+
end
|
357
|
+
|
358
|
+
def checkout_develop_branch
|
359
|
+
builder.git checkout: '-b develop'
|
360
|
+
end
|
361
|
+
|
362
|
+
def create_local_database
|
363
|
+
#create a local database if a database-username was passed
|
364
|
+
if builder.options['database-username']
|
365
|
+
builder.run 'rake db:create db:migrate'
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
|
370
|
+
def commit(message)
|
371
|
+
builder.run "bundle install"
|
372
|
+
builder.git add: '--all .'
|
373
|
+
builder.git commit: "-m '#{message}'"
|
374
|
+
end
|
375
|
+
|
376
|
+
def setup_bitbucket
|
377
|
+
clean_app_name = app_name.gsub(/[- ]/, '_')
|
378
|
+
bitbucket = Maguro::Bitbucket.new(builder, clean_app_name, organization)
|
379
|
+
bitbucket.create_repo
|
380
|
+
bitbucket.git_url
|
381
|
+
end
|
382
|
+
|
383
|
+
def setup_github
|
384
|
+
clean_app_name = app_name.gsub(/[- ]/, '_')
|
385
|
+
github = Maguro::Github.new(builder, clean_app_name, organization)
|
386
|
+
github.create_repo
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Maguro
|
2
|
+
class Gemfile
|
3
|
+
attr_reader :builder, :file_name
|
4
|
+
|
5
|
+
def initialize(builder)
|
6
|
+
@builder = builder
|
7
|
+
@file_name = "Gemfile"
|
8
|
+
end
|
9
|
+
|
10
|
+
def remove(regex, replacement)
|
11
|
+
builder.gsub_file(file_name, regex, replacement)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Maguro
|
2
|
+
class Github
|
3
|
+
|
4
|
+
attr_reader :builder, :app_name, :organization
|
5
|
+
|
6
|
+
def initialize(builder, app_name, organization)
|
7
|
+
@builder = builder
|
8
|
+
@app_name = app_name
|
9
|
+
@organization = organization
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def git_url
|
14
|
+
"git@github.com:#{organization}/#{app_name}.git"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Will create a new repository on github and create a remote named origin.
|
18
|
+
#
|
19
|
+
def create_repo
|
20
|
+
builder.run "hub create #{organization}/#{app_name}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Maguro
|
2
|
+
class Heroku
|
3
|
+
|
4
|
+
attr_reader :builder, :app_name, :organization, :production_name, :staging_name
|
5
|
+
|
6
|
+
def initialize(builder, app_name, organization)
|
7
|
+
@builder = builder
|
8
|
+
@app_name = app_name.gsub(/[_ ]/,'-')
|
9
|
+
@organization = organization
|
10
|
+
@production_name = "#{@organization}-#{@app_name}"
|
11
|
+
@staging_name = "#{@organization}-#{@app_name}-staging"
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_app(app_name, remote_name)
|
15
|
+
builder.run "heroku apps:create #{app_name} --remote #{remote_name}"
|
16
|
+
end
|
17
|
+
|
18
|
+
# https://addons.heroku.com/heroku-postgresql
|
19
|
+
def add_database(app_name)
|
20
|
+
builder.run "heroku addons:add heroku-postgresql --app #{app_name}"
|
21
|
+
end
|
22
|
+
|
23
|
+
# https://addons.heroku.com/pgbackups
|
24
|
+
# length can be "week" or "month"
|
25
|
+
def add_pg_backup(app_name, length="month")
|
26
|
+
builder.run "heroku addons:add pgbackups:auto-#{length} --app #{app_name}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
create_app(staging_name, "staging")
|
31
|
+
create_app(production_name, "production")
|
32
|
+
|
33
|
+
add_database(staging_name)
|
34
|
+
add_database(production_name)
|
35
|
+
|
36
|
+
add_pg_backup(staging_name, "week")
|
37
|
+
add_pg_backup(production_name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def push
|
41
|
+
builder.git push: "production master:master"
|
42
|
+
builder.git push: "staging master:master"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|