rails-interactive 2.1.0 → 2.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 482ad6f26a28d35ab5a4d58ea8f0f56bfe977bd1096bfc25a26bed05cf318b1f
4
- data.tar.gz: fad72c7fec9fe01a3e28ba23e370f1c200155ad2207dc32e8c57b969c0b4e882
3
+ metadata.gz: a8f73ef75d5e0f8f36b2206dc2b36f11e9d3a64103496d03b893bbf431cce3c9
4
+ data.tar.gz: 48036a06a2a349f958e34249c833b9462ff4a1452feadd9e611a2880ec34ffad
5
5
  SHA512:
6
- metadata.gz: 4a91c4823bd9b5322c5e72b3fb402edba3d8d90f951aeb5c9b4e7762ea14a50bb91669995b2171a6a478d70b2e4234f5b55870d7c3eaa1ef159535cdd08c3a3f
7
- data.tar.gz: 17c8c28bfa9286d09bb0e72a56372f40438a68ff594836fbca9e1146a7709f443ae37ccfeddce8e4cd842ac83025018b1171f98a8a6799b4d5918aed384bc2b1
6
+ metadata.gz: bd644861a5cc67eaab30f629965a36ce3bb9fea78d071055e6ede9ddea5296f44f9be1f05cf2ca21c128f3b7352f73bad60474ec6e6f4c596e1ad5592c656352
7
+ data.tar.gz: 0baa8477280f02d4d564cb54e9a3e478160b1c0c3e13610b8ec2ef806f6b4d033303a1bf26b0218e6bd1894050111cd447bd5b2f47927b71665316512e1a9629
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ mkmf.log
16
16
  *.gem
17
17
  # rspec failure tracking
18
18
  .rspec_status
19
+ .idea
data/.rubocop.yml CHANGED
@@ -19,4 +19,10 @@ Metrics/MethodLength:
19
19
  Max: 12
20
20
 
21
21
  Metrics/CyclomaticComplexity:
22
- Max: 25
22
+ Max: 25
23
+
24
+ Metrics/PerceivedComplexity:
25
+ Max: 10
26
+
27
+ Metrics/AbcSize:
28
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,73 +1,73 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails-interactive (2.1.0)
4
+ rails-interactive (2.1.3)
5
5
  tty-prompt
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (7.0.3)
11
- actionpack (= 7.0.3)
12
- activesupport (= 7.0.3)
10
+ actioncable (7.0.3.1)
11
+ actionpack (= 7.0.3.1)
12
+ activesupport (= 7.0.3.1)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
- actionmailbox (7.0.3)
16
- actionpack (= 7.0.3)
17
- activejob (= 7.0.3)
18
- activerecord (= 7.0.3)
19
- activestorage (= 7.0.3)
20
- activesupport (= 7.0.3)
15
+ actionmailbox (7.0.3.1)
16
+ actionpack (= 7.0.3.1)
17
+ activejob (= 7.0.3.1)
18
+ activerecord (= 7.0.3.1)
19
+ activestorage (= 7.0.3.1)
20
+ activesupport (= 7.0.3.1)
21
21
  mail (>= 2.7.1)
22
22
  net-imap
23
23
  net-pop
24
24
  net-smtp
25
- actionmailer (7.0.3)
26
- actionpack (= 7.0.3)
27
- actionview (= 7.0.3)
28
- activejob (= 7.0.3)
29
- activesupport (= 7.0.3)
25
+ actionmailer (7.0.3.1)
26
+ actionpack (= 7.0.3.1)
27
+ actionview (= 7.0.3.1)
28
+ activejob (= 7.0.3.1)
29
+ activesupport (= 7.0.3.1)
30
30
  mail (~> 2.5, >= 2.5.4)
31
31
  net-imap
32
32
  net-pop
33
33
  net-smtp
34
34
  rails-dom-testing (~> 2.0)
