inertia_rails-contrib 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -1
  3. data/README.md +14 -6
  4. data/lib/generators/inertia/install/frameworks.yml +39 -7
  5. data/lib/generators/inertia/install/helpers.rb +7 -1
  6. data/lib/generators/inertia/install/install_generator.rb +84 -17
  7. data/lib/generators/inertia/install/templates/react/InertiaExample.tsx +60 -0
  8. data/lib/generators/inertia/install/templates/react/inertia.ts +36 -0
  9. data/lib/generators/inertia/install/templates/react/tsconfig.app.json +27 -0
  10. data/lib/generators/inertia/install/templates/react/tsconfig.json +11 -0
  11. data/lib/generators/inertia/install/templates/react/tsconfig.node.json +13 -0
  12. data/lib/generators/inertia/install/templates/react/vite-env.d.ts +1 -0
  13. data/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte +116 -0
  14. data/lib/generators/inertia/install/templates/svelte/inertia.js +4 -5
  15. data/lib/generators/inertia/install/templates/svelte/inertia.ts +32 -0
  16. data/lib/generators/inertia/install/templates/svelte/tsconfig.json +21 -0
  17. data/lib/generators/inertia/install/templates/svelte/tsconfig.node.json +12 -0
  18. data/lib/generators/inertia/install/templates/svelte/vite-env.d.ts +2 -0
  19. data/lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue +117 -0
  20. data/lib/generators/inertia/install/templates/vue/inertia.js +1 -1
  21. data/lib/generators/inertia/install/templates/vue/inertia.ts +33 -0
  22. data/lib/generators/inertia/install/templates/vue/tsconfig.app.json +24 -0
  23. data/lib/generators/inertia/install/templates/vue/tsconfig.json +11 -0
  24. data/lib/generators/inertia/install/templates/vue/tsconfig.node.json +22 -0
  25. data/lib/generators/inertia/install/templates/vue/vite-env.d.ts +1 -0
  26. data/lib/inertia_rails_contrib/generators_helper.rb +1 -1
  27. data/lib/inertia_rails_contrib/version.rb +1 -1
  28. metadata +20 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9bf363cb43e7bd6c98bcd4ca6b3538e09927f61f5687553c44a3df5a347c3e1
4
- data.tar.gz: 31345ef902abb988dc50540f5bfc110fa392b94cb0a7d82c10dfa6a36cd4ca96
3
+ metadata.gz: 918249a8473355fbcec2ce48a47c56a468601587623ff25a684b9d168f3405e1
4
+ data.tar.gz: 06a83350918c230d4006b8be40a763a444d26d8aee7133967342d4f5bcb77e27
5
5
  SHA512:
6
- metadata.gz: bc56d3c96c345caafbdafbf8b46c9b2d6b58d3f710f032a3127a2954df38f2453824c61d585959e751d97724b0d9612c884b3fedabacb1fded37c8b45c14e0bd
7
- data.tar.gz: 5af321921aad351f9be524c9d533c44c5db0d359b0646e8b48abba9581e8803e7ab15eb7e8a82d7c3bf39e8065e0f987ad13735ae64731976b8f70c4a8c68310
6
+ metadata.gz: 53145888f043896709756bc40a08c86c7d57e947952d3ec0f84040ec766695c6b0815f1d13ed74301fd7c5a6e93b62bc9cf455b444e2607e517d90c4e38d6ed4
7
+ data.tar.gz: d7986308cd3c945a3ac65ff44b363dd56c11bb1c8f2dda893fbfdcc7e2e71a6e6d0b0478c239f30722afed4f2528ee5dc49b619c717f30945392f39581bef6d7
data/CHANGELOG.md CHANGED
@@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning].
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.2] - 2024-10-09
11
+
12
+ Added:
13
+
14
+ - TypeScript support for the installation generator ([@skryukov])
15
+ Note that it doesn't include scaffold templates yet.
16
+
17
+ - New `--inertia-version` option for the installation generator ([@skryukov])
18
+ This allows you to specify the Inertia.js version to install.
19
+
20
+ - Support `tailwind.config.ts` for Tailwind CSS template guessing ([@Shaglock])
21
+
22
+ Fixed:
23
+
24
+ - Correct examples for default layouts in inertia entrypoints ([@skryukov])
25
+ - Inertia attribute added to the head tag in the layout for vue ([@skryukov])
26
+ - Remove duplicate `vite_stylesheet_tag` when Tailwind CSS is installed ([@skryukov])
27
+
28
+ ## [0.2.1] - 2024-08-11
29
+
30
+ Added:
31
+
32
+ - Support `pnpm` package manager ([@skryukov])
33
+ - New `--verbose` option for the installation generator ([@skryukov])
34
+
35
+ Fixed:
36
+
37
+ - Support installation alongside Webpacker ([@skryukov])
38
+
10
39
  ## [0.2.0] - 2024-08-10
11
40
 
12
41
  Added:
@@ -30,9 +59,12 @@ Added:
30
59
  - Initial release ([@iurev], [@skryukov])
31
60
 
32
61
  [@iurev]: https://github.com/iurev
62
+ [@Shaglock]: https://github.com/Shaglock
33
63
  [@skryukov]: https://github.com/skryukov
34
64
 
35
- [Unreleased]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.0...HEAD
65
+ [Unreleased]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.2...HEAD
66
+ [0.2.2]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.1...v0.2.2
67
+ [0.2.1]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.0...v0.2.1
36
68
  [0.2.0]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.1.1...v0.2.0
37
69
  [0.1.1]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.1.0...v0.1.1
38
70
  [0.1.0]: https://github.com/skryukov/inertia_rails-contrib/commits/v0.1.0
data/README.md CHANGED
@@ -48,6 +48,10 @@ Would you like to install Vite Ruby? (y/n) y
48
48
  Vite Rails gem successfully installed
