svelte-on-rails 0.0.18 → 0.0.21

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.
@@ -1,200 +1,116 @@
1
1
  Rake::Task["assets:precompile"].enhance do
2
- SvelteOnRails::RenderServerSide.reset_dist
3
- puts "Mount Svelte: Reset dist ausgeführt"
2
+ SvelteOnRails::RenderServerSide.reset_and_compile_all
3
+ puts "Mount Svelte: Reset dist and compile-all executed"
4
4
  end
5
5
 
6
+ require 'svelte_on_rails/installer/utils'
7
+ require 'svelte_on_rails/installer/haml'
8
+ utils = SvelteOnRails::Installer::Utils
9
+ npm_i = SvelteOnRails::Installer::Npm
10
+ application_js_path = Rails.root.join("app", "frontend", "entrypoints", "application.js")
11
+
6
12
  namespace :svelte_on_rails do
7
- desc "Installs SvelteOnRails YAML configuration into your Rails application"
8
- task :install do
9
13
 
10
- create_configuration_file
14
+ desc "Installs SvelteOnRails for usage together with vite_rails, haml and @hotwired/turbo-rails"
15
+ task :install_haml_vite => :environment do
11
16
 
12
- end
17
+ puts '-' * 80
18
+ puts 'STARTING SVELTE-ON-RAILS INSTALLATION'
13
19
 
14
- desc "Installs SvelteOnRails for usage together with vite_rails and @hotwired/turbo-rails"
15
- task :install_for_vite_and_turbo do
20
+ # svelte_on_rails
16
21
 
17
- create_configuration_file
22
+ utils.write_templates(['config/svelte_on_rails.yml'])
23
+ npm_i.install_or_update_package('@csedl/svelte-on-rails')
24
+ # insert_initializer
25
+ uts = SvelteOnRails::Installer::Utils
26
+ uts.write_templates(['app/frontend/initializers/svelte.js'])
27
+ # add import statements
28
+ js_i = SvelteOnRails::Installer::Javascript
29
+ init_stat = '../initializers/svelte.js'
30
+ js_i.append_import_statement(application_js_path, init_stat, "import '#{init_stat}';")
18
31
 
19
- install_npm_package
20
- install_turbo
21
32
 
22
- create_folder(Rails.root.join("app", "frontend", "initializers"))
23
- create_folder(Rails.root.join("app", "frontend", "javascript", "components"))
24
- add_line_to_file(Rails.root.join("app", "frontend", "entrypoints", "application.js"), "import '../initializers/svelte.js';")
33
+ # haml
25
34
 
26
- create_javascript_initializer
27
- create_svelte_hello_world
35
+ haml_i = SvelteOnRails::Installer::Haml
36
+ haml_i.install_haml_and_convert
28
37
 
29
- puts ''
30
- puts 'SvelteOnRails installed successfully for using together with vite_rails and @hotwired/turbo-rails.'
31
- puts 'Restart the server and check if it all works.'
32
- puts 'Happy coding!'
38
+ # vite
33
39
 
34
- end
40
+ vite_i = SvelteOnRails::Installer::Vite
41
+ vite_i.install_vite
35
42
 
36
- def install_npm_package
37
- package_name = "@csedl/svelte-on-rails@latest"
38
- puts "Installing #{package_name} via npm..."
43
+ # turbo
39
44
 
40
- if system("npm install #{package_name}")
41
- puts "#{package_name} successfully installed."
42
- else
43
- abort "Failed to install #{package_name}. Please ensure npm is installed and try running 'npm install #{package_name}' manually."
44
- end
45
- end
45
+ tr_pkg = '@hotwired/turbo-rails'
46
46
 