35
- actionpack (7.0.3)
36
- actionview (= 7.0.3)
37
- activesupport (= 7.0.3)
35
+ actionpack (7.0.3.1)
36
+ actionview (= 7.0.3.1)
37
+ activesupport (= 7.0.3.1)
38
38
  rack (~> 2.0, >= 2.2.0)
39
39
  rack-test (>= 0.6.3)
40
40
  rails-dom-testing (~> 2.0)
41
41
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
42
- actiontext (7.0.3)
43
- actionpack (= 7.0.3)
44
- activerecord (= 7.0.3)
45
- activestorage (= 7.0.3)
46
- activesupport (= 7.0.3)
42
+ actiontext (7.0.3.1)
43
+ actionpack (= 7.0.3.1)
44
+ activerecord (= 7.0.3.1)
45
+ activestorage (= 7.0.3.1)
46
+ activesupport (= 7.0.3.1)
47
47
  globalid (>= 0.6.0)
48
48
  nokogiri (>= 1.8.5)
49
- actionview (7.0.3)
50
- activesupport (= 7.0.3)
49
+ actionview (7.0.3.1)
50
+ activesupport (= 7.0.3.1)
51
51
  builder (~> 3.1)
52
52
  erubi (~> 1.4)
53
53
  rails-dom-testing (~> 2.0)
54
54
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
55
- activejob (7.0.3)
56
- activesupport (= 7.0.3)
55
+ activejob (7.0.3.1)
56
+ activesupport (= 7.0.3.1)
57
57
  globalid (>= 0.3.6)
58
- activemodel (7.0.3)
59
- activesupport (= 7.0.3)
60
- activerecord (7.0.3)
61
- activemodel (= 7.0.3)
62
- activesupport (= 7.0.3)
63
- activestorage (7.0.3)
64
- actionpack (= 7.0.3)
65
- activejob (= 7.0.3)
66
- activerecord (= 7.0.3)
67
- activesupport (= 7.0.3)
58
+ activemodel (7.0.3.1)
59
+ activesupport (= 7.0.3.1)
60
+ activerecord (7.0.3.1)
61
+ activemodel (= 7.0.3.1)
62
+ activesupport (= 7.0.3.1)
63
+ activestorage (7.0.3.1)
64
+ actionpack (= 7.0.3.1)
65
+ activejob (= 7.0.3.1)
66
+ activerecord (= 7.0.3.1)
67
+ activesupport (= 7.0.3.1)
68
68
  marcel (~> 1.0)
69
69
  mini_mime (>= 1.1.0)
70
- activesupport (7.0.3)
70
+ activesupport (7.0.3.1)
71
71
  concurrent-ruby (~> 1.0, >= 1.0.2)
72
72
  i18n (>= 1.6, < 2)
73
73
  minitest (>= 5.1)
@@ -84,8 +84,9 @@ GEM
84
84
  erubi (1.10.0)
85
85
  globalid (1.0.0)
86
86
  activesupport (>= 5.0)
87
- i18n (1.10.0)
87
+ i18n (1.12.0)
88
88
  concurrent-ruby (~> 1.0)
89
+ json (2.6.2)
89
90
  loofah (2.18.0)
90
91
  crass (~> 1.0.2)
91
92
  nokogiri (>= 1.5.9)
@@ -94,7 +95,7 @@ GEM
94
95
  marcel (1.0.2)
95
96
  method_source (1.0.0)
96
97
  mini_mime (1.1.2)
97
- minitest (5.15.0)
98
+ minitest (5.16.2)
98
99
  net-imap (0.2.3)
99
100
  digest
100
101
  net-protocol
@@ -110,9 +111,9 @@ GEM
110
111
  net-protocol
111
112
  timeout
112
113
  nio4r (2.5.8)
113
- nokogiri (1.13.6-x86_64-darwin)
114
+ nokogiri (1.13.7-x86_64-darwin)
114
115
  racc (~> 1.4)
115
- nokogiri (1.13.6-x86_64-linux)
116
+ nokogiri (1.13.7-x86_64-linux)
116
117
  racc (~> 1.4)
117
118
  parallel (1.22.1)
