panacea-rails 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.
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "arguments_parser"
4
+ require_relative "customizer"
5
+
6
+ module Panacea # :nodoc:
7
+ module Rails # :nodoc:
8
+ ###
9
+ # == Panacea::Rails::Runner
10
+ #
11
+ # This module is where Panacea's work start.
12
+ module Runner
13
+ extend ArgumentsParser
14
+
15
+ class << self
16
+ ###
17
+ # This method receives the App's name and the arguments passed to Panacea command.
18
+ #
19
+ # It uses the Panacea::Rails::ArgumentsParser.parse_arguments method to transform the passed arguments.
20
+ #
21
+ # It also starts the Panacea::Rails::Customizer which is in charge of asking the configuration questions.
22
+ #
23
+ # Then, it appends the Panacea's Template option to the list of parsed arguments.
24
+ #
25
+ # It finally runs the rails new command with the App's name and the final list of arguments.
26
+ def call(app_name, rails_args)
27
+ parsed_arguments = parse_arguments(rails_args)
28
+ Customizer.start(app_name, parsed_arguments.dup)
29
+
30
+ panacea_template = __dir__ + "/template.rb"
31
+ parsed_arguments << " --template=#{panacea_template}"
32
+ parsed_arguments = parsed_arguments.split(" ")
33
+
34
+ system("rails", "new", app_name, *parsed_arguments)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/http"
5
+
6
+ module Panacea # :nodoc:
7
+ module Rails # :nodoc:
8
+ ###
9
+ # == Panacea::Rails::Stats
10
+ #
11
+ # This class tracks the end users answers if they agree to.
12
+ class Stats
13
+ ###
14
+ # Hash with the question's answers + ruby version + passed arguments
15
+ attr_reader :params
16
+
17
+ ###
18
+ # Panacea's Stats App endpoint
19
+ API_BASE = "https://stats.panacea.website/statistics"
20
+
21
+ ###
22
+ # It sends the end user's answers to the Panacea's Stats App.
23
+ def self.track(params)
24
+ new(params)
25
+ end
26
+
27
+ ###
28
+ # Panacea::Rails::Stats initialize method.
29
+ def initialize(params)
30
+ @params = params
31
+ track
32
+ end
33
+
34
+ ###
35
+ # Makes an async call to the Panacea's Stats App.
36
+ def track
37
+ request_async_post(params)
38
+ end
39
+
40
+ private
41
+
42
+ def request_async_post(params)
43
+ Thread.new do
44
+ request_post(params)
45
+ end
46
+ end
47
+
48
+ def request_post(params)
49
+ uri = URI(API_BASE)
50
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
51
+ request = Net::HTTP::Post.new(uri)
52
+ request["Accept"] = "application/json"
53
+ request["Content-Type"] = "application/json"
54
+ request.body = params.to_json
55
+
56
+ http.request(request)
57
+ end
58
+
59
+ response.code == "201" || response.code != "422"
60
+ rescue Net::OpenTimeout, Errno::ECONNREFUSED
61
+ false
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ ###
4
+ # == Panacea::Rails::Template
5
+ #
6
+ # Template passed to the rails new command.
7
+ #
8
+ # If you want more information about what's happening you can read Panacea::Rails::Generator docs.
9
+
10
+ require "yaml"
11
+ require_relative "generator"
12
+
13
+ ###
14
+ # Panacea's Installation directory
15
+ ROOT_DIR = File.expand_path("../../../", __dir__)
16
+
17
+ # Read .panacea configurations file
18
+ configurations_file = File.join(ROOT_DIR, ".panacea")
19
+ panacea_config = YAML.safe_load(File.read(configurations_file))
20
+ panacea_config["ruby_version"] = RUBY_VERSION
21
+
22
+ # Start running Panacea Generator Actions via Rails Generator / Thor
23
+ panacea_generator = Panacea::Rails::Generator.new(self, panacea_config, ROOT_DIR)
24
+
25
+ panacea_generator.update_source_paths
26
+ panacea_generator.copy_gemfile
27
+ panacea_generator.copy_readme
28
+ panacea_generator.generate_panacea_document
29
+ panacea_generator.setup_rubocop
30
+ panacea_generator.setup_letter_opener
31
+ panacea_generator.setup_timezone
32
+ panacea_generator.setup_default_locale
33
+ panacea_generator.setup_oj if panacea_config.dig("oj")
34
+ panacea_generator.setup_dotenv if panacea_config.dig("dotenv")
35
+
36
+ panacea_generator.after_bundle_hook do |generator|
37
+ generator.setup_bullet
38
+ generator.setup_test_suite
39
+ generator.override_test_helper
40
+ generator.setup_simplecov
41
+ generator.setup_background_job if panacea_config.dig("background_job") != "none"
42
+ generator.override_application_system_test if panacea_config.dig("headless_chrome")
43
+ generator.setup_devise if panacea_config.dig("devise")
44
+ generator.setup_money_rails if panacea_config.dig("money_rails")
45
+ generator.setup_kaminari if panacea_config.dig("kaminari")
46
+ generator.setup_webpack if panacea_config.dig("webpack")
47
+ generator.setup_foreman if panacea_config.dig("foreman")
48
+ generator.setup_pundit if panacea_config.dig("pundit")
49
+
50
+ # This should be always at the end
51
+ generator.fix_offenses!
52
+ generator.commit! if panacea_config.dig("autocommit")
53
+ generator.setup_githook if panacea_config.dig("githook") && !options[:skip_git]
54
+
55
+ generator.bye_message
56
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Panacea # :nodoc:
4
+ module Rails # :nodoc:
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require "panacea/rails/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "panacea-rails"
10
+ spec.version = Panacea::Rails::VERSION
11
+ spec.authors = ["Guillermo Moreno", "Rafael Ramos", "Eduardo Figarola"]
12
+ spec.email = ["guillermo@michelada.io", "rafael@michelada.io", "eduardo@michelada.io"]
13
+
14
+ spec.summary = "Rails Apps Generator"
15
+ spec.homepage = "https://www.panacea.website"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "bundler", "~> 1"
26
+ spec.add_dependency "slop", "~> 4.6"
27
+ spec.add_dependency "tty-prompt", "~> 0.17"
28
+
29
+ spec.add_development_dependency "minitest", "~> 5.0"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rubocop", "~> 0.58"
32
+ spec.add_development_dependency "sdoc", "~> 1.0"
33
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+ <%- db_gem = database_gemfile_entry -%>
3
+
4
+ source "https://rubygems.org"
5
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
6
+
7
+ ruby "<%= @panacea.dig("ruby_version") %>"
8
+ gem "rails", "~> 5.2.1"
9
+ gem "<%= db_gem.name %>"<%= %(, '#{db_gem.version}') if db_gem.version %>
10
+
11
+ gem "bootsnap", ">= 1.1.0", require: false
12
+ <% if @panacea.dig("devise") -%>
13
+ gem "devise"
14
+ <% end -%>
15
+ gem "haml-rails"
16
+ gem "interactor-rails"
17
+ <% if @panacea.dig("kaminari") -%>
18
+ gem "kaminari"
19
+ <% end -%>
20
+ <% if @panacea.dig("oj") -%>
21
+ gem "oj", "~> 3"
22
+ <% end -%>
23
+ <% if @panacea.dig("money_rails") -%>
24
+ gem "money-rails", "~> 1"
25
+ <% end -%>
26
+ <% if @panacea.dig("pg_search") -%>
27
+ gem "pg_search"
28
+ <% end -%>
29
+ gem "puma", "~> 3.11"
30
+ <% if @panacea.dig("pundit") -%>
31
+ gem "pundit"
32
+ <% end -%>
33
+ <% if @panacea.dig("markdown") -%>
34
+ gem "redcarpet"
35
+ <% end -%>
36
+ gem "sass-rails", "~> 5.0"
37
+ gem "turbolinks", "~> 5"
38
+ gem "uglifier", ">= 1.3.0"
39
+ <% if @panacea.dig("webpack") -%>
40
+ gem "webpacker"
41
+ <% end -%>
42
+
43
+ <% if @panacea.dig("background_job") != "none" -%>
44
+ # Background Jobs Adapter
45
+ gem "<%= @panacea.dig("background_job") %>"
46
+ <% end -%>
47
+
48
+ # Test Suite Gem
49
+ gem "<%= @panacea.dig("test_suite") %>-rails", group: [:development, :test]
50
+
51
+ group :development, :test do
52
+ <% if @panacea.dig("awesome_print") -%>
53
+ gem "awesome_print"
54
+ <% end -%>
55
+ <% if @panacea.dig("dotenv") -%>
56
+ gem "dotenv-rails"
57
+ <% end -%>
58
+ <% if @panacea.dig("factory_bot") -%>
59
+ gem "factory_bot_rails", "~> 4.0"
60
+ <% end -%>
61
+ gem "pry"
62
+ gem "rubocop-rails_config"
63
+ end
64
+
65
+ group :development do
66
+ gem "brakeman"
67
+ gem "bullet"
68
+ gem "web-console", ">= 3.3.0"
69
+ gem "listen", ">= 3.0.5", "< 3.2"
70
+ gem "spring"
71
+ gem "spring-watcher-listen", "~> 2.0.0"
72
+ gem "letter_opener"
73
+ end
74
+
75
+ group :test do
76
+ gem "capybara", ">= 2.15", "< 4.0"
77
+ gem "capybara-selenium"
78
+ gem "chromedriver-helper"
79
+ <% if @panacea.dig("faker") -%>
80
+ gem "faker"
81
+ <% end -%>
82
+ gem "selenium-webdriver"
83
+ gem "simplecov", require: false
84
+ <% if @panacea.dig("http_stubs") != "none" -%>
85
+ gem "<%= @panacea.dig("http_stubs") %>"
86
+ <% end -%>
87
+ end
88
+
89
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
90
+ gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
@@ -0,0 +1,188 @@
1
+ # Panacea::Rails
2
+
3
+ Here is what Panacea has setup for you:
4
+
5
+ ### Application Settings
6
+
7
+ #### Timezone
8
+
9
+ Default timezone was set to: **<%= @panacea.dig("timezone") %>** in *config/application.rb*
10
+
11
+ #### Locale
12
+
13
+ Default locale was set to: **<%= @panacea.dig("locale") %>** in *config/application.rb*
14
+
15
+ ### Development Tools
16
+
17
+ <% if @panacea.dig("awesome_print") -%>
18
+ #### awesome_print
19
+ The gem was included in Gemfile.
20
+ <% end -%>
21
+
22
+ #### Bullet
23
+ * The gem was included in Gemfile.
24
+ * `config/environments/development.rb` was modified.
25
+
26
+ <% if @panacea.dig("foreman") -%>
27
+ #### Foreman
28
+ * Foreman gem was installed in system if needed.
29
+ * **Procfile** was created.
30
+ <% end -%>
31
+
32
+ <% if @panacea.dig("githook") -%>
33
+ #### Git hook
34
+ The Git hook was installed in *.git/hooks/<%= @panacea.dig("githook_type") %>*
35
+ <% end -%>
36
+
37
+ ### General Purpose
38
+
39
+ <% if @panacea.dig("devise") -%>
40
+ #### devise
41
+ * The gem was included in Gemfile.
42
+ * `app/models/<%= @panacea.dig("devise_model_name") %>.rb` was created.
43
+ * <%= @panacea.dig("devise_override_views") ? "Devise views were created." : "Devise views were not created." %>
44
+ <% end -%>
45
+
46
+ <% if @panacea.dig("dotenv") -%>
47
+ #### dotenv-rails
48
+ * The gem was included in Gemfile.
49
+ * `.env` file was created
50
+ * `.env` file was added to .gitignore
51
+ <% end -%>
52
+
53
+ #### haml-rails
54
+ The gem was included in Gemfile.
55
+
56
+ #### interactor-rails
57
+ The gem was included in Gemfile.
58
+
59
+ <% if @panacea.dig("kaminari") -%>
60
+ #### Kaminari
61
+ * The gem was included in Gemfile.
62
+ * The `rails generate kaminari:config` generator was ran.
63
+ <% end -%>
64
+
65
+ #### letter_opener
66
+ * The gem was included in Gemfile.
67
+ * `config/environments/development.rb` was modified.
68
+
69
+ <% if @panacea.dig("money_rails") -%>
70
+ #### money-rails
71
+ * The gem was included in Gemfile.
72
+ * The `rails generate money_rails:initializer` generator was ran.
73
+ <% end -%>
74
+
75
+ <% if @panacea.dig("oj") -%>
76
+ #### oj
77
+ * The gem was included in Gemfile.
78
+ * The `config/initializers/oj.rb` file was created
79
+ <% end -%>
80
+
81
+ #### pry
82
+ The gem was included in Gemfile.
83
+
84
+ <% if @panacea.dig("pg_search") -%>
85
+ #### pg_search
86
+ The gem was included in Gemfile.
87
+ <% end -%>
88
+
89
+ <% if @panacea.dig("pundit") -%>
90
+ #### pundit
91
+ * The gem was included in Gemfile.
92
+ * `app/controllers/application_controller.rb` was modified.
93
+ * The `rails generate pundit:install` generator was ran.
94
+ <% end -%>
95
+
96
+ <% if @panacea.dig("markdown") -%>
97
+ #### redcarpet
98
+ The gem was included in Gemfile.
99
+ <% end -%>
100
+
101
+ <% if @panacea.dig("webpack") -%>
102
+ ### Assets
103
+
104
+ #### webpacker
105
+ * The gem was included in Gemfile.
106
+ * **<%= @panacea.dig("webpack_type") %>** was the chosen framework.
107
+ <% end -%>
108
+
109
+ ### Background Job
110
+
111
+ #### <%= @panacea.dig("background_job") %>
112
+ <% if @panacea.dig("background_job") != "none" -%>
113
+ * The gem was included in Gemfile.
114
+ * `config/application.rb` was modified.
115
+ <% end -%>
116
+ <% if @panacea.dig("background_job") =~ /sidekiq|resque/ -%>
117
+ * `config/routes.rb` were updated.
118
+ <% end -%>
119
+ <% if @panacea.dig("background_job") == "resque" -%>
120
+ * `Rakefile` was updated
121
+ <% end -%>
122
+
123
+ ### Security
124
+
125
+ #### brakeman
126
+ The gem was included in Gemfile.
127
+
128
+ ### Code Coverage
129
+
130
+ #### simplecov
131
+ * The gem was included in Gemfile.
132
+ * The expected code coverage was set to: <%= @panacea.dig("expected_coverage") %>
133
+ <% if @panacea.dig("test_suite") == "minitest" -%>
134
+ * `test/support/simplecov.rb` was created.
135
+ <% else -%>
136
+ * `spec/support/simplecov.rb` was created.
137
+ <% end -%>
138
+
139
+ ### Linting
140
+
141
+ #### rubocop-rails_config
142
+ * The gem was included in Gemfile.
143
+ * The `.rubocop.yml` file was created.
144
+
145
+ ### Testing
146
+
147
+ <% if @panacea.dig("factory_bot") -%>
148
+ #### factory_bot
149
+ * The gem was included in Gemfile.
150
+ <% if @panacea.dig("test_suite") == "minitest" -%>
151
+ * `test/test_helper.rb` was modified.
152
+ <% else -%>
153
+ * `spec/rails_helper.rb` was modified.
154
+ <% end -%>
155
+ <% end -%>
156
+
157
+ <% if @panacea.dig("faker") -%>
158
+ #### Faker
159
+ * The gem was included in Gemfile.
160
+ <% if @panacea.dig("test_suite") == "minitest" -%>
161
+ * `test/test_helper.rb` was modified.
162
+ <% else -%>
163
+ * `spec/rails_helper.rb` was modified.
164
+ <% end -%>
165
+ <% end -%>
166
+
167
+ #### <%= @panacea.dig("test_suite") %>-rails
168
+ * The gem was included in Gemfile.
169
+ <% if @panacea.dig("test_suite") == "minitest" -%>
170
+ * `test/test_helper.rb` was created.
171
+ <% else -%>
172
+ * `spec/rails_helper.rb` was created.
173
+ <% end -%>
174
+
175
+ <% if @panacea.dig("headless_chrome") -%>
176
+ #### Headless Chrome
177
+ The System Tests were configured to run using a Headless Chrome Driver.
178
+ <% end -%>
179
+
180
+ <% if @panacea.dig("http_stubs") != "none" -%>
181
+ #### <%= @panacea.dig("http_stubs") %>
182
+ * The gem was included in Gemfile.
183
+ <% if @panacea.dig("test_suite") == "minitest" -%>
184
+ * `test/test_helper.rb` was modified.
185
+ <% else -%>
186
+ * `spec/rails_helper.rb` was modified.
187
+ <% end -%>
188
+ <% end -%>