49
49
  run bundle exec vite install from "."
50
50
  Vite Rails successfully installed
51
+ Would you like to use TypeScript? (y/n) y
52
+ Adding TypeScript support
53
+ What framework do you want to use with Inertia? [react, vue, svelte] (react)
54
+ run npm add @types/react @types/react-dom typescript --silent from "."
51
55
  Would you like to install Tailwind CSS? (y/n) y
52
56
  Installing Tailwind CSS
53
57
  run npm add tailwindcss postcss autoprefixer @tailwindcss/forms @tailwindcss/typography @tailwindcss/container-queries --silent from "."
@@ -59,14 +63,14 @@ Adding Tailwind CSS to the application layout
59
63
  Adding Inertia's Rails adapter initializer
60
64
  create config/initializers/inertia_rails.rb
61
65
  Installing Inertia npm packages
62
- What framework do you want to use with Inertia? [react, vue, svelte] (react)
63
- run npm add @inertiajs/react react react-dom @vitejs/plugin-react --silent from "."
66
+ run npm add @vitejs/plugin-react react react-dom --silent from "."
67
+ run npm add @inertiajs/react@latest --silent from "."
64
68
  Adding Vite plugin for react
65
69
  insert vite.config.ts
66
70
  prepend vite.config.ts
67
- Copying inertia.js entrypoint
68
- create app/frontend/entrypoints/inertia.js
69
- Adding inertia.js script tag to the application layout
71
+ Copying inertia.ts entrypoint
72
+ create app/frontend/entrypoints/inertia.ts
73
+ Adding inertia.ts script tag to the application layout
70
74
  insert app/views/layouts/application.html.erb
71
75
  Adding Vite React Refresh tag to the application layout
72
76
  insert app/views/layouts/application.html.erb
@@ -76,11 +80,15 @@ Copying example Inertia controller
76
80
  Adding a route for the example Inertia controller
77
81
  route get 'inertia-example', to: 'inertia_example#index'
78
82
  Copying page assets
79
- create app/frontend/pages/InertiaExample.jsx
80
83
  create app/frontend/pages/InertiaExample.module.css
81
84
  create app/frontend/assets/react.svg
82
85
  create app/frontend/assets/inertia.svg
83
86
  create app/frontend/assets/vite_ruby.svg
87
+ create app/frontend/pages/InertiaExample.tsx
88
+ create tsconfig.json
89
+ create tsconfig.app.json
90
+ create tsconfig.node.json
91
+ create app/frontend/vite-env.d.ts
84
92
  Copying bin/dev
85
93
  create bin/dev
86
94
  Inertia's Rails adapter successfully installed
@@ -1,41 +1,73 @@
1
1
  react:
2
+ inertia_package: "@inertiajs/react"
2
3
  packages:
3
- - "@inertiajs/react"
4
+ - "@vitejs/plugin-react"
4
5
  - "react"
5
6
  - "react-dom"
6
- - "@vitejs/plugin-react"
7
+ packages_ts:
8
+ - "@types/react"
9
+ - "@types/react-dom"
10
+ - "typescript"
7
11
  vite_plugin_import: "import react from '@vitejs/plugin-react'"
8
12
  vite_plugin_call: "react()"
9
- copy_files:
13
+ copy_files_ts:
14
+ "InertiaExample.tsx": "%{js_destination_path}/pages/InertiaExample.tsx"
15
+ "tsconfig.json": "tsconfig.json"
16
+ "tsconfig.app.json": "tsconfig.app.json"
17
+ "tsconfig.node.json": "tsconfig.node.json"
18
+ "vite-env.d.ts": "%{js_destination_path}/vite-env.d.ts"
19
+ copy_files_js:
10
20
  "InertiaExample.jsx": "%{js_destination_path}/pages/InertiaExample.jsx"
21
+ copy_files:
11
22
  "InertiaExample.module.css": "%{js_destination_path}/pages/InertiaExample.module.css"
12
23
  "../assets/react.svg": "%{js_destination_path}/assets/react.svg"
13
24
  "../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
14
25
  "../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
15
26
 
16
27
  vue:
28
+ inertia_package: "@inertiajs/vue3"
17
29
  packages:
18
- - "@inertiajs/vue3"
19
30
  - "vue"
20
31
  - "@vitejs/plugin-vue"
32
+ packages_ts:
33
+ - "typescript"
34
+ - "vue-tsc"
21
35
  vite_plugin_import: "import vue from '@vitejs/plugin-vue'"
22
36
  vite_plugin_call: "vue()"
23
37
  copy_files:
24
- "InertiaExample.vue": "%{js_destination_path}/pages/InertiaExample.vue"
25
38
  "../assets/vue.svg": "%{js_destination_path}/assets/vue.svg"
26
39
  "../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
27
40
  "../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
41
+ copy_files_ts:
42
+ "InertiaExample.ts.vue": "%{js_destination_path}/pages/InertiaExample.vue"
43
+ "tsconfig.json": "tsconfig.json"
44
+ "tsconfig.app.json": "tsconfig.app.json"
45
+ "tsconfig.node.json": "tsconfig.node.json"
46
+ "vite-env.d.ts": "%{js_destination_path}/vite-env.d.ts"
47
+ copy_files_js:
48
+ "InertiaExample.vue": "%{js_destination_path}/pages/InertiaExample.vue"
28
49
 
29
50
  svelte:
51
+ inertia_package: "@inertiajs/svelte"
30
52
  packages:
31
- - "@inertiajs/svelte"
32
53
  - "svelte"
33
54
  - "@sveltejs/vite-plugin-svelte"