118
119
  parser (3.1.2.0)
@@ -123,31 +124,31 @@ GEM
123
124
  coderay (~> 1.1)
124
125
  method_source (~> 1.0)
125
126
  racc (1.6.0)
126
- rack (2.2.3.1)
127
- rack-test (1.1.0)
128
- rack (>= 1.0, < 3)
129
- rails (7.0.3)
130
- actioncable (= 7.0.3)
131
- actionmailbox (= 7.0.3)
132
- actionmailer (= 7.0.3)
133
- actionpack (= 7.0.3)
134
- actiontext (= 7.0.3)
135
- actionview (= 7.0.3)
136
- activejob (= 7.0.3)
137
- activemodel (= 7.0.3)
138
- activerecord (= 7.0.3)
139
- activestorage (= 7.0.3)
140
- activesupport (= 7.0.3)
127
+ rack (2.2.4)
128
+ rack-test (2.0.2)
129
+ rack (>= 1.3)
130
+ rails (7.0.3.1)
131
+ actioncable (= 7.0.3.1)
132
+ actionmailbox (= 7.0.3.1)
133
+ actionmailer (= 7.0.3.1)
134
+ actionpack (= 7.0.3.1)
135
+ actiontext (= 7.0.3.1)
136
+ actionview (= 7.0.3.1)
137
+ activejob (= 7.0.3.1)
138
+ activemodel (= 7.0.3.1)
139
+ activerecord (= 7.0.3.1)
140
+ activestorage (= 7.0.3.1)
141
+ activesupport (= 7.0.3.1)
141
142
  bundler (>= 1.15.0)
142
- railties (= 7.0.3)
143
+ railties (= 7.0.3.1)
143
144
  rails-dom-testing (2.0.3)
144
145
  activesupport (>= 4.2.0)
145
146
  nokogiri (>= 1.6)
146
- rails-html-sanitizer (1.4.2)
147
+ rails-html-sanitizer (1.4.3)
147
148
  loofah (~> 2.3)
148
- railties (7.0.3)
149
- actionpack (= 7.0.3)
150
- activesupport (= 7.0.3)
149
+ railties (7.0.3.1)
150
+ actionpack (= 7.0.3.1)
151
+ activesupport (= 7.0.3.1)
151
152
  method_source
152
153
  rake (>= 12.2)
153
154
  thor (~> 1.0)
@@ -169,7 +170,8 @@ GEM
169
170
  diff-lcs (>= 1.2.0, < 2.0)
170
171
  rspec-support (~> 3.11.0)
171
172
  rspec-support (3.11.0)
172
- rubocop (1.30.0)
173
+ rubocop (1.31.2)
174
+ json (~> 2.3)
173
175
  parallel (~> 1.10)
174
176
  parser (>= 3.1.0.0)
175
177
  rainbow (>= 2.2.2, < 4.0)
@@ -178,7 +180,7 @@ GEM
178
180
  rubocop-ast (>= 1.18.0, < 2.0)
179
181
  ruby-progressbar (~> 1.7)
180
182
  unicode-display_width (>= 1.4.0, < 3.0)
181
- rubocop-ast (1.18.0)
183
+ rubocop-ast (1.19.1)
182
184
  parser (>= 3.1.1.0)
183
185
  ruby-progressbar (1.11.0)
184
186
  strscan (3.0.3)
@@ -196,13 +198,13 @@ GEM
196
198
  tty-screen (0.8.1)
197
199
  tzinfo (2.0.4)
198
200
  concurrent-ruby (~> 1.0)
199
- unicode-display_width (2.1.0)
201
+ unicode-display_width (2.2.0)
200
202
  websocket-driver (0.7.5)
201
203
  websocket-extensions (>= 0.1.0)
202
204
  websocket-extensions (0.1.5)
203
205
  wisper (2.0.1)
204
206
  yaml (0.2.0)
205
- zeitwerk (2.5.4)
207
+ zeitwerk (2.6.0)
206
208
 
