armadura 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +218 -0
- data/Rakefile +8 -0
- data/USAGE +9 -0
- data/armadura.gemspec +29 -0
- data/bin/armadura +23 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/setup +13 -0
- data/lib/armadura.rb +7 -0
- data/lib/armadura/actions.rb +33 -0
- data/lib/armadura/adapters/heroku.rb +118 -0
- data/lib/armadura/app_builder.rb +484 -0
- data/lib/armadura/generators/app_generator.rb +245 -0
- data/lib/armadura/generators/static_generator.rb +10 -0
- data/lib/armadura/generators/stylesheet_base_generator.rb +37 -0
- data/lib/armadura/version.rb +8 -0
- data/spec/adapters/heroku_spec.rb +57 -0
- data/spec/fakes/bin/heroku +5 -0
- data/spec/fakes/bin/hub +5 -0
- data/spec/features/cli_help_spec.rb +36 -0
- data/spec/features/github_spec.rb +16 -0
- data/spec/features/heroku_spec.rb +75 -0
- data/spec/features/new_project_spec.rb +295 -0
- data/spec/features/sidekiq_spec.rb +30 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/armadura.rb +83 -0
- data/spec/support/fake_github.rb +21 -0
- data/spec/support/fake_heroku.rb +53 -0
- data/templates/Gemfile.erb +60 -0
- data/templates/Procfile +2 -0
- data/templates/README.md.erb +28 -0
- data/templates/_analytics.html.erb +7 -0
- data/templates/_css_overrides.html.erb +7 -0
- data/templates/_flashes.html.erb +7 -0
- data/templates/_javascript.html.erb +12 -0
- data/templates/action_mailer.rb +5 -0
- data/templates/app.json.erb +39 -0
- data/templates/application.scss +9 -0
- data/templates/armadura_gitignore +14 -0
- data/templates/armadura_layout.html.erb.erb +22 -0
- data/templates/bin_deploy +12 -0
- data/templates/bin_setup +22 -0
- data/templates/bin_setup_review_app.erb +19 -0
- data/templates/browserslist +3 -0
- data/templates/bundler_audit.rake +12 -0
- data/templates/capybara_webkit.rb +5 -0
- data/templates/circle.yml.erb +6 -0
- data/templates/config_locales_en.yml.erb +19 -0
- data/templates/database_cleaner_rspec.rb +21 -0
- data/templates/dev.rake +12 -0
- data/templates/dotfiles/.ctags +2 -0
- data/templates/dotfiles/.env +14 -0
- data/templates/errors.rb +34 -0
- data/templates/factories.rb +2 -0
- data/templates/factory_girl_rspec.rb +3 -0
- data/templates/flashes_helper.rb +5 -0
- data/templates/hound.yml +14 -0
- data/templates/i18n.rb +3 -0
- data/templates/json_encoding.rb +1 -0
- data/templates/postgresql_database.yml.erb +21 -0
- data/templates/puma.rb +28 -0
- data/templates/rack_mini_profiler.rb +5 -0
- data/templates/rails_helper.rb +22 -0
- data/templates/secrets.yml +14 -0
- data/templates/shoulda_matchers_config_rspec.rb +6 -0
- data/templates/sidekiq.yml +6 -0
- data/templates/smtp.rb +13 -0
- data/templates/spec_helper.rb +29 -0
- metadata +188 -0
@@ -0,0 +1,245 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/rails/app/app_generator'
|
3
|
+
|
4
|
+
module Armadura
|
5
|
+
class AppGenerator < Rails::Generators::AppGenerator
|
6
|
+
hide!
|
7
|
+
|
8
|
+
class_option :database, type: :string, aliases: "-d", default: "postgresql",
|
9
|
+
desc: "Configure for selected database (options: #{DATABASES.join("/")})"
|
10
|
+
|
11
|
+
class_option :heroku, type: :boolean, aliases: "-H", default: false,
|
12
|
+
desc: "Create staging and production Heroku apps"
|
13
|
+
|
14
|
+
class_option :heroku_flags, type: :string, default: "",
|
15
|
+
desc: "Set extra Heroku flags"
|
16
|
+
|
17
|
+
class_option :github, type: :string, default: nil,
|
18
|
+
desc: "Create Github repository and add remote origin pointed to repo"
|
19
|
+
|
20
|
+
class_option :version, type: :boolean, aliases: "-v", group: :armadura,
|
21
|
+
desc: "Show Armadura version number and quit"
|
22
|
+
|
23
|
+
class_option :help, type: :boolean, aliases: '-h', group: :armadura,
|
24
|
+
desc: "Show this help message and quit"
|
25
|
+
|
26
|
+
class_option :path, type: :string, default: nil,
|
27
|
+
desc: "Path to the gem"
|
28
|
+
|
29
|
+
def finish_template
|
30
|
+
invoke :armadura_customization
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
def armadura_customization
|
35
|
+
invoke :customize_gemfile
|
36
|
+
invoke :setup_development_environment
|
37
|
+
invoke :setup_test_environment
|
38
|
+
invoke :setup_production_environment
|
39
|
+
invoke :setup_secret_token
|
40
|
+
invoke :create_armadura_views
|
41
|
+
invoke :configure_app
|
42
|
+
invoke :copy_miscellaneous_files
|
43
|
+
invoke :customize_error_pages
|
44
|
+
invoke :remove_config_comment_lines
|
45
|
+
invoke :remove_routes_comment_lines
|
46
|
+
invoke :setup_dotfiles
|
47
|
+
invoke :setup_git
|
48
|
+
invoke :setup_database
|
49
|
+
invoke :create_local_heroku_setup
|
50
|
+
invoke :create_heroku_apps
|
51
|
+
invoke :create_github_repo
|
52
|
+
invoke :setup_segment
|
53
|
+
invoke :setup_bundler_audit
|
54
|
+
invoke :setup_spring
|
55
|
+
invoke :generate_default
|
56
|
+
invoke :outro
|
57
|
+
end
|
58
|
+
|
59
|
+
def customize_gemfile
|
60
|
+
build :replace_gemfile, options[:path]
|
61
|
+
build :set_ruby_to_version_being_used
|
62
|
+
bundle_command 'install'
|
63
|
+
build :configure_simple_form
|
64
|
+
end
|
65
|
+
|
66
|
+
def setup_database
|
67
|
+
say 'Setting up database'
|
68
|
+
|
69
|
+
if 'postgresql' == options[:database]
|
70
|
+
build :use_postgres_config_template
|
71
|
+
end
|
72
|
+
|
73
|
+
build :create_database
|
74
|
+
end
|
75
|
+
|
76
|
+
def setup_development_environment
|
77
|
+
say 'Setting up the development environment'
|
78
|
+
build :raise_on_missing_assets_in_test
|
79
|
+
build :raise_on_delivery_errors
|
80
|
+
build :remove_turbolinks
|
81
|
+
build :set_test_delivery_method
|
82
|
+
build :add_bullet_gem_configuration
|
83
|
+
build :raise_on_unpermitted_parameters
|
84
|
+
build :provide_setup_script
|
85
|
+
build :provide_dev_prime_task
|
86
|
+
build :configure_generators
|
87
|
+
build :configure_i18n_for_missing_translations
|
88
|
+
build :configure_quiet_assets
|
89
|
+
end
|
90
|
+
|
91
|
+
def setup_test_environment
|
92
|
+
say 'Setting up the test environment'
|
93
|
+
build :set_up_factory_girl_for_rspec
|
94
|
+
build :generate_factories_file
|
95
|
+
build :set_up_hound
|
96
|
+
build :generate_rspec
|
97
|
+
build :configure_rspec
|
98
|
+
build :enable_database_cleaner
|
99
|
+
build :provide_shoulda_matchers_config
|
100
|
+
build :configure_spec_support_features
|
101
|
+
build :configure_ci
|
102
|
+
build :configure_i18n_for_test_environment
|
103
|
+
build :configure_action_mailer_in_specs
|
104
|
+
build :configure_capybara_webkit
|
105
|
+
end
|
106
|
+
|
107
|
+
def setup_production_environment
|
108
|
+
say 'Setting up the production environment'
|
109
|
+
build :configure_smtp
|
110
|
+
build :configure_rack_timeout
|
111
|
+
build :enable_rack_canonical_host
|
112
|
+
build :enable_rack_deflater
|
113
|
+
build :setup_asset_host
|
114
|
+
end
|
115
|
+
|
116
|
+
def setup_secret_token
|
117
|
+
say 'Moving secret token out of version control'
|
118
|
+
build :setup_secret_token
|
119
|
+
end
|
120
|
+
|
121
|
+
def create_armadura_views
|
122
|
+
say 'Creating armadura views'
|
123
|
+
build :create_partials_directory
|
124
|
+
build :create_shared_flashes
|
125
|
+
build :create_shared_javascripts
|
126
|
+
build :create_shared_css_overrides
|
127
|
+
build :create_application_layout
|
128
|
+
end
|
129
|
+
|
130
|
+
def configure_app
|
131
|
+
say 'Configuring app'
|
132
|
+
build :configure_action_mailer
|
133
|
+
build :configure_active_job
|
134
|
+
build :configure_sidekiq
|
135
|
+
build :configure_time_formats
|
136
|
+
build :setup_default_rake_task
|
137
|
+
build :replace_default_puma_configuration
|
138
|
+
build :set_up_forego
|
139
|
+
build :setup_rack_mini_profiler
|
140
|
+
end
|
141
|
+
|
142
|
+
def setup_git
|
143
|
+
if !options[:skip_git]
|
144
|
+
say "Initializing git"
|
145
|
+
invoke :setup_default_directories
|
146
|
+
invoke :init_git
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def create_local_heroku_setup
|
151
|
+
say "Creating local Heroku setup"
|
152
|
+
build :create_review_apps_setup_script
|
153
|
+
build :create_deploy_script
|
154
|
+
build :create_heroku_application_manifest_file
|
155
|
+
end
|
156
|
+
|
157
|
+
def create_heroku_apps
|
158
|
+
if options[:heroku]
|
159
|
+
say "Creating Heroku apps"
|
160
|
+
build :create_heroku_apps, options[:heroku_flags]
|
161
|
+
build :set_heroku_remotes
|
162
|
+
build :set_heroku_rails_secrets
|
163
|
+
build :set_heroku_application_host
|
164
|
+
build :create_heroku_pipeline
|
165
|
+
build :configure_automatic_deployment
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def create_github_repo
|
170
|
+
if !options[:skip_git] && options[:github]
|
171
|
+
say 'Creating Github repo'
|
172
|
+
build :create_github_repo, options[:github]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def setup_segment
|
177
|
+
say 'Setting up Segment'
|
178
|
+
build :setup_segment
|
179
|
+
end
|
180
|
+
|
181
|
+
def setup_dotfiles
|
182
|
+
build :copy_dotfiles
|
183
|
+
end
|
184
|
+
|
185
|
+
def setup_default_directories
|
186
|
+
build :setup_default_directories
|
187
|
+
end
|
188
|
+
|
189
|
+
def setup_bundler_audit
|
190
|
+
say "Setting up bundler-audit"
|
191
|
+
build :setup_bundler_audit
|
192
|
+
end
|
193
|
+
|
194
|
+
def setup_spring
|
195
|
+
say "Springifying binstubs"
|
196
|
+
build :setup_spring
|
197
|
+
end
|
198
|
+
|
199
|
+
def init_git
|
200
|
+
build :init_git
|
201
|
+
end
|
202
|
+
|
203
|
+
def copy_miscellaneous_files
|
204
|
+
say 'Copying miscellaneous support files'
|
205
|
+
build :copy_miscellaneous_files
|
206
|
+
end
|
207
|
+
|
208
|
+
def customize_error_pages
|
209
|
+
say 'Customizing the 500/404/422 pages'
|
210
|
+
build :customize_error_pages
|
211
|
+
end
|
212
|
+
|
213
|
+
def remove_config_comment_lines
|
214
|
+
build :remove_config_comment_lines
|
215
|
+
end
|
216
|
+
|
217
|
+
def remove_routes_comment_lines
|
218
|
+
build :remove_routes_comment_lines
|
219
|
+
end
|
220
|
+
|
221
|
+
def generate_default
|
222
|
+
run("spring stop")
|
223
|
+
generate("armadura:static")
|
224
|
+
generate("armadura:stylesheet_base")
|
225
|
+
end
|
226
|
+
|
227
|
+
def outro
|
228
|
+
say 'The Rails application is now created!'
|
229
|
+
end
|
230
|
+
|
231
|
+
def self.banner
|
232
|
+
"armadura #{arguments.map(&:usage).join(' ')} [options]"
|
233
|
+
end
|
234
|
+
|
235
|
+
protected
|
236
|
+
|
237
|
+
def get_builder_class
|
238
|
+
Armadura::AppBuilder
|
239
|
+
end
|
240
|
+
|
241
|
+
def using_active_record?
|
242
|
+
!options[:skip_active_record]
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module Armadura
|
4
|
+
class StylesheetBaseGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path(
|
6
|
+
File.join("..", "..", "..", "templates"),
|
7
|
+
File.dirname(__FILE__))
|
8
|
+
|
9
|
+
def add_stylesheet_gems
|
10
|
+
gem "bourbon", "5.0.0.beta.6"
|
11
|
+
gem "neat", "~> 1.8.0"
|
12
|
+
gem "refills", group: [:development, :test]
|
13
|
+
Bundler.with_clean_env { run "bundle install" }
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_css_config
|
17
|
+
copy_file(
|
18
|
+
"application.scss",
|
19
|
+
"app/assets/stylesheets/application.scss",
|
20
|
+
force: true,
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def remove_prior_config
|
25
|
+
remove_file "app/assets/stylesheets/application.css"
|
26
|
+
end
|
27
|
+
|
28
|
+
def install_refills
|
29
|
+
generate "refills:import", "flashes"
|
30
|
+
remove_dir "app/views/refills"
|
31
|
+
end
|
32
|
+
|
33
|
+
def install_bitters
|
34
|
+
run "bitters install --path app/assets/stylesheets"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Armadura
|
4
|
+
module Adapters
|
5
|
+
RSpec.describe Heroku do
|
6
|
+
it "sets the heroku remotes" do
|
7
|
+
setup_file = "bin/setup"
|
8
|
+
app_builder = double(app_name: app_name)
|
9
|
+
allow(app_builder).to receive(:append_file)
|
10
|
+
|
11
|
+
Heroku.new(app_builder).set_heroku_remotes
|
12
|
+
|
13
|
+
expect(app_builder).to have_received(:append_file).
|
14
|
+
with(setup_file, /heroku join --app #{app_name.dasherize}-production/)
|
15
|
+
expect(app_builder).to have_received(:append_file).
|
16
|
+
with(setup_file, /heroku join --app #{app_name.dasherize}-staging/)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets the heroku rails secrets" do
|
20
|
+
app_builder = double(app_name: app_name)
|
21
|
+
allow(app_builder).to receive(:run)
|
22
|
+
|
23
|
+
Heroku.new(app_builder).set_heroku_rails_secrets
|
24
|
+
|
25
|
+
expect(app_builder).to(
|
26
|
+
have_configured_var("staging", "SECRET_KEY_BASE"),
|
27
|
+
)
|
28
|
+
expect(app_builder).to(
|
29
|
+
have_configured_var("production", "SECRET_KEY_BASE"),
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets the application host" do
|
34
|
+
app_builder = double(app_name: app_name)
|
35
|
+
allow(app_builder).to receive(:run)
|
36
|
+
|
37
|
+
Heroku.new(app_builder).set_heroku_application_host
|
38
|
+
|
39
|
+
expect(app_builder).to(
|
40
|
+
have_configured_var("staging", "APPLICATION_HOST"),
|
41
|
+
)
|
42
|
+
|
43
|
+
expect(app_builder).to(
|
44
|
+
have_configured_var("production", "APPLICATION_HOST"),
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def app_name
|
49
|
+
ArmaduraTestHelpers::APP_NAME
|
50
|
+
end
|
51
|
+
|
52
|
+
def have_configured_var(remote_name, var)
|
53
|
+
have_received(:run).with(/config:add #{var}=.+ --remote #{remote_name}/)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/fakes/bin/hub
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Command line help output" do
|
4
|
+
let(:help_text) { armadura_help_command }
|
5
|
+
|
6
|
+
it "does not contain the default rails usage statement" do
|
7
|
+
expect(help_text).not_to include("rails new APP_PATH [options]")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "provides the correct usage statement for armadura" do
|
11
|
+
expect(help_text).to include <<~EOH
|
12
|
+
Usage:
|
13
|
+
armadura APP_PATH [options]
|
14
|
+
EOH
|
15
|
+
end
|
16
|
+
|
17
|
+
it "does not contain the default rails group" do
|
18
|
+
expect(help_text).not_to include("Rails options:")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "provides help and version usage within the armadura group" do
|
22
|
+
expect(help_text).to include <<~EOH
|
23
|
+
Armadura options:
|
24
|
+
-h, [--help], [--no-help] # Show this help message and quit
|
25
|
+
-v, [--version], [--no-version] # Show Armadura version number and quit
|
26
|
+
EOH
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not show the default extended rails help section" do
|
30
|
+
expect(help_text).not_to include("Create armadura files for app generator.")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "contains the usage statement from the armadura gem" do
|
34
|
+
expect(help_text).to include IO.read(usage_file)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "GitHub" do
|
4
|
+
before do
|
5
|
+
drop_dummy_database
|
6
|
+
remove_project_directory
|
7
|
+
end
|
8
|
+
|
9
|
+
it "suspends a project with --github option" do
|
10
|
+
repo_name = "test"
|
11
|
+
run_armadura("--github=#{repo_name}")
|
12
|
+
setup_app_dependencies
|
13
|
+
|
14
|
+
expect(FakeGithub).to have_created_repo(repo_name)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Heroku" do
|
4
|
+
context "--heroku" do
|
5
|
+
before(:all) do
|
6
|
+
clean_up
|
7
|
+
run_armadura("--heroku=true")
|
8
|
+
setup_app_dependencies
|
9
|
+
end
|
10
|
+
|
11
|
+
it "suspends a project for Heroku" do
|
12
|
+
app_name = ArmaduraTestHelpers::APP_NAME.dasherize
|
13
|
+
|
14
|
+
expect(FakeHeroku).to have_created_app_for("staging")
|
15
|
+
expect(FakeHeroku).to have_created_app_for("production")
|
16
|
+
expect(FakeHeroku).to have_configured_vars("staging", "SECRET_KEY_BASE")
|
17
|
+
expect(FakeHeroku).to have_configured_vars(
|
18
|
+
"production",
|
19
|
+
"SECRET_KEY_BASE",
|
20
|
+
)
|
21
|
+
expect(FakeHeroku).to have_configured_vars(
|
22
|
+
"staging",
|
23
|
+
"APPLICATION_HOST",
|
24
|
+
)
|
25
|
+
expect(FakeHeroku).to have_configured_vars(
|
26
|
+
"production",
|
27
|
+
"APPLICATION_HOST",
|
28
|
+
)
|
29
|
+
expect(FakeHeroku).to have_setup_pipeline_for(app_name)
|
30
|
+
|
31
|
+
bin_setup_path = "#{project_path}/bin/setup"
|
32
|
+
bin_setup = IO.read(bin_setup_path)
|
33
|
+
|
34
|
+
expect(bin_setup).to include("heroku join --app #{app_name}-production")
|
35
|
+
expect(bin_setup).to include("heroku join --app #{app_name}-staging")
|
36
|
+
expect(bin_setup).to include("git config heroku.remote staging")
|
37
|
+
expect(File.stat(bin_setup_path)).to be_executable
|
38
|
+
|
39
|
+
readme = IO.read("#{project_path}/README.md")
|
40
|
+
|
41
|
+
expect(readme).to include("./bin/deploy staging")
|
42
|
+
expect(readme).to include("./bin/deploy production")
|
43
|
+
|
44
|
+
circle_yml_path = "#{project_path}/circle.yml"
|
45
|
+
circle_yml = IO.read(circle_yml_path)
|
46
|
+
|
47
|
+
expect(circle_yml).to include <<-YML.strip_heredoc
|
48
|
+
deployment:
|
49
|
+
staging:
|
50
|
+
branch: master
|
51
|
+
commands:
|
52
|
+
- bin/deploy staging
|
53
|
+
YML
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "--heroku with region flag" do
|
58
|
+
before(:all) do
|
59
|
+
clean_up
|
60
|
+
run_armadura(%{--heroku=true --heroku-flags="--region eu"})
|
61
|
+
setup_app_dependencies
|
62
|
+
end
|
63
|
+
|
64
|
+
it "suspends a project with extra Heroku flags" do
|
65
|
+
expect(FakeHeroku).to have_created_app_for("staging", "--region eu")
|
66
|
+
expect(FakeHeroku).to have_created_app_for("production", "--region eu")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def clean_up
|
71
|
+
drop_dummy_database
|
72
|
+
remove_project_directory
|
73
|
+
FakeHeroku.clear!
|
74
|
+
end
|
75
|
+
end
|