55
+ packages_ts:
56
+ - "@tsconfig/svelte"
57
+ - "svelte-check"
58
+ - "typescript"
59
+ - "tslib"
34
60
  vite_plugin_import: "import { svelte } from '@sveltejs/vite-plugin-svelte'"
35
61
  vite_plugin_call: "svelte()"
62
+ copy_files_ts:
63
+ "InertiaExample.ts.svelte": "%{js_destination_path}/pages/InertiaExample.svelte"
64
+ "tsconfig.json": "tsconfig.json"
65
+ "tsconfig.node.json": "tsconfig.node.json"
66
+ "vite-env.d.ts": "%{js_destination_path}/vite-env.d.ts"
67
+ copy_files_js:
68
+ "InertiaExample.svelte": "%{js_destination_path}/pages/InertiaExample.svelte"
36
69
  copy_files:
37
70
  "svelte.config.js": "svelte.config.js"
38
- "InertiaExample.svelte": "%{js_destination_path}/pages/InertiaExample.svelte"
39
71
  "../assets/svelte.svg": "%{js_destination_path}/assets/svelte.svg"
40
72
  "../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
41
73
  "../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
@@ -3,7 +3,13 @@ module Inertia
3
3
  module Helpers
4
4
  ### FS Helpers
5
5
  def js_destination_path
6
- defined?(ViteRuby) ? ViteRuby.config.source_code_dir : "app/frontend"
6
+ return ViteRuby.config.source_code_dir if defined?(ViteRuby)
7
+ if file?("config/vite.json")
8
+ source_code_dir = JSON.parse(File.read(file_path("config/vite.json"))).dig("all", "sourceCodeDir")
9
+ return source_code_dir if source_code_dir
10
+ end
11
+
12
+ "app/frontend"
7
13
  end
8
14
 
9
15
  def js_destination_root
@@ -18,7 +18,13 @@ module Inertia
18
18
  enum: FRAMEWORKS.keys,
19
19
  default: nil
20
20
 
21
- class_option :package_manager, type: :string, default: nil, enum: %w[npm yarn bun],
21
+ class_option :inertia_version, type: :string, default: "latest",
22
+ desc: "The version of Inertia.js to install"
23
+
24
+ class_option :typescript, type: :boolean, default: false,
25
+ desc: "Whether to use TypeScript"
26
+
27
+ class_option :package_manager, type: :string, default: nil, enum: %w[npm yarn bun pnpm],
22
28
  desc: "The package manager you want to use to install Inertia's npm packages"
23
29
 
24
30
  class_option :interactive, type: :boolean, default: true,
@@ -31,13 +37,23 @@ module Inertia
31
37
  class_option :example_page, type: :boolean, default: true,
32
38
  desc: "Whether to add an example Inertia page"
33
39
 
40
+ class_option :verbose, type: :boolean, default: false,
41
+ desc: "Run the generator in verbose mode"
42
+
34
43
  remove_class_option :skip_namespace, :skip_collision_check
35
44
 
36
45
  def install
37
46
  say "Installing Inertia's Rails adapter"
38
47
 
48
+ if inertia_resolved_version.version == "0"
49
+ say_error "Could not find the Inertia.js package version #{options[:inertia_version]}.", :red
50
+ exit(false)
51
+ end
52
+
39
53
  install_vite unless ruby_vite_installed?
40
54
 
55
+ install_typescript if typescript?
56
+
41
57
  install_tailwind if install_tailwind?
42
58
 
43
59
  install_inertia
@@ -46,7 +62,7 @@ module Inertia
46
62
 
47
63
  say "Copying bin/dev"
48
64
  copy_file "#{__dir__}/templates/dev", "bin/dev"
49
- chmod "bin/dev", 0o755, verbose: false
65
+ chmod "bin/dev", 0o755, verbose: verbose?
50
66
 
51
67
  say "Inertia's Rails adapter successfully installed", :green
52
68
  end
@@ -59,6 +75,7 @@ module Inertia
59
75
 
60
76
  say "Installing Inertia npm packages"
61
77
  add_packages(*FRAMEWORKS[framework]["packages"])
78
+ add_packages(inertia_package)
62
79
 
63
80
  unless File.read(vite_config_path).include?(FRAMEWORKS[framework]["vite_plugin_import"])
64
81
  say "Adding Vite plugin for #{framework}"
@@ -66,34 +83,45 @@ module Inertia
66
83
  prepend_file vite_config_path, "#{FRAMEWORKS[framework]["vite_plugin_import"]}\n"
67
84
  end
68
85
 
69
- say "Copying inertia.js entrypoint"
70
- template "#{framework}/inertia.js", js_file_path("entrypoints/inertia.js")
86
+ say "Copying #{inertia_entrypoint} entrypoint"
87
+ template "#{framework}/#{inertia_entrypoint}", js_file_path("entrypoints/#{inertia_entrypoint}")
71
88
 
72
89
  if application_layout.exist?
73
- say "Adding inertia.js script tag to the application layout"
90
+ say "Adding #{inertia_entrypoint} script tag to the application layout"
74
91
  headers = <<-ERB
75
- <%= vite_javascript_tag "inertia" %>
92
+ <%= #{vite_tag} "inertia" %>
76
93
  <%= inertia_headers %>
77
94
  ERB
78
- headers += "\n <%= vite_stylesheet_tag \"application\" %>" if install_tailwind?
79
-
80
95
  insert_into_file application_layout.to_s, headers, after: "<%= vite_client_tag %>\n"
81
96
 
82
97
  if framework == "react" && !application_layout.read.include?("vite_react_refresh_tag")
83
98
  say "Adding Vite React Refresh tag to the application layout"
84
99
  insert_into_file application_layout.to_s, "<%= vite_react_refresh_tag %>\n ", before: "<%= vite_client_tag %>"
85
- gsub_file application_layout.to_s, /<title>/, "<title inertia>"
86
100
  end