207
209
  PLATFORMS
208
210
  x86_64-darwin-20
@@ -9,24 +9,42 @@ module RailsInteractive
9
9
  class CommandHandler
10
10
  def initialize
11
11
  @commands = Command.new.all
12
+ @installed_commands = []
13
+ @installed_dependencies = []
12
14
  end
13
15
 
14
16
  def handle_multi_options(options, dependencies = nil)
15
17
  handle_dependencies(dependencies)
16
- options.each { |option| system("bin/rails app:template LOCATION=templates/setup_#{option}.rb") }
18
+
19
+ options.each do |option|
20
+ @installed_commands << option
21
+ system("bin/rails app:template LOCATION=templates/setup_#{option}.rb")
22
+ end
17
23
  end
18
24
 
19
25
  def handle_option(option, dependencies = nil)
26
+ @installed_commands << option
20
27
  handle_dependencies(dependencies)
28
+
21
29
  system("bin/rails app:template LOCATION=templates/setup_#{option}.rb")
22
30
  end
23
31
 
24
32
  def handle_dependencies(dependencies)
25
33
  dependencies&.each do |dependency|
34
+ next if duplicated_gem?(dependency)
35
+
26
36
  puts ">> Dependency Detected: #{dependency} "
37
+ @installed_dependencies << dependency
38
+
27
39
  system("bin/rails app:template LOCATION=templates/setup_#{dependency}.rb")
28
40
  end
29
41
  end
42
+
43
+ private
44
+
45
+ def duplicated_gem?(option)
46
+ @installed_commands.include?(option) || @installed_dependencies.include?(option)
47
+ end
30
48
  end
31
49
  end
32
50
  end
@@ -15,37 +15,52 @@
15
15
  type: "select"
16
16
  required: false
17
17
  -
18
- name: template_engine
18
+ name: end_to_end_testing
19
19
  weight: 4
20
20
  type: "select"
21
21
  required: false
22
22
  -
23
- name: code_quality
23
+ name: template_engine
24
24
  weight: 5
25
25
  type: "select"
26
26
  required: false
27
27
  -
28
- name: background_job
28
+ name: frontend
29
29
  weight: 6
30
30
  type: "select"
31
31
  required: false
32
32
  -
33
- name: security
33
+ name: css_framework
34
34
  weight: 7
35
35
  type: "select"
36
36
  required: false
37
37
  -
38
- name: admin_panel
38
+ name: background_job
39
39
  weight: 8
40
40
  type: "select"
41
41
  required: false
42
42
  -
43
- name: features
43
+ name: code_quality
44
44
  weight: 9
45
+ type: "select"
46
+ required: false
47
+ -
48
+ name: security
49
+ weight: 10
50
+ type: "select"
51
+ required: false
52
+ -
53
+ name: admin_panel
54
+ weight: 11
55
+ type: "select"
56
+ required: false
57
+ -
58
+ name: features
59
+ weight: 12
45
60
  type: "multi_select"
46
61
  required: false
47
62
  -
48
63
  name: development
49
- weight: 10
64
+ weight: 13
50
65
  type: "multi_select"
51
66
  required: false
@@ -125,4 +125,48 @@
125
125
  name: StandartRB
126
126
  category: code_quality
127
127
  description: " Ruby Style Guide, with linter & automatic code fixer. For details: https://github.com/testdouble/standard"