47
- def install_turbo
48
-
49
- pkg_js = Rails.root.join("package.json")
50
- package_name = "@hotwired/turbo-rails"
51
- file_content = File.exist?(pkg_js) ? File.read(pkg_js) : ""
52
-
53
- if file_content.match?(/#{package_name}/)
54
- puts "#{package_name} is already present in package.json, assuming that it is set up well and working."
55
- else
56
- puts "Installing #{package_name} via npm..."
57
- if system("npm install #{package_name}")
58
- puts "#{package_name} successfully installed."
59
- add_line_to_file(Rails.root.join("app", "frontend", "entrypoints", "application.js"), "import '#{package_name}';")
60
- else
61
- abort "Failed to install #{package_name}. Please ensure npm is installed and try running 'npm install #{package_name}' manually."
62
- end
63
- end
47
+ npm_i.install_or_update_package(tr_pkg)
48
+
49
+ js_i = SvelteOnRails::Installer::Javascript
50
+ js_i.append_import_statement(application_js_path, tr_pkg, "import '#{tr_pkg}';")
64
51
 
65
- end
52
+ # svelte
66
53
 
67
- def create_javascript_initializer
68
- config_path = Rails.root.join("app", "frontend", "initializers", "svelte.js")
69
- if File.exist?(config_path)
70
- puts "Initializer already exists: file://#{config_path}"
71
- else
72
- File.write(config_path, <<~JAVASCRIPT)
54
+ svelte_i = SvelteOnRails::Installer::Svelte
55
+ svelte_i.install_svelte
73
56
 
74
- import { initializeSvelteComponents, cleanupSvelteComponents } from '@csedl/svelte-on-rails';
57
+ # Hello World
75
58
 
76
- const components = import.meta.glob('/javascript/components/**/*.svelte', { eager: true });
77
- const componentsRoot = '/javascript/components';
59
+ puts '-' * 80
60
+ hello_world_path = nil
61
+ if utils.ask_yn('Do you want to install the Hello World component?')
62
+ hw_i = SvelteOnRails::Installer::HelloWorld
63
+ hello_world_path = hw_i.install_hello_world
64
+ end
78
65
 
79
- // Initialize Svelte components
80
- initializeSvelteComponents(componentsRoot, components, true);
66
+ # finish
81
67
 
82
- // Turbo event listener for page load
83
- document.addEventListener('turbo:load', () => {
84
- initializeSvelteComponents(componentsRoot, components, true);
85
- });
68
+ puts '-' * 80
69
+ puts 'FINISHED SVELTE INSTALLATION'
70
+ puts '-' * 80
86
71
 
87
- // Turbo event listener for cleanup before page cache
88
- document.addEventListener('turbo:before-cache', () => {
89
- cleanupSvelteComponents(false);
90
- });
91
- JAVASCRIPT
92
- puts "Created initializer file at file://#{config_path}"
72
+ puts "SvelteOnRails installed successfully!"
73
+ puts "Restart the server and check if it all works."
74
+ if hello_world_path
75
+ puts "You can now see the Hello World component on: #{hello_world_path}."
93
76
  end
77
+ puts "Happy coding!"
78
+ #exit
94
79
  end
95
80
 
96
- def create_svelte_hello_world
97
- file_path = Rails.root.join("app", "frontend", "javascript", "components", "HelloWorld.svelte")
98
- if File.exist?(file_path)
99
- puts "Hello World file already exists: file://#{file_path}"
100
- else
101
- File.write(file_path, <<~HTML)
102
- <script>
103
- export let items
104
- let count = 0;
105
-
106
- function increment() {
107
- count += 1;
108
- }
109
- </script>
110
-
111
- <h1>Greetings from svelte</h1>
112
-
113
- <button on:click={increment}>Increment: {count}</button>
114
- <ul>
115
- {#each items as item}
116
- <li>{item}</li>
117
- {/each}
118
- </ul>
119
-
120
- <style>
121
- button {
122
- background-color: darkred;
123
- color: white;
124
- padding: 10px;
125
- border: none;
126
- }
127
- </style>
128
- HTML
129
- puts "Hello World file at file://#{file_path}"
130
- end
131
- end
81
+ desc "Installs SvelteOnRails YAML configuration into your Rails application"
82
+ task :install do
132
83
 
133
- def create_file(file_path)
84
+ # svelte_on_rails
85
+
86
+ utils.write_templates(['config/svelte_on_rails.yml'])
87
+ npm_i.install_or_update_package('@csedl/svelte-on-rails')
134
88
 
135
- unless File.exist?(file_path)
136
- FileUtils.touch(file_path)
137
- puts "Created empty file at file://#{file_path}"
138
- end
139
89
  end
140
90
 
141
- def add_line_to_file(file_path, line)
142
- file_content = File.exist?(file_path) ? File.read(file_path) : ""
91
+ desc "Removes the Hello World component"
92
+ task :remove_hello_world do
143
93
 
144
- if file_content.match?(/#{line}/)
145
- puts "#{line} already present in #{file_path}, nothing changed here."
146
- return
147
- end
94
+ hw_i = SvelteOnRails::Installer::HelloWorld
95
+ hw_i.remove_hello_world
148
96
 
149
- File.open(file_path, 'a') do |file|
150
- file.puts(line)
151
- end
152
- puts "added #{line} to #{file_path}."
153
- rescue StandardError => e
154
- puts "Error: #{e.message}"
155
97
  end
156
98
 
157
- def create_folder(folder)
158
- if Dir.exist?(folder)
159
- puts "Folder already exists: #{folder}"
160
- else
161
- FileUtils.mkdir_p(folder)
162
- puts "Created folder: #{folder}"
99
+ desc "Add the Hello World component"
100
+ task :add_hello_world do
101
+
102
+ puts '-' * 80
103
+ if utils.ask_yn('Do you want to install the Hello World component?')
104
+ hw_i = SvelteOnRails::Installer::HelloWorld
105
+ hello_world_path = hw_i.install_hello_world
106
+ puts "You can now see the Hello World component on: #{hello_world_path}."
163
107
  end
108
+
164
109
  end
165
110
 
166
- def create_configuration_file
167
- config_path = Rails.root.join("config", "svelte_on_rails.yml")
168
- if File.exist?(config_path)
169
- puts "Configuration file already exists at file://#{config_path}"
170
- else
171
- File.write(config_path, <<~YAML)
172
-
173
- frontend_folder: "app/frontend"
174
- # the entrypoint that is your web root, example for vite: where @ points to
175
- # relative to Rails.root
176
-
177
- components_folder: "javascript/components"
178
- # relative to frontend_folder
179
- # where your svelte components are located
180
-
181
- render_server_side: :auto
182
- # options: true, false, :auto
183
- # :auto: render server side if request is initial request (works only with turbo, because it checks for the X-Turbo-Request-ID header)
184
- # when not server-side rendered the components must be built as custom elements, see node-package @csedl/svelte-on-rails
185
-
186
- development:
187
- watch_changes: true
188
- # Check on every request if any file within the svelte components folder have changed, for recompiling
189
- # Case sensitive path checking, even the file system is case insensitive
190
- # Make sure this ist set to tue for development and test, but not for production
191
-
192
- test:
193
- watch_changes: true
194
-
195
- production:
196
- YAML
197
- puts "Created configuration file at file://#{config_path}"
198
- end
111
+ desc "Compile all Svelte components"
112
+ task :reset_and_compile_all do
113
+ SvelteOnRails::RenderServerSide.reset_and_compile_all
199
114
  end
115
+
200
116
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svelte-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-17 00:00:00.000000000 Z
11
+ date: 2025-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -34,6 +34,19 @@ files:
34
34
  - lib/svelte-on-rails.rb
35
35
  - lib/svelte_on_rails/compile.js
36
36
  - lib/svelte_on_rails/configuration.rb
37
+ - lib/svelte_on_rails/installer/gem_utils.rb
38
+ - lib/svelte_on_rails/installer/haml.rb
39
+ - lib/svelte_on_rails/installer/hello_world.rb
40
+ - lib/svelte_on_rails/installer/javascript.rb
41
+ - lib/svelte_on_rails/installer/npm.rb
42
+ - lib/svelte_on_rails/installer/rails_template/app/controllers/svelte_on_rails_hello_world_controller.rb
43
+ - lib/svelte_on_rails/installer/rails_template/app/frontend/initializers/svelte.js
44
+ - lib/svelte_on_rails/installer/rails_template/app/frontend/javascript/components/SvelteOnRailsHelloWorld.svelte
45
+ - lib/svelte_on_rails/installer/rails_template/app/views/svelte_on_rails_hello_world/index.haml
46
+ - lib/svelte_on_rails/installer/rails_template/config/svelte_on_rails.yml
47
+ - lib/svelte_on_rails/installer/svelte.rb
48
+ - lib/svelte_on_rails/installer/utils.rb
49
+ - lib/svelte_on_rails/installer/vite.rb
37
50
  - lib/svelte_on_rails/node_modules/@ampproject/remapping/LICENSE
38
51
  - lib/svelte_on_rails/node_modules/@ampproject/remapping/README.md
39
52
  - lib/svelte_on_rails/node_modules/@ampproject/remapping/dist/remapping.mjs