101
+
102
+ gsub_file application_layout.to_s, /<title>/, "<title inertia>" if framework != "svelte"
87
103
  else
88
104
  say_error "Could not find the application layout file. Please add the following tags manually:", :red
89
105
  say_error "- <title>...</title>"
90
106
  say_error "+ <title inertia>...</title>"
91
107
  say_error "+ <%= inertia_headers %>"
92
108
  say_error "+ <%= vite_react_refresh_tag %>" if framework == "react"
93
- say_error "+ <%= vite_javascript_tag \"inertia\" %>"
109
+ say_error "+ <%= #{vite_tag} \"inertia\" %>"
94
110
  end
95
111
  end
96
112
 
113
+ def install_typescript
114
+ say "Adding TypeScript support"
115
+ if framework == "svelte" && inertia_resolved_version.release < Gem::Version.new("1.3.0")
116
+ say "WARNING: @inertiajs/svelte < 1.3.0 does not support TypeScript (resolved version: #{inertia_resolved_version}).", :yellow
117
+ say "Skipping TypeScript support for @inertiajs/svelte", :yellow
118
+ @typescript = false
119
+ return
120
+ end
121
+
122
+ add_packages(*FRAMEWORKS[framework]["packages_ts"])
123
+ end
124
+
97
125
  def install_example_page
98
126
  say "Copying example Inertia controller"
99
127
  template "controller.rb", file_path("app/controllers/inertia_example_controller.rb")
@@ -102,7 +130,8 @@ module Inertia
102
130
  route "get 'inertia-example', to: 'inertia_example#index'"
103
131
 
104
132
  say "Copying page assets"
105
- FRAMEWORKS[framework]["copy_files"].each do |source, destination|
133
+ copy_files = FRAMEWORKS[framework]["copy_files"].merge(FRAMEWORKS[framework]["copy_files_#{typescript? ? "ts" : "js"}"])
134
+ copy_files.each do |source, destination|
106
135
  template "#{framework}/#{source}", file_path(destination % {js_destination_path: js_destination_path})
107
136
  end
108
137
  end
@@ -132,14 +161,14 @@ module Inertia
132
161
 
133
162
  in_root do
134
163
  Bundler.with_original_env do
135
- if (capture = run("bundle add vite_rails", capture: true))
164
+ if (capture = run("bundle add vite_rails", capture: !verbose?))
136
165
  say "Vite Rails gem successfully installed", :green
137
166
  else
138
167
  say capture
139
168
  say_error "Failed to install Vite Rails gem", :red
140
169
  exit(false)
141
170
  end
142
- if (capture = run("bundle exec vite install", capture: true))
171
+ if (capture = run("bundle exec vite install", capture: !verbose?))
143
172
  say "Vite Rails successfully installed", :green
144
173
  else
145
174
  say capture
@@ -155,12 +184,22 @@ module Inertia
155
184
 
156
185
  if package_manager.nil?
157
186
  say_status "Could not find a package.json file to install Inertia to.", nil
187
+ elsif gem_installed?("webpacker") || gem_installed?("shakapacker")
188
+ say "Webpacker or Shakapacker is installed.", :yellow
189
+ say "Vite Ruby can work alongside Webpacker or Shakapacker, but it might cause issues.", :yellow
190
+ say "Please see the Vite Ruby documentation for the migration guide:", :yellow
191
+ say "https://vite-ruby.netlify.app/guide/migration.html#webpacker-%F0%9F%93%A6", :yellow
158
192
  else
159
- say_status "Could not find a Vite configuration files (`config/vite.json` & `vite.config.{ts,js,mjs,cjs}`).", nil
193
+ say_status "Could not find a Vite configuration files (`config/vite.json` & `vite.config.{ts,js,mjs,cjs,mts,cts}`).", nil
160
194
  end
161
195
  false
162
196
  end
163
197
 