128
+ dependencies: null
129
+ -
130
+ identifier: sassc_rails
131
+ name: Saasc Rails
132
+ category: development
133
+ description: "Integrate SassC-Ruby with Rails! For details: https://github.com/sass/sassc-rails"
134
+ dependencies: null
135
+ -
136
+ identifier: active_admin
137
+ name: ActiveAdmin
138
+ category: admin_panel
139
+ description: "The administration framework for Ruby on Rails applications. For details: https://github.com/activeadmin/activeadmin"
140
+ dependencies:
141
+ - sassc_rails
142
+ - devise
143
+ -
144
+ identifier: minitest
145
+ name: MiniTest ( Default )
146
+ category: testing
147
+ description: "minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking. For details: https://github.com/minitest/minitest"
148
+ dependencies: null
149
+ -
150
+ identifier: capybara
151
+ name: Capybara
152
+ category: end_to_end_testing
153
+ description: "Acceptance test framework for web applications. For details: https://github.com/teamcapybara/capybara"
154
+ dependencies: null
155
+ -
156
+ identifier: stimulus
157
+ name: StimulusJS
158
+ category: frontend
159
+ description: "A modest JavaScript framework for the HTML you already have. For details: https://github.com/hotwired/stimulus"
160
+ dependencies: null
161
+ -
162
+ identifier: react
163
+ name: ReactJS
164
+ category: frontend
165
+ description: "A declarative, efficient, and flexible JavaScript library for building user interfaces. For details: https://github.com/facebook/react/"
166
+ dependencies: null
167
+ -
168
+ identifier: tailwind
169
+ name: Tailwind
170
+ category: css_framework
171
+ description: "A utility-first CSS framework for rapid UI development. For details: https://github.com/tailwindlabs/tailwindcss"
128
172
  dependencies: null
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ run "bundle add activeadmin"
4
+ run "bundle add bcrypt"
5
+ Bundler.with_unbundled_env { run "bundle" }
6
+
7
+ rails_command "generate active_admin:install"
8
+ rails_command "db:migrate"
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ gem_group :development, :test do
4
+ gem "capybara"
5
+ end
6
+
7
+ Bundler.with_unbundled_env { run "bundle install" }
8
+
9
+ if defined? RSpec
10
+ inject_into_file "spec/spec_helper.rb", before: "RSpec.configure do |config|" do
11
+ <<~RB
12
+ require 'capybara/rspec'
13
+ RB
14
+ end
15
+ elsif defined? MiniTest && !defined? RSpec
16
+ inject_into_file "test/test_helper.rb", before: "class ActiveSupport::TestCase" do
17
+ <<~RB
18
+ require 'capybara/rails'
19
+ require 'capybara/minitest'
20
+ RB
21
+ end
22
+ else
23
+ puts "No test framework detected or related test framework does not exist in RailsInteractive"
24
+ end
@@ -5,6 +5,11 @@ Bundler.with_unbundled_env { run "bundle install" }
5
5
 
6
6
  rails_command "generate devise:install"
7
7
 
8
- run "rails generate devise User"
9
- run "rails db:create"
8
+ model_name = ask("What do you want to call your Devise model?")
9
+ model_name = model_name.empty? ? "user" : model_name
10
+
11
+ File.open("devise-model.txt", "w") { |f| f.write(model_name) }
12
+
13
+ run "rails generate devise #{model_name.capitalize}"
14
+ run "rails db:prepare"
10
15
  run "rails db:migrate"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ run "bundle add minitest"
4
+
5
+ Bundler.with_unbundled_env { run "bundle install" }
@@ -1,30 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "fileutils"
4
+
3
5
  run "bundle add omniauth"
4
6
 
5
7
  run "bundle install"
6
8
 
9
+ devise_model_name = File.read("devise-model.txt")
10
+ FileUtils.rm("devise-model.txt")
11
+
7
12
  # rubocop:disable Layout/LineLength
8
- rails_command "generate model identity user:references provider:string:index uid:string:index token:string:index refresh_token:string:index"
13
+ rails_command "generate model identity #{devise_model_name}:references provider:string:index uid:string:index token:string:index refresh_token:string:index"
9
14
  # rubocop:enable Layout/LineLength
10
15
 
11
- rails_command "generate migration AddIdentityToUsers identities_count:integer"
16
+ rails_command "generate migration AddIdentityTo#{devise_model_name.capitalize}s identities_count:integer"
12
17
 
13
18
  rails_command "db:migrate"
14
19
 
