inertia_rails-contrib 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -1
- data/README.md +16 -7
- data/lib/generators/inertia/install/frameworks.yml +66 -9
- data/lib/generators/inertia/install/install_generator.rb +61 -9
- data/lib/generators/inertia/install/templates/react/InertiaExample.tsx +60 -0
- data/lib/generators/inertia/install/templates/react/inertia.ts +36 -0
- data/lib/generators/inertia/install/templates/react/tsconfig.app.json +27 -0
- data/lib/generators/inertia/install/templates/react/tsconfig.json +11 -0
- data/lib/generators/inertia/install/templates/react/tsconfig.node.json +13 -0
- data/lib/generators/inertia/install/templates/react/vite-env.d.ts +1 -0
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte +3 -7
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte +112 -0
- data/lib/generators/inertia/install/templates/svelte/inertia.js +4 -4
- data/lib/generators/inertia/install/templates/svelte/inertia.ts +30 -0
- data/lib/generators/inertia/install/templates/svelte/tsconfig.json +21 -0
- data/lib/generators/inertia/install/templates/svelte/tsconfig.node.json +12 -0
- data/lib/generators/inertia/install/templates/svelte/vite-env.d.ts +2 -0
- data/lib/generators/inertia/install/templates/svelte4/InertiaExample.svelte +116 -0
- data/lib/generators/inertia/install/templates/svelte4/InertiaExample.ts.svelte +116 -0
- data/lib/generators/inertia/install/templates/svelte4/inertia.js +29 -0
- data/lib/generators/inertia/install/templates/svelte4/inertia.ts +29 -0
- data/lib/generators/inertia/install/templates/svelte4/svelte.config.js +7 -0
- data/lib/generators/inertia/install/templates/svelte4/tsconfig.json +21 -0
- data/lib/generators/inertia/install/templates/svelte4/tsconfig.node.json +12 -0
- data/lib/generators/inertia/install/templates/svelte4/vite-env.d.ts +2 -0
- data/lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue +117 -0
- data/lib/generators/inertia/install/templates/vue/inertia.js +1 -1
- data/lib/generators/inertia/install/templates/vue/inertia.ts +33 -0
- data/lib/generators/inertia/install/templates/vue/tsconfig.app.json +24 -0
- data/lib/generators/inertia/install/templates/vue/tsconfig.json +11 -0
- data/lib/generators/inertia/install/templates/vue/tsconfig.node.json +22 -0
- data/lib/generators/inertia/install/templates/vue/vite-env.d.ts +1 -0
- data/lib/generators/inertia_templates/controller/templates/svelte4/view.svelte.tt +2 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Form.jsx.tt +2 -2
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.svelte.tt +3 -4
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.svelte.tt +12 -10
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Index.svelte.tt +1 -8
- data/lib/generators/inertia_templates/scaffold/templates/svelte/New.svelte.tt +3 -4
- data/lib/generators/inertia_templates/scaffold/templates/svelte/One.svelte.tt +1 -1
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Show.svelte.tt +4 -9
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.svelte.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.svelte.tt +96 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.svelte.tt +36 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/New.svelte.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/One.svelte.tt +28 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.svelte.tt +46 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Form.vue.tt +1 -1
- data/lib/generators/inertia_tw_templates/controller/templates/svelte4/view.svelte.tt +2 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.jsx.tt +2 -2
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.svelte.tt +3 -4
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.svelte.tt +12 -13
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Index.svelte.tt +1 -8
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.svelte.tt +3 -4
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/One.svelte.tt +1 -1
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Show.svelte.tt +7 -8
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.svelte.tt +45 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.svelte.tt +120 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Index.svelte.tt +43 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/New.svelte.tt +33 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/One.svelte.tt +28 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Show.svelte.tt +58 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Form.vue.tt +2 -2
- data/lib/inertia_rails_contrib/generators_helper.rb +5 -4
- data/lib/inertia_rails_contrib/version.rb +1 -1
- metadata +42 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27c11a71a3acff524328e14dd27d4265a5365a113a58ae636b6877dbfb294d12
|
4
|
+
data.tar.gz: 8150b80e446aebe35e9e5a58026d2d633ce06c693254c2849229ceeee0f30a1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2c94b176f794229063106b9ca1bd28a73c0b766cb657479bc75656cbc2ef4de74e94a85c61aaa64e1ae20e6659bc5cf9923c1c75fd069f224e0403eb63fab74
|
7
|
+
data.tar.gz: c3030cd27b25dbc309d6e3ea7a2b410563b794724fad3f7043a53d86430ea8b1fae7eb122c62bfdaa69bf9301e0da9fdec7525f114c7e98df825eee0877ff1c5
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,34 @@ and this project adheres to [Semantic Versioning].
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.3.0] - 2024-10-25
|
11
|
+
|
12
|
+
Added:
|
13
|
+
|
14
|
+
- [BREAKING] Svelte 5 support ([@skryukov])
|
15
|
+
- The `--framework=svelte` option now installs Svelte 5
|
16
|
+
- New `--framework=svelte4` option installs Svelte 4
|
17
|
+
- Support for Svelte 5 in the installation generator
|
18
|
+
- Support for Svelte 5 in the scaffold templates
|
19
|
+
|
20
|
+
## [0.2.2] - 2024-10-09
|
21
|
+
|
22
|
+
Added:
|
23
|
+
|
24
|
+
- TypeScript support for the installation generator ([@skryukov])
|
25
|
+
Note that it doesn't include scaffold templates yet.
|
26
|
+
|
27
|
+
- New `--inertia-version` option for the installation generator ([@skryukov])
|
28
|
+
This allows you to specify the Inertia.js version to install.
|
29
|
+
|
30
|
+
- Support `tailwind.config.ts` for Tailwind CSS template guessing ([@Shaglock])
|
31
|
+
|
32
|
+
Fixed:
|
33
|
+
|
34
|
+
- Correct examples for default layouts in inertia entrypoints ([@skryukov])
|
35
|
+
- Inertia attribute added to the head tag in the layout for vue ([@skryukov])
|
36
|
+
- Remove duplicate `vite_stylesheet_tag` when Tailwind CSS is installed ([@skryukov])
|
37
|
+
|
10
38
|
## [0.2.1] - 2024-08-11
|
11
39
|
|
12
40
|
Added:
|
@@ -41,9 +69,12 @@ Added:
|
|
41
69
|
- Initial release ([@iurev], [@skryukov])
|
42
70
|
|
43
71
|
[@iurev]: https://github.com/iurev
|
72
|
+
[@Shaglock]: https://github.com/Shaglock
|
44
73
|
[@skryukov]: https://github.com/skryukov
|
45
74
|
|
46
|
-
[Unreleased]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.
|
75
|
+
[Unreleased]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.3.0...HEAD
|
76
|
+
[0.3.0]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.2...v0.3.0
|
77
|
+
[0.2.2]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.1...v0.2.2
|
47
78
|
[0.2.1]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.0...v0.2.1
|
48
79
|
[0.2.0]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.1.1...v0.2.0
|
49
80
|
[0.1.1]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.1.0...v0.1.1
|
data/README.md
CHANGED
@@ -31,7 +31,8 @@ bin/rails generate inertia:install
|
|
31
31
|
|
32
32
|
This command will:
|
33
33
|
- Check for Vite Rails and install it if not present
|
34
|
-
- Ask you to
|
34
|
+
- Ask if you want to use TypeScript
|
35
|
+
- Ask you to choose your preferred frontend framework (React, Vue, Svelte 4, or Svelte 5)
|
35
36
|
- Ask if you want to install Tailwind CSS
|
36
37
|
- Install necessary dependencies
|
37
38
|
- Set up the application to work with Inertia
|
@@ -48,6 +49,10 @@ Would you like to install Vite Ruby? (y/n) y
|
|
48
49
|
Vite Rails gem successfully installed
|
49
50
|
run bundle exec vite install from "."
|
50
51
|
Vite Rails successfully installed
|
52
|
+
Would you like to use TypeScript? (y/n) y
|
53
|
+
Adding TypeScript support
|
54
|
+
What framework do you want to use with Inertia? [react, vue, svelte4, svelte] (react)
|
55
|
+
run npm add @types/react @types/react-dom typescript --silent from "."
|
51
56
|
Would you like to install Tailwind CSS? (y/n) y
|
52
57
|
Installing Tailwind CSS
|
53
58
|
run npm add tailwindcss postcss autoprefixer @tailwindcss/forms @tailwindcss/typography @tailwindcss/container-queries --silent from "."
|
@@ -59,14 +64,14 @@ Adding Tailwind CSS to the application layout
|
|
59
64
|
Adding Inertia's Rails adapter initializer
|
60
65
|
create config/initializers/inertia_rails.rb
|
61
66
|
Installing Inertia npm packages
|
62
|
-
|
63
|
-
run npm add @inertiajs/react
|
67
|
+
run npm add @vitejs/plugin-react react react-dom --silent from "."
|
68
|
+
run npm add @inertiajs/react@latest --silent from "."
|
64
69
|
Adding Vite plugin for react
|
65
70
|
insert vite.config.ts
|
66
71
|
prepend vite.config.ts
|
67
|
-
Copying inertia.
|
68
|
-
create app/frontend/entrypoints/inertia.
|
69
|
-
Adding inertia.
|
72
|
+
Copying inertia.ts entrypoint
|
73
|
+
create app/frontend/entrypoints/inertia.ts
|
74
|
+
Adding inertia.ts script tag to the application layout
|
70
75
|
insert app/views/layouts/application.html.erb
|
71
76
|
Adding Vite React Refresh tag to the application layout
|
72
77
|
insert app/views/layouts/application.html.erb
|
@@ -76,11 +81,15 @@ Copying example Inertia controller
|
|
76
81
|
Adding a route for the example Inertia controller
|
77
82
|
route get 'inertia-example', to: 'inertia_example#index'
|
78
83
|
Copying page assets
|
79
|
-
create app/frontend/pages/InertiaExample.jsx
|
80
84
|
create app/frontend/pages/InertiaExample.module.css
|
81
85
|
create app/frontend/assets/react.svg
|
82
86
|
create app/frontend/assets/inertia.svg
|
83
87
|
create app/frontend/assets/vite_ruby.svg
|
88
|
+
create app/frontend/pages/InertiaExample.tsx
|
89
|
+
create tsconfig.json
|
90
|
+
create tsconfig.app.json
|
91
|
+
create tsconfig.node.json
|
92
|
+
create app/frontend/vite-env.d.ts
|
84
93
|
Copying bin/dev
|
85
94
|
create bin/dev
|
86
95
|
Inertia's Rails adapter successfully installed
|
@@ -1,41 +1,98 @@
|
|
1
1
|
react:
|
2
|
+
inertia_package: "@inertiajs/react"
|
2
3
|
packages:
|
3
|
-
- "@
|
4
|
+
- "@vitejs/plugin-react"
|
4
5
|
- "react"
|
5
6
|
- "react-dom"
|
6
|
-
|
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
|
-
|
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
|
+
svelte4:
|
51
|
+
inertia_package: "@inertiajs/svelte"
|
30
52
|
packages:
|
31
|
-
- "@
|
32
|
-
- "svelte"
|
33
|
-
|
53
|
+
- "svelte@4"
|
54
|
+
- "@sveltejs/vite-plugin-svelte@3"
|
55
|
+
packages_ts:
|
56
|
+
- "@tsconfig/svelte@4"
|
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"
|
71
|
+
"../assets/svelte.svg": "%{js_destination_path}/assets/svelte.svg"
|
72
|
+
"../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
|
73
|
+
"../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
|
74
|
+
|
75
|
+
svelte:
|
76
|
+
inertia_package: "@inertiajs/svelte"
|
77
|
+
packages:
|
78
|
+
- "svelte@5"
|
79
|
+
- "@sveltejs/vite-plugin-svelte@4"
|
80
|
+
packages_ts:
|
81
|
+
- "@tsconfig/svelte@5"
|
82
|
+
- "svelte-check"
|
83
|
+
- "typescript"
|
84
|
+
- "tslib"
|
85
|
+
vite_plugin_import: "import { svelte } from '@sveltejs/vite-plugin-svelte'"
|
86
|
+
vite_plugin_call: "svelte()"
|
87
|
+
copy_files_ts:
|
88
|
+
"InertiaExample.ts.svelte": "%{js_destination_path}/pages/InertiaExample.svelte"
|
89
|
+
"tsconfig.json": "tsconfig.json"
|
90
|
+
"tsconfig.node.json": "tsconfig.node.json"
|
91
|
+
"vite-env.d.ts": "%{js_destination_path}/vite-env.d.ts"
|
92
|
+
copy_files_js:
|
38
93
|
"InertiaExample.svelte": "%{js_destination_path}/pages/InertiaExample.svelte"
|
94
|
+
copy_files:
|
95
|
+
"svelte.config.js": "svelte.config.js"
|
39
96
|
"../assets/svelte.svg": "%{js_destination_path}/assets/svelte.svg"
|
40
97
|
"../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
|
41
98
|
"../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
|
@@ -18,6 +18,12 @@ module Inertia
|
|
18
18
|
enum: FRAMEWORKS.keys,
|
19
19
|
default: nil
|
20
20
|
|
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
|
+
|
21
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
|
|
@@ -39,8 +45,15 @@ module Inertia
|
|
39
45
|
def install
|
40
46
|
say "Installing Inertia's Rails adapter"
|
41
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
|
+
|
42
53
|
install_vite unless ruby_vite_installed?
|
43
54
|
|
55
|
+
install_typescript if typescript?
|
56
|
+
|
44
57
|
install_tailwind if install_tailwind?
|
45
58
|
|
46
59
|
install_inertia
|
@@ -62,6 +75,7 @@ module Inertia
|
|
62
75
|
|
63
76
|
say "Installing Inertia npm packages"
|
64
77
|
add_packages(*FRAMEWORKS[framework]["packages"])
|
78
|
+
add_packages(inertia_package)
|
65
79
|
|
66
80
|
unless File.read(vite_config_path).include?(FRAMEWORKS[framework]["vite_plugin_import"])
|
67
81
|
say "Adding Vite plugin for #{framework}"
|
@@ -69,32 +83,43 @@ module Inertia
|
|
69
83
|
prepend_file vite_config_path, "#{FRAMEWORKS[framework]["vite_plugin_import"]}\n"
|
70
84
|
end
|
71
85
|
|
72
|
-
say "Copying
|
73
|
-
template "#{framework}
|
86
|
+
say "Copying #{inertia_entrypoint} entrypoint"
|
87
|
+
template "#{framework}/#{inertia_entrypoint}", js_file_path("entrypoints/#{inertia_entrypoint}")
|
74
88
|
|
75
89
|
if application_layout.exist?
|
76
|
-
say "Adding
|
90
|
+
say "Adding #{inertia_entrypoint} script tag to the application layout"
|
77
91
|
headers = <<-ERB
|
78
|
-
<%=
|
92
|
+
<%= #{vite_tag} "inertia" %>
|
79
93
|
<%= inertia_headers %>
|
80
94
|
ERB
|
81
|
-
headers += "\n <%= vite_stylesheet_tag \"application\" %>" if install_tailwind?
|
82
|
-
|
83
95
|
insert_into_file application_layout.to_s, headers, after: "<%= vite_client_tag %>\n"
|
84
96
|
|
85
97
|
if framework == "react" && !application_layout.read.include?("vite_react_refresh_tag")
|
86
98
|
say "Adding Vite React Refresh tag to the application layout"
|
87
99
|
insert_into_file application_layout.to_s, "<%= vite_react_refresh_tag %>\n ", before: "<%= vite_client_tag %>"
|
88
|
-
gsub_file application_layout.to_s, /<title>/, "<title inertia>"
|
89
100
|
end
|
101
|
+
|
102
|
+
gsub_file application_layout.to_s, /<title>/, "<title inertia>" unless svelte?
|
90
103
|
else
|
91
104
|
say_error "Could not find the application layout file. Please add the following tags manually:", :red
|
92
105
|
say_error "- <title>...</title>"
|
93
106
|
say_error "+ <title inertia>...</title>"
|
94
107
|
say_error "+ <%= inertia_headers %>"
|
95
108
|
say_error "+ <%= vite_react_refresh_tag %>" if framework == "react"
|
96
|
-
say_error "+ <%=
|
109
|
+
say_error "+ <%= #{vite_tag} \"inertia\" %>"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def install_typescript
|
114
|
+
say "Adding TypeScript support"
|
115
|
+
if 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
|
97
120
|
end
|
121
|
+
|
122
|
+
add_packages(*FRAMEWORKS[framework]["packages_ts"])
|
98
123
|
end
|
99
124
|
|
100
125
|
def install_example_page
|
@@ -105,7 +130,8 @@ module Inertia
|
|
105
130
|
route "get 'inertia-example', to: 'inertia_example#index'"
|
106
131
|
|
107
132
|
say "Copying page assets"
|
108
|
-
FRAMEWORKS[framework]["copy_files"].
|
133
|
+
copy_files = FRAMEWORKS[framework]["copy_files"].merge(FRAMEWORKS[framework]["copy_files_#{typescript? ? "ts" : "js"}"])
|
134
|
+
copy_files.each do |source, destination|
|
109
135
|
template "#{framework}/#{source}", file_path(destination % {js_destination_path: js_destination_path})
|
110
136
|
end
|
111
137
|
end
|
@@ -222,10 +248,36 @@ module Inertia
|
|
222
248
|
@install_tailwind = options[:install_tailwind] || yes?("Would you like to install Tailwind CSS? (y/n)", :green)
|
223
249
|
end
|
224
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
|
+
|
225
269
|
def verbose?
|
226
270
|
options[:verbose]
|
227
271
|
end
|
228
272
|
|
273
|
+
def svelte?
|
274
|
+
framework.start_with? "svelte"
|
275
|
+
end
|
276
|
+
|
277
|
+
def inertia_package
|
278
|
+
"#{FRAMEWORKS[framework]["inertia_package"]}@#{options[:inertia_version]}"
|
279
|
+
end
|
280
|
+
|
229
281
|
def framework
|
230
282
|
@framework ||= options[:framework] || ask("What framework do you want to use with Inertia?", :green, limited_to: FRAMEWORKS.keys, default: "react")
|
231
283
|
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 ResolvedComponent = { 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<ResolvedComponent>('../pages/**/*.tsx', { eager: true })
|
20
|
+
return pages[`../pages/${name}.tsx`]
|
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`]
|
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,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" />
|
@@ -3,13 +3,9 @@
|
|
3
3
|
import inertiaSvg from '/assets/inertia.svg'
|
4
4
|
import viteRubySvg from '/assets/vite_ruby.svg'
|
5
5
|
|
6
|
-
|
6
|
+
let { name } = $props()
|
7
7
|
|
8
|
-
let count = 0
|
9
|
-
|
10
|
-
function handleClick() {
|
11
|
-
count += 1
|
12
|
-
}
|
8
|
+
let count = $state(0)
|
13
9
|
</script>
|
14
10
|
|
15
11
|
<svelte:head>
|
@@ -34,7 +30,7 @@
|
|
34
30
|
<h2>Inertia + Vite Ruby + Svelte</h2>
|
35
31
|
|
36
32
|
<div class="card">
|
37
|
-
<button
|
33
|
+
<button onclick={() => count++}>
|
38
34
|
count is {count}
|
39
35
|
</button>
|
40
36
|
<p>
|
@@ -0,0 +1,112 @@
|
|
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
|
+
let { name }: { name: string } = $props()
|
7
|
+
|
8
|
+
let count = $state(0)
|
9
|
+
</script>
|
10
|
+
|
11
|
+
<svelte:head>
|
12
|
+
<title>Inertia + Vite Ruby + Svelte Example</title>
|
13
|
+
</svelte:head>
|
14
|
+
|
15
|
+
<div class="inertia_example">
|
16
|
+
<h1>Hello {name}!</h1>
|
17
|
+
|
18
|
+
<div>
|
19
|
+
<a href="https://inertia-rails.netlify.app" target="_blank">
|
20
|
+
<img class="logo" src={inertiaSvg} alt="Inertia logo" />
|
21
|
+
</a>
|
22
|
+
<a href="https://vite-ruby.netlify.app" target="_blank">
|
23
|
+
<img class="logo vite" src={viteRubySvg} alt="Vite Ruby logo" />
|
24
|
+
</a>
|
25
|
+
<a href="https://svelte.dev" target="_blank">
|
26
|
+
<img class="logo svelte" src={svelteSvg} alt="Svelte logo" />
|
27
|
+
</a>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<h2>Inertia + Vite Ruby + Svelte</h2>
|
31
|
+
|
32
|
+
<div class="card">
|
33
|
+
<button onclick={() => count++}>
|
34
|
+
count is {count}
|
35
|
+
</button>
|
36
|
+
<p>
|
37
|
+
Edit <code>app/frontend/pages/InertiaExample.svelte</code> and save to test
|
38
|
+
HMR
|
39
|
+
</p>
|
40
|
+
</div>
|
41
|
+
<p class="read-the-docs">
|
42
|
+
Click on the Inertia, Vite Ruby, and Svelte logos to learn more
|
43
|
+
</p>
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<style>
|
47
|
+
.inertia_example {
|
48
|
+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
49
|
+
line-height: 1.5;
|
50
|
+
font-weight: 400;
|
51
|
+
color: #213547;
|
52
|
+
background-color: #ffffff;
|
53
|
+
max-width: 1280px;
|
54
|
+
margin: 0 auto;
|
55
|
+
padding: 2rem;
|
56
|
+
text-align: center;
|
57
|
+
}
|
58
|
+
|
59
|
+
h1 {
|
60
|
+
font-size: 3.2em;
|
61
|
+
line-height: 1.1;
|
62
|
+
}
|
63
|
+
|
64
|
+
h2 {
|
65
|
+
font-size: 2.6em;
|
66
|
+
line-height: 1.1;
|
67
|
+
}
|
68
|
+
|
69
|
+
button {
|
70
|
+
border-radius: 8px;
|
71
|
+
border: 1px solid transparent;
|
72
|
+
padding: 0.6em 1.2em;
|
73
|
+
font-size: 1em;
|
74
|
+
font-weight: 500;
|
75
|
+
font-family: inherit;
|
76
|
+
background-color: #f9f9f9;
|
77
|
+
cursor: pointer;
|
78
|
+
transition: border-color 0.25s;
|
79
|
+
}
|
80
|
+
button:hover {
|
81
|
+
border-color: #646cff;
|
82
|
+
}
|
83
|
+
button:focus,
|
84
|
+
button:focus-visible {
|
85
|
+
outline: 4px auto -webkit-focus-ring-color;
|
86
|
+
}
|
87
|
+
|
88
|
+
.logo {
|
89
|
+
display: inline-block;
|
90
|
+
height: 6em;
|
91
|
+
padding: 1.5em;
|
92
|
+
will-change: filter;
|
93
|
+
transition: filter 300ms;
|
94
|
+
}
|
95
|
+
.logo:hover {
|
96
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
97
|
+
}
|
98
|
+
.logo.vite:hover {
|
99
|
+
filter: drop-shadow(0 0 2em #e4023baa);
|
100
|
+
}
|
101
|
+
.logo.svelte:hover {
|
102
|
+
filter: drop-shadow(0 0 2em #ff3e00aa);
|
103
|
+
}
|
104
|
+
|
105
|
+
.card {
|
106
|
+
padding: 2em;
|
107
|
+
}
|
108
|
+
|
109
|
+
.read-the-docs {
|
110
|
+
color: #888;
|
111
|
+
}
|
112
|
+
</style>
|