198
+ def gem_installed?(name)
199
+ regex = /^[^#]*gem\s+['"]#{name}['"]/
200
+ File.read(file_path("Gemfile")).match?(regex)
201
+ end
202
+
164
203
  def application_layout
165
204
  @application_layout ||= Pathname.new(file_path("app/views/layouts/application.html.erb"))
166
205
  end
@@ -175,7 +214,7 @@ module Inertia
175
214
 
176
215
  def add_packages(*packages)
177
216
  in_root do
178
- run "#{package_manager} add #{packages.join(" ")} --silent"
217
+ run "#{package_manager} add #{packages.join(" ")} #{verbose? ? "" : "--silent"}"
179
218
  end
180
219
  end
181
220
 
@@ -184,15 +223,17 @@ module Inertia
184
223
 
185
224
  if file?("package-lock.json")
186
225
  "npm"
187
- elsif file?("bun.config.js") || file?("bun.lockb")
226
+ elsif file?("bun.lockb")
188
227
  "bun"
228
+ elsif file?("pnpm-lock.yaml")
229
+ "pnpm"
189
230
  else
190
231
  "yarn"
191
232
  end
192
233
  end
193
234
 
194
235
  def vite_config_path
195
- @vite_config_path ||= Dir.glob(file_path("vite.config.{ts,js,mjs,cjs}")).first
236
+ @vite_config_path ||= Dir.glob(file_path("vite.config.{ts,js,mjs,cjs,mts,cts}")).first
196
237
  end
197
238
 
198
239
  def install_vite?
@@ -207,6 +248,32 @@ module Inertia
207
248
  @install_tailwind = options[:install_tailwind] || yes?("Would you like to install Tailwind CSS? (y/n)", :green)
208
249
  end
209
250
 
251
+ def typescript?
252
+ return @typescript if defined?(@typescript)
253
+
254
+ @typescript = options[:typescript] || yes?("Would you like to use TypeScript? (y/n)", :green)
255
+ end
256
+
257
+ def inertia_entrypoint
258
+ "inertia.#{typescript? ? "ts" : "js"}"
259
+ end
260
+
261
+ def vite_tag
262
+ typescript? ? "vite_typescript_tag" : "vite_javascript_tag"
263
+ end
264
+
265
+ def inertia_resolved_version
266
+ @inertia_resolved_version ||= Gem::Version.new(`npm show @inertiajs/core@#{options[:inertia_version]} version`.strip)
267
+ end
268
+
269
+ def verbose?
270
+ options[:verbose]
271
+ end
272
+
273
+ def inertia_package
274
+ "#{FRAMEWORKS[framework]["inertia_package"]}@#{options[:inertia_version]}"
275
+ end
276
+
210
277
  def framework
211
278
  @framework ||= options[:framework] || ask("What framework do you want to use with Inertia?", :green, limited_to: FRAMEWORKS.keys, default: "react")
212
279
  end
@@ -0,0 +1,60 @@
1
+ import { Head } from '@inertiajs/react'
2
+ import { useState } from 'react'
3
+
4
+ import reactSvg from '/assets/react.svg'
5
+ import inertiaSvg from '/assets/inertia.svg'
6
+ import viteRubySvg from '/assets/vite_ruby.svg'
7
+
8
+ import cs from './InertiaExample.module.css'
9
+
10
+ export default function InertiaExample({ name }: { name: string }) {
11
+ const [count, setCount] = useState(0)
12
+
13
+ return (
14
+ <>
15
+ <Head title="Inertia + Vite Ruby + React Example" />
16
+
17
+ <div className={cs.root}>
18
+ <h1 className={cs.h1}>Hello {name}!</h1>
19
+
20
+ <div>
21
+ <a href="https://inertia-rails.netlify.app" target="_blank">
22
+ <img className={cs.logo} src={inertiaSvg} alt="Inertia logo" />
23
+ </a>
24
+ <a href="https://vite-ruby.netlify.app" target="_blank">
25
+ <img
26
+ className={`${cs.logo} ${cs.vite}`}
27
+ src={viteRubySvg}
28
+ alt="Vite Ruby logo"
29
+ />
30
+ </a>
31
+ <a href="https://react.dev" target="_blank">
32
+ <img
33
+ className={`${cs.logo} ${cs.react}`}
34
+ src={reactSvg}
35
+ alt="React logo"
36
+ />
37
+ </a>
38
+ </div>
39
+
40
+ <h2 className={cs.h2}>Inertia + Vite Ruby + React</h2>
41
+
42
+ <div className="card">
43
+ <button
44
+ className={cs.button}
45
+ onClick={() => setCount((count) => count + 1)}
46
+ >
47
+ count is {count}
48
+ </button>
49
+ <p>
50
+ Edit <code>app/frontend/pages/InertiaExample.jsx</code> and save to
51
+ test HMR
52
+ </p>
53
+ </div>
54
+ <p className={cs.readTheDocs}>
55
+ Click on the Inertia, Vite Ruby, and React logos to learn more
56
+ </p>
57
+ </div>
58
+ </>
59
+ )
60
+ }
@@ -0,0 +1,36 @@
1
+ import { createInertiaApp } from '@inertiajs/react'
2
+ import { createElement, ReactNode } from 'react'
3
+ import { createRoot } from 'react-dom/client'
4
+
5
+ type Component = { default: ReactNode & { layout?: (page: ReactNode) => ReactNode } }
6
+
7
+ createInertiaApp({
8
+ // Set default page title
9
+ // see https://inertia-rails.netlify.app/guide/title-and-meta
10
+ //
11
+ // title: title => title ? `${title} - App` : 'App',
12
+
13
+ // Disable progress bar
14
+ //
15
+ // see https://inertia-rails.netlify.app/guide/progress-indicators
16
+ // progress: false,
17
+
18
+ resolve: (name) => {
19
+ const pages = import.meta.glob('../pages/**/*.tsx', { eager: true })
20
+ return pages[`../pages/${name}.tsx`] as Component
21
+
22
+ // To use a default layout, import the Layout component
23
+ // and use the following lines.
24
+ // see https://inertia-rails.netlify.app/guide/pages#default-layouts
25
+ //
26
+ // const page = pages[`../pages/${name}.tsx`] as Component
27
+ // page.default.layout ||= (page) => createElement(Layout, null, page)
28
+ // return page
29
+ },
30
+
31
+ setup({ el, App, props }) {
32
+ const root = createRoot(el)
33
+
34
+ root.render(createElement(App, props))
35
+ },
36
+ })
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
5
+ "target": "ES2020",
6
+ "useDefineForClassFields": true,
7
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
8
+ "module": "ESNext",
9
+ "skipLibCheck": true,
10
+
11
+ /* Bundler mode */
12
+ "moduleResolution": "bundler",
13
+ "allowImportingTsExtensions": true,
14
+ "resolveJsonModule": true,
15
+ "isolatedModules": true,
16
+ "moduleDetection": "force",
17
+ "noEmit": true,
18
+ "jsx": "react-jsx",
19
+
20
+ /* Linting */
21
+ "strict": true,
22
+ "noUnusedLocals": true,
23
+ "noUnusedParameters": true,
24
+ "noFallthroughCasesInSwitch": true,
25
+ },
26
+ "include": ["<%= js_destination_path %>"]
27
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ {
5
+ "path": "./tsconfig.app.json"
6
+ },
7
+ {
8
+ "path": "./tsconfig.node.json"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
5
+ "skipLibCheck": true,
6
+ "module": "ESNext",
7
+ "moduleResolution": "bundler",
8
+ "allowSyntheticDefaultImports": true,
9
+ "strict": true,
10
+ "noEmit": true
11
+ },
12
+ "include": ["vite.config.ts"]
13
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,116 @@
1
+ <script lang="ts">
2
+ import svelteSvg from '/assets/svelte.svg'
3
+ import inertiaSvg from '/assets/inertia.svg'
4
+ import viteRubySvg from '/assets/vite_ruby.svg'
5
+
6
+ export let name: string
7
+
8
+ let count = 0
9
+
10
+ function handleClick() {
11
+ count += 1
12
+ }
13
+ </script>
14
+
15
+ <svelte:head>
16
+ <title>Inertia + Vite Ruby + Svelte Example</title>
17
+ </svelte:head>
18
+
19
+ <div class="inertia_example">
20
+ <h1>Hello {name}!</h1>
21
+
22
+ <div>
23
+ <a href="https://inertia-rails.netlify.app" target="_blank">
24
+ <img class="logo" src={inertiaSvg} alt="Inertia logo" />
25
+ </a>
26
+ <a href="https://vite-ruby.netlify.app" target="_blank">
27
+ <img class="logo vite" src={viteRubySvg} alt="Vite Ruby logo" />
28
+ </a>
29
+ <a href="https://svelte.dev" target="_blank">
30
+ <img class="logo svelte" src={svelteSvg} alt="Svelte logo" />
31
+ </a>
32
+ </div>
33
+
34
+ <h2>Inertia + Vite Ruby + Svelte</h2>
35
+
36
+ <div class="card">
37
+ <button on:click={handleClick}>
38
+ count is {count}
39
+ </button>
40
+ <p>
41
+ Edit <code>app/frontend/pages/InertiaExample.svelte</code> and save to test
42
+ HMR
43
+ </p>
44
+ </div>
45
+ <p class="read-the-docs">
46
+ Click on the Inertia, Vite Ruby, and Svelte logos to learn more
47
+ </p>
48
+ </div>
49
+
50
+ <style>
51
+ .inertia_example {
52
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
53
+ line-height: 1.5;
54
+ font-weight: 400;
55
+ color: #213547;
56
+ background-color: #ffffff;
57
+ max-width: 1280px;
58
+ margin: 0 auto;
59
+ padding: 2rem;
60
+ text-align: center;
61
+ }
62
+
63
+ h1 {
64
+ font-size: 3.2em;
65
+ line-height: 1.1;
66
+ }
67
+
68
+ h2 {
69
+ font-size: 2.6em;
70
+ line-height: 1.1;
71
+ }
72
+
73
+ button {
74
+ border-radius: 8px;
75
+ border: 1px solid transparent;
76
+ padding: 0.6em 1.2em;
77
+ font-size: 1em;
78
+ font-weight: 500;
79
+ font-family: inherit;
80
+ background-color: #f9f9f9;
81
+ cursor: pointer;
82
+ transition: border-color 0.25s;
83
+ }
84
+ button:hover {
85
+ border-color: #646cff;
86
+ }
87
+ button:focus,
88
+ button:focus-visible {
89
+ outline: 4px auto -webkit-focus-ring-color;
90
+ }
91
+
92
+ .logo {
93
+ display: inline-block;
94
+ height: 6em;
95
+ padding: 1.5em;
96
+ will-change: filter;
97
+ transition: filter 300ms;
98
+ }
99
+ .logo:hover {
100
+ filter: drop-shadow(0 0 2em #646cffaa);
101
+ }
102
+ .logo.vite:hover {
103
+ filter: drop-shadow(0 0 2em #e4023baa);
104
+ }
105
+ .logo.svelte:hover {
106
+ filter: drop-shadow(0 0 2em #ff3e00aa);
107
+ }
108
+
109
+ .card {
110
+ padding: 2em;
111
+ }
112
+
113
+ .read-the-docs {
114
+ color: #888;
115
+ }
116
+ </style>
@@ -19,12 +19,11 @@ createInertiaApp({
19
19
  // and use the following lines.
20
20
  // see https://inertia-rails.netlify.app/guide/pages#default-layouts
21
21
  //
22
- // const page = pages[`../pages/${name}.vue`]
23
- // page.default.layout ||= (page) => createElement(Layout, null, page)
24
- // return page
22
+ // const page = pages[`../pages/${name}.svelte`]
23
+ // return { default: page.default, layout: page.layout || Layout }
25
24
  },
26
25
 
27
- setup({ el, App, props }) {
28
- new App({ target: el, props })
26
+ setup({ el, App }) {
27
+ new App({ target: el })
29
28
  },
30
29
  })
@@ -0,0 +1,32 @@
1
+ import { createInertiaApp } from '@inertiajs/svelte'
2
+ import type { ComponentType } from 'svelte';
3
+
4
+ type ResolvedComponent = { default: ComponentType, layout?: ComponentType }
5
+
6
+ createInertiaApp({
7
+ // Set default page title
8
+ // see https://inertia-rails.netlify.app/guide/title-and-meta
9
+ //
10
+ // title: title => title ? `${title} - App` : 'App',
11
+
12
+ // Disable progress bar
13
+ //
14
+ // see https://inertia-rails.netlify.app/guide/progress-indicators
15
+ // progress: false,
16
+
17
+ resolve: (name) => {
18
+ const pages = import.meta.glob('../pages/**/*.svelte', { eager: true })
19
+ return pages[`../pages/${name}.svelte`] as ResolvedComponent
20
+
21
+ // To use a default layout, import the Layout component
22
+ // and use the following lines.
23
+ // see https://inertia-rails.netlify.app/guide/pages#default-layouts
24
+ //
25
+ // const page = pages[`../pages/${name}.svelte`] as ResolvedComponent
26
+ // return { default: page.default, layout: page.layout || Layout }
27
+ },
28
+
29
+ setup({ el, App }) {
30
+ new App({ target: el })
31
+ },
32
+ })
@@ -0,0 +1,21 @@
1
+ {
2
+ "extends": "@tsconfig/svelte/tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "ESNext",
5
+ "useDefineForClassFields": true,
6
+ "module": "ESNext",
7
+ "resolveJsonModule": true,
8
+ /**
9
+ * Typecheck JS in `.svelte` and `.js` files by default.
10
+ * Disable checkJs if you'd like to use dynamic types in JS.
11
+ * Note that setting allowJs false does not prevent the use
12
+ * of JS in `.svelte` files.
13
+ */
14
+ "allowJs": true,
15
+ "checkJs": true,
16
+ "isolatedModules": true,
17
+ "moduleDetection": "force",
18
+ },
19
+ "include": ["<%= js_destination_path %>/**/*.ts", "<%= js_destination_path %>/**/*.js", "<%= js_destination_path %>/**/*.svelte"],
20
+ "references": [{ "path": "./tsconfig.node.json" }]
21
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
5
+ "skipLibCheck": true,
6
+ "module": "ESNext",
7
+ "moduleResolution": "bundler",
8
+ "strict": true,
9
+ "noEmit": true,
10
+ },
11
+ "include": ["vite.config.ts"]
12
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference types="svelte" />
2
+ /// <reference types="vite/client" />
@@ -0,0 +1,117 @@
1
+ <template>
2
+ <Head title="Inertia + Vite Ruby + Vue Example" />
3
+
4
+ <div class="root">
5
+ <h1 class="h1">Hello {{ name }}!</h1>
6
+
7
+ <div>
8
+ <a href="https://inertia-rails.netlify.app" target="_blank">
9
+ <img class="logo" :src="inertiaSvg" alt="Inertia logo" />
10
+ </a>
11
+ <a href="https://vite-ruby.netlify.app" target="_blank">
12
+ <img class="logo vite" :src="viteRubySvg" alt="Vite Ruby logo" />
13
+ </a>
14
+ <a href="https://vuejs.org" target="_blank">
15
+ <img class="logo vue" :src="vueSvg" alt="Vue logo" />
16
+ </a>
17
+ </div>
18
+
19
+ <h2 class="h2">Inertia + Vite Ruby + Vue</h2>
20
+
21
+ <div class="card">
22
+ <button class="button" type="button" @click="count++">
23
+ count is {{ count }}
24
+ </button>
25
+ <p>
26
+ Edit <code>app/frontend/pages/InertiaExample.vue</code> and save to test
27
+ HMR
28
+ </p>
29
+ </div>
30
+ <p class="readTheDocs">
31
+ Click on the Inertia, Vite Ruby, and Vue logos to learn more
32
+ </p>
33
+ </div>
34
+ </template>
35
+
36
+ <script setup lang="ts">
37
+ import { Head } from '@inertiajs/vue3'
38
+ import { ref } from 'vue'
39
+
40
+ import vueSvg from '/assets/vue.svg'
41
+ import inertiaSvg from '/assets/inertia.svg'
42
+ import viteRubySvg from '/assets/vite_ruby.svg'
43
+
44
+ defineProps({
45
+ name: String,
46
+ })
47
+
48
+ const count = ref(0)
49
+ </script>
50
+
51
+ <style scoped>
52
+ .root {
53
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
54
+ line-height: 1.5;
55
+ font-weight: 400;
56
+ color: #213547;
57
+ background-color: #ffffff;
58
+ max-width: 1280px;
59
+ margin: 0 auto;
60
+ padding: 2rem;
61
+ text-align: center;
62
+ }
63
+
64
+ .h1 {
65
+ font-size: 3.2em;
66
+ line-height: 1.1;
67
+ }
68
+
69
+ .h2 {
70
+ font-size: 2.6em;
71
+ line-height: 1.1;
72
+ }
73
+
74
+ .button {
75
+ border-radius: 8px;
76
+ border: 1px solid transparent;
77
+ padding: 0.6em 1.2em;
78
+ font-size: 1em;
79
+ font-weight: 500;
80
+ font-family: inherit;
81
+ background-color: #f9f9f9;
82
+ cursor: pointer;
83
+ transition: border-color 0.25s;
84
+ }
85
+ .button:hover {
86
+ border-color: #646cff;
87
+ }
88
+ .button:focus,
89
+ .button:focus-visible {
90
+ outline: 4px auto -webkit-focus-ring-color;
91
+ }
92
+
93
+ .logo {
94
+ display: inline-block;
95
+ height: 6em;
96
+ padding: 1.5em;
97
+ will-change: filter;
98
+ transition: filter 300ms;
99
+ }
100
+ .logo:hover {
101
+ filter: drop-shadow(0 0 2em #646cffaa);
102
+ }
103
+ .logo.vite:hover {
104
+ filter: drop-shadow(0 0 2em #e4023baa);
105
+ }
106
+ .logo.vue:hover {
107
+ filter: drop-shadow(0 0 2em #41b883aa);
108
+ }
109
+
110
+ .card {
111
+ padding: 2em;
112
+ }
113
+
114
+ .readTheDocs {
115
+ color: #888;
116
+ }
117
+ </style>
@@ -21,7 +21,7 @@ createInertiaApp({
21
21
  // see https://inertia-rails.netlify.app/guide/pages#default-layouts
22
22
  //
23
23
  // const page = pages[`../pages/${name}.vue`]
24
- // page.default.layout ||= (page) => createElement(Layout, null, page)
24
+ // page.default.layout = page.default.layout || Layout
25
25
  // return page
26
26
  },
27
27
 
@@ -0,0 +1,33 @@
1
+ import { createInertiaApp } from '@inertiajs/vue3'
2
+ import {createApp, DefineComponent, h} from 'vue'
3
+
4
+ createInertiaApp({
5
+ // Set default page title
6
+ // see https://inertia-rails.netlify.app/guide/title-and-meta
7
+ //
8
+ // title: title => title ? `${title} - App` : 'App',
9
+
10
+ // Disable progress bar
11
+ //
12
+ // see https://inertia-rails.netlify.app/guide/progress-indicators
13
+ // progress: false,
14
+
15
+ resolve: (name) => {
16
+ const pages = import.meta.glob('../pages/**/*.vue', { eager: true })
17
+ return pages[`../pages/${name}.vue`] as DefineComponent
18
+
19
+ // To use a default layout, import the Layout component
20
+ // and use the following lines.
21
+ // see https://inertia-rails.netlify.app/guide/pages#default-layouts
22
+ //
23
+ // const page = pages[`../pages/${name}.vue`] as DefineComponent
24
+ // page.default.layout = page.default.layout || Layout
25
+ // return page
26
+ },
27
+
28
+ setup({ el, App, props, plugin }) {
29
+ createApp({ render: () => h(App, props) })
30
+ .use(plugin)
31
+ .mount(el)
32
+ },
33
+ })
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "isolatedModules": true,
13
+ "moduleDetection": "force",
14
+ "noEmit": true,
15
+ "jsx": "preserve",
16
+
17
+ /* Linting */
18
+ "strict": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "noFallthroughCasesInSwitch": true
22
+ },
23
+ "include": ["<%= js_destination_path %>/**/*.ts", "<%= js_destination_path %>/**/*.tsx", "<%= js_destination_path %>/**/*.vue"]
24
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ {
5
+ "path": "./tsconfig.app.json"
6
+ },
7
+ {
8
+ "path": "./tsconfig.node.json"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["ES2023"],
5
+ "module": "ESNext",
6
+ "skipLibCheck": true,
7
+
8
+ /* Bundler mode */
9
+ "moduleResolution": "bundler",
10
+ "allowImportingTsExtensions": true,
11
+ "isolatedModules": true,
12
+ "moduleDetection": "force",
13
+ "noEmit": true,
14
+
15
+ /* Linting */
16
+ "strict": true,
17
+ "noUnusedLocals": true,
18
+ "noUnusedParameters": true,
19
+ "noFallthroughCasesInSwitch": true
20
+ },
21
+ "include": ["vite.config.ts"]
22
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -14,7 +14,7 @@ module InertiaRailsContrib
14
14
  end
15
15
 
16
16
  def self.guess_inertia_template
17
- if Rails.root.join("tailwind.config.js").exist?
17
+ if Rails.root.join("tailwind.config.js").exist? || Rails.root.join("tailwind.config.ts").exist?
18
18
  "inertia_tw_templates"
19
19
  else
20
20
  "inertia_templates"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InertiaRailsContrib
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inertia_rails-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svyatoslav Kryukov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-10 00:00:00.000000000 Z
11
+ date: 2024-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -63,15 +63,32 @@ files:
63
63
  - lib/generators/inertia/install/templates/initializer.rb
64
64
  - lib/generators/inertia/install/templates/react/InertiaExample.jsx
65
65
  - lib/generators/inertia/install/templates/react/InertiaExample.module.css
66
+ - lib/generators/inertia/install/templates/react/InertiaExample.tsx
66
67
  - lib/generators/inertia/install/templates/react/inertia.js
68
+ - lib/generators/inertia/install/templates/react/inertia.ts
69
+ - lib/generators/inertia/install/templates/react/tsconfig.app.json
70
+ - lib/generators/inertia/install/templates/react/tsconfig.json
71
+ - lib/generators/inertia/install/templates/react/tsconfig.node.json
72
+ - lib/generators/inertia/install/templates/react/vite-env.d.ts
67
73
  - lib/generators/inertia/install/templates/svelte/InertiaExample.svelte
74
+ - lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte
68
75
  - lib/generators/inertia/install/templates/svelte/inertia.js
76
+ - lib/generators/inertia/install/templates/svelte/inertia.ts
69
77
  - lib/generators/inertia/install/templates/svelte/svelte.config.js
78
+ - lib/generators/inertia/install/templates/svelte/tsconfig.json
79
+ - lib/generators/inertia/install/templates/svelte/tsconfig.node.json
80
+ - lib/generators/inertia/install/templates/svelte/vite-env.d.ts
70
81
  - lib/generators/inertia/install/templates/tailwind/application.css
71
82
  - lib/generators/inertia/install/templates/tailwind/postcss.config.js
72
83
  - lib/generators/inertia/install/templates/tailwind/tailwind.config.js.tt
84
+ - lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue
73
85
  - lib/generators/inertia/install/templates/vue/InertiaExample.vue
74
86
  - lib/generators/inertia/install/templates/vue/inertia.js
87
+ - lib/generators/inertia/install/templates/vue/inertia.ts
88
+ - lib/generators/inertia/install/templates/vue/tsconfig.app.json
89
+ - lib/generators/inertia/install/templates/vue/tsconfig.json
90
+ - lib/generators/inertia/install/templates/vue/tsconfig.node.json
91
+ - lib/generators/inertia/install/templates/vue/vite-env.d.ts
75
92
  - lib/generators/inertia/scaffold/scaffold_generator.rb
76
93
  - lib/generators/inertia/scaffold_controller/scaffold_controller_generator.rb
77
94
  - lib/generators/inertia/scaffold_controller/templates/controller.rb.tt
@@ -152,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
169
  - !ruby/object:Gem::Version
153
170
  version: '0'
154
171
  requirements: []
155
- rubygems_version: 3.5.7
172
+ rubygems_version: 3.5.17
156
173
  signing_key:
157
174
  specification_version: 4
158
175
  summary: A collection of extensions and developer tools for Rails Inertia adapter