15
- inject_into_file "config/routes.rb", after: "devise_for :users\n" do
16
- " # devise_for :users, controllers: { omniauth_callbacks: 'omniauth' }"
20
+ inject_into_file "config/routes.rb", after: "devise_for :#{devise_model_name}s\n" do
21
+ " # devise_for :#{devise_model_name}s, controllers: { omniauth_callbacks: 'omniauth' }"
17
22
  end
18
23
 
19
- inject_into_file "app/models/user.rb", after: ":database_authenticatable, " do
24
+ inject_into_file "app/models/#{devise_model_name}.rb", after: ":database_authenticatable, " do
20
25
  ":omniauthable, "
21
26
  end
22
27
 
23
- inject_into_file "app/models/identity.rb", after: "belongs_to :user" do
28
+ inject_into_file "app/models/identity.rb", after: "belongs_to :#{devise_model_name}" do
24
29
  ", counter_cache: true"
25
30
  end
26
31
 
27
- inject_into_file "app/models/user.rb", after: "class User < ApplicationRecord\n" do
32
+ inject_into_file "app/models/#{devise_model_name}.rb",
33
+ after: "class #{devise_model_name.capitalize} < ApplicationRecord\n" do
28
34
  # rubocop:disable Naming/HeredocDelimiterNaming
29
35
  <<-EOF
30
36
  has_many :identities, dependent: :destroy
@@ -36,15 +42,15 @@ inject_into_file "app/models/user.rb", after: "class User < ApplicationRecord\n"
36
42
  identity.token = auth.credentials.token
37
43
  identity.refresh_token = auth.credentials.refresh_token
38
44
  end
39
- if identity.user.nil? && auth.info.email.present?
40
- user = User.where(email: auth.info.email).first_or_initialize
45
+ if identity.#{devise_model_name}.nil? && auth.info.email.present?
46
+ user = #{devise_model_name}.where(email: auth.info.email).first_or_initialize
41
47
  user.name = auth.info.name
42
48
  user.password = Devise.friendly_token if user.new_record?
43
49
  user.save!
44
- identity.user = user
50
+ identity.#{devise_model_name} = user
45
51
  end
46
52
  identity.save!
47
- identity.user
53
+ identity.#{devise_model_name}
48
54
  end
49
55
  end
50
56
 
@@ -57,5 +63,6 @@ file "app/controllers/omniauth_controller.rb", <<~CODE
57
63
 
58
64
  end
59
65
  CODE
60
-
61
- puts "IMPORTANT: Add devise_for :users, controllers: { omniauth_callbacks: 'omniauth' } to your routes.rb"
66
+ # rubocop:disable Layout/LineLength
67
+ puts "IMPORTANT: Add devise_for :#{devise_model_name}s, controllers: { omniauth_callbacks: 'omniauth' } to your routes.rb"
68
+ # rubocop:enable Layout/LineLength
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ # NPM
4
+ run "yarn init -y"
5
+ run "yarn add esbuild react react-dom"
6
+
7
+ # rubocop:disable Layout/LineLength
8
+ run "npm set-script build 'esbuild app/javascript/*.* --bundle --sourcemap --loader:.js=jsx --outdir=app/assets/javascripts'"
9
+ # rubocop:enable Layout/LineLength
10
+ #
11
+ # Foreman
12
+ run "gem install foreman"
13
+ run 'echo "#!/usr/bin/env bash\nforeman start -f Procfile.dev "$@"" > bin/dev'
14
+ run "echo 'web: bin/rails server -p 3000\njs: yarn build --watch' > Procfile.dev"
15
+ run "chmod u+x bin/dev"
16
+
17
+ # Component Helper from Ruby on Rails
18
+ inject_into_file "app/helpers/application_helper.rb", after: "module ApplicationHelper" do
19
+ <<~RB
20
+
21
+ def react_component(component_name, **props)
22
+ tag.div(data: {
23
+ react_component: component_name,
24
+ props: props.to_json
25
+ }) { '' }
26
+ end
27
+ RB
28
+ end
29
+
30
+ # Include JS to application.html.erb
31
+ inject_into_file "app/views/layouts/application.html.erb", after: "<%= javascript_importmap_tags %>" do
32
+ <<~ERB
33
+
34
+ <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
35
+ ERB
36
+ end
37
+
38
+ # Component Mounter for JS
39
+ create_file "app/javascript/mount.js" do
40
+ <<~JAVASCRIPT
41
+ import React from 'react';
42
+ import ReactDOM from 'react-dom';
43
+
44
+ export default function mount(components = {}) {
45
+ const mountPoints = document.querySelectorAll('[data-react-component]');
46
+ mountPoints.forEach((mountPoint) => {
47
+ const { dataset } = mountPoint;
48
+ const componentName = dataset.reactComponent;
49
+ const Component = components[componentName];
50
+
51
+ if (Component) {
52
+ const props = JSON.parse(dataset.props);
53
+ ReactDOM.render(<Component {...props} />, mountPoint);
54
+ }
55
+ });
56
+ }
57
+ JAVASCRIPT
58
+ end
59
+
60
+ # Example React Component
61
+ create_file "app/javascript/components/hello.jsx" do
62
+ <<~JAVASCRIPT
63
+ import React from "react";
64
+
65
+ const Hello = () => <div>HELLO WORLD!</div>
66
+
67
+ export default Hello;
68
+ JAVASCRIPT
69
+ end
70
+
71
+ # rubocop:disable Layout/LineLength
72
+ # Application JS file update
73
+ inject_into_file "app/javascript/application.js",
74
+ after: "// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails" do
75
+ <<~JAVASCRIPT
76
+
77
+ // Components
78
+ import Hello from "./components/hello"
79
+
80
+ // Component Mounter
81
+ import mount from './mount'
82
+
83
+ // Mount Components
84
+ mount({ Hello });
85
+ JAVASCRIPT
86
+ end
87
+ # rubocop:enable Layout/LineLength
88
+
89
+ run "yarn build"
90
+
91
+ # Example Page for Component Test
92
+ rails_command "g controller Home index"
93
+ inject_into_file "app/views/home/index.html.erb", after: "<p>Find me in app/views/home/index.html.erb</p>" do
94
+ <<~ERB
95
+
96
+ <%= react_component "Hello" %>
97
+ ERB
98
+ end
99
+
100
+ puts "React is installed! You can run bin/dev then go to home/index and see the Hello World component."
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ run "bundle add sassc-rails"
4
+ Bundler.with_unbundled_env { run "bundle" }
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ run "bundle add turbo-rails"
4
+ run "bundle add stimulus-rails"
5
+
6
+ Bundler.with_unbundled_env { run "bundle install" }
7
+
8
+ rails_command "turbo:install stimulus:install"
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ def package?(package)
4
+ require "json"
5
+
6
+ file = File.open("package.json") if File.file?("package.json")
7
+
8
+ packages = JSON.parse(file.read) if file
9
+
10
+ packages["dependencies"].include?(package) if packages
11
+ end
12
+
13
+ run "bundle add tailwindcss-rails"
14
+
15
+ if package?("react")
16
+ run "rm Procfile.dev"
17
+ run "rm bin/dev"
18
+ end
19
+
20
+ rails_command "tailwindcss:install"
21
+
22
+ if package?("react")
23
+ run "rm Procfile.dev"
24
+ run "echo 'web: bin/rails server -p 3000\njs: yarn build --watch\ncss: bin/rails tailwindcss:watch' > Procfile.dev"
25
+ end
data/lib/cli/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RailsInteractive
4
4
  class CLI
5
- VERSION = "2.1.0"
5
+ VERSION = "2.1.3"
6
6
  end
7
7
  end
@@ -63,7 +63,7 @@ module RailsInteractive
63
63
 
64
64
  @inputs.first(3).each { |_key, value| cmd += "#{value} " unless value.empty? }
65
65
 
66
- "#{base} #{cmd} -q"
66
+ "#{base} #{cmd} -q --skip-hotwire"
67
67
  end
68
68
 
69
69
  def create_project
@@ -72,7 +72,7 @@ module RailsInteractive
72
72
  # Create project
73
73
  system(setup)
74
74
  # Install gems
75
- intall_gems
75
+ install_gems
76
76
  # Prepare project requirements and give instructions
77
77
  Utils.sign_project
78
78
  Message.prepare
@@ -95,19 +95,21 @@ module RailsInteractive
95
95
  list
96
96
  end
97
97
 
98
- def intall_gems
98
+ def install_gems
99
99
  # Copy template files to project folder
100
100
  Utils.copy_templates_to_project(@inputs[:name])
101
101
 
102
102
  @inputs.each do |key, value|
103
103
  next if %i[name type database].include?(key) || value.is_a?(Array) && value.empty? || value.nil?
104
104
 
105
- dependencies = @commands.dependencies(value)
106
-
105
+ dependencies ||= @commands.dependencies(value)
107
106
  @handler.handle_multi_options(value, dependencies) if value.is_a?(Array)
108
107
  @handler.handle_option(value, dependencies) if value.is_a?(String)
109
108
  end
110
109
 
110
+ # Prepare database for project everytime
111
+ system("bin/rails db:prepare")
112
+
111
113
  # Remove templates folder from project folder
112
114
  Utils.remove_templates(@inputs[:name])
113
115
  end
@@ -126,5 +128,12 @@ module RailsInteractive
126
128
 
127
129
  @inputs[:database] = Prompt.new("Database: ", "select", database_types, required: true).perform
128
130
  end
131
+
132
+ def admin_panel
133
+ admin_panel = { "ActiveAdmin" => "active_admin" }
134
+
135
+ @inputs[:admin_panel] =
136
+ Prompt.new("Choose project admin panel: ", "select", admin_panel).perform
137
+ end
129
138
  end
130
139
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-interactive
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oguzhan Ince
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-30 00:00:00.000000000 Z
11
+ date: 2022-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -170,12 +170,14 @@ files:
170
170
  - lib/cli/config/commands.yml
171
171
  - lib/cli/message.rb
172
172
  - lib/cli/prompt.rb
173
+ - lib/cli/templates/setup_active_admin.rb
173
174
  - lib/cli/templates/setup_avo.rb
174
175
  - lib/cli/templates/setup_awesome_print.rb
175
176
  - lib/cli/templates/setup_better_errors.rb
176
177
  - lib/cli/templates/setup_brakeman.rb
177
178
  - lib/cli/templates/setup_bullet.rb
178
179
  - lib/cli/templates/setup_cancancan.rb
180
+ - lib/cli/templates/setup_capybara.rb
179
181
  - lib/cli/templates/setup_devise.rb
180
182
  - lib/cli/templates/setup_faker.rb
181
183
  - lib/cli/templates/setup_friendly_id.rb
@@ -183,14 +185,19 @@ files:
183
185
  - lib/cli/templates/setup_haml.rb
184
186
  - lib/cli/templates/setup_kaminari.rb
185
187
  - lib/cli/templates/setup_letter_opener.rb
188
+ - lib/cli/templates/setup_minitest.rb
186
189
  - lib/cli/templates/setup_omniauth.rb
187
190
  - lib/cli/templates/setup_pundit.rb
188
191
  - lib/cli/templates/setup_rails_admin.rb
192
+ - lib/cli/templates/setup_react.rb
189
193
  - lib/cli/templates/setup_rspec.rb
190
194
  - lib/cli/templates/setup_rubocop.rb
195
+ - lib/cli/templates/setup_sassc_rails.rb
191
196
  - lib/cli/templates/setup_sidekiq.rb
192
197
  - lib/cli/templates/setup_slim.rb
193
198
  - lib/cli/templates/setup_standardrb.rb
199
+ - lib/cli/templates/setup_stimulus.rb
200
+ - lib/cli/templates/setup_tailwind.rb
194
201
  - lib/cli/utils.rb
195
202
  - lib/cli/version.rb
196
203
  - lib/rails_interactive.rb