svelte-on-rails 0.0.34 → 0.0.37
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 +4 -4
- data/README.md +38 -50
- data/lib/generators/svelte_on_rails/install/install_generator.rb +27 -8
- data/lib/svelte-on-rails.rb +0 -10
- data/lib/svelte_on_rails/installer/haml.rb +19 -13
- data/lib/svelte_on_rails/installer/hello_world.rb +8 -2
- data/lib/svelte_on_rails/installer/svelte.rb +1 -1
- data/lib/svelte_on_rails/installer/utils.rb +5 -5
- data/lib/svelte_on_rails/installer/vite.rb +1 -1
- data/lib/tasks/svelte_on_rails_tasks.rake +2 -32
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40380d23e1e5115506e76b3a03f7024ffe7817d28ef2ea807c555ef565547cb2
|
4
|
+
data.tar.gz: 8e20a2c5620788b190b43c5f0d072af21c0d96573dce9e5d15217d7027f65598
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0f10a0d977358a4a709882ae662ea9b53d0892ec89c2068b37aecd5648b534f759f9ea5279103bd736bc297dac8988441eee4739ce81d7386c58db046a73208
|
7
|
+
data.tar.gz: 62c4f47cd06a2d7ce3172b5829468847b328a7381f81db5219ddc24389f17660a49f4b026cdd8fcff46a608e36aa1e74f27ee97be7239476302c5d52da913173
|
data/README.md
CHANGED
@@ -72,7 +72,14 @@ The `--full` contains:
|
|
72
72
|
- `--hello-world`
|
73
73
|
- adds a hello world component
|
74
74
|
|
75
|
-
You can also use the options you want instead of using `--full
|
75
|
+
You can also use the options you want instead of using `--full`.
|
76
|
+
And there is the option `--force` that would not ask you whether it should overwrite existing files, for automated processes like testing.
|
77
|
+
|
78
|
+
This means, if you want all, except haml, you can run:
|
79
|
+
|
80
|
+
```bash
|
81
|
+
rails g svelte_on_rails:install --vite --turbo --svelte --hello-world --force
|
82
|
+
```
|
76
83
|
|
77
84
|
The installer is written carefully: It does not overwrite a file without asking.
|
78
85
|
It tells you all what he is doing.
|
@@ -90,13 +97,7 @@ and start coding.
|
|
90
97
|
|
91
98
|
## Minimal Installation
|
92
99
|
|
93
|
-
within
|
94
|
-
|
95
|
-
```bash
|
96
|
-
bundle add svelte-on-rails
|
97
|
-
```
|
98
|
-
|
99
|
-
Run the installer
|
100
|
+
For example, within a existing app, add the gem and run the installer without any options
|
100
101
|
|
101
102
|
```bash
|
102
103
|
rails g svelte_on_rails:install
|
@@ -230,11 +231,14 @@ rails svelte_on_rails:add_hello_world
|
|
230
231
|
rails svelte_on_rails:remove_hello_world
|
231
232
|
```
|
232
233
|
|
233
|
-
```bash
|
234
|
-
|
235
|
-
|
234
|
+
[//]: # (```bash)
|
235
|
+
|
236
|
+
[//]: # (rails svelte_on_rails:toggle_hello_world_svg)
|
237
|
+
|
238
|
+
[//]: # (```)
|
236
239
|
|
237
|
-
|
240
|
+
[//]: # ()
|
241
|
+
[//]: # (toggles the svg nested to the hello world component for check if thee svg is refreshed when imported image changes)
|
238
242
|
|
239
243
|
```bash
|
240
244
|
rails svelte_on_rails:reset_and_compile_all
|
@@ -257,53 +261,37 @@ Example from the rails console for a medium complex component
|
|
257
261
|
- => subsequent calls
|
258
262
|
- Completed 200 OK in 521ms (Views: 520.2ms | ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.3ms)
|
259
263
|
|
260
|
-
##
|
264
|
+
## Developers Guide
|
261
265
|
|
262
|
-
|
266
|
+
Tests are based on the included templates, like the `hello world template` and on the installer.
|
263
267
|
|
264
|
-
|
268
|
+
On the gem folder you can put a file `generated_test_app_path`, and put the path for a existing
|
269
|
+
folder where the tests generate a test rails app.
|
265
270
|
|
266
|
-
|
267
|
-
|
268
|
-
peer dependencies necessary for ssr tests, and some example components.
|
269
|
-
This is mainly for testing the compiler.
|
271
|
+
**Installer tests** starting with completely destroy the rails app within the `generated_test_app_path`,
|
272
|
+
generating a new rails app and running the installer and test by `playwright` if the components are working.
|
270
273
|
|
271
|
-
**
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
274
|
+
**component tests** only checking if a rails server is alive, and if not, install and run a rails app.
|
275
|
+
For this is the testing helper `start_rails_server_unless_ping`. This step may only be slow on the
|
276
|
+
first run, then it is fast. And on every repeating the test it always overwrites the components
|
277
|
+
with the components from the template by the testing helper `install_hello_world(
|
278
|
+
['rails_vite_hello_world'],
|
279
|
+
app_root: generated_rails_app_root,
|
280
|
+
force: true,
|
281
|
+
silent: true
|
282
|
+
)`. At the end of the test it leaves the rails server running.
|
276
283
|
|
284
|
+
On that way a developer can just edit the templates and run a test and see always the refreshed
|
285
|
+
content on the browser and on the app within the `generated_test_app_path`.
|
286
|
+
|
277
287
|
NOTE: Theese tests are dependend on your environment, including the running ruby version!
|
278
|
-
I am
|
288
|
+
I am working on rvm. If you work on a different environment, some (not many) changes may be necessary.
|
289
|
+
Thats your part :)
|
279
290
|
|
280
291
|
The current test cases including (among others):
|
281
292
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
Development helpers:
|
286
|
-
|
287
|
-
```bash
|
288
|
-
rake svelte_on_rails:create_test_app
|
289
|
-
```
|
290
|
-
|
291
|
-
This creates a new rails app within `spec/installer_tests` and runs the installer with `--full`.
|
292
|
-
On the last line it shows you the path to the test app.
|
293
|
-
Now you can cd into this folder and run `rails s`.
|
294
|
-
|
295
|
-
```bash
|
296
|
-
rake svelte_on_rails:replace_test_app_hello_world
|
297
|
-
```
|
298
|
-
|
299
|
-
Overwrites the hello world files within this test app from template.
|
300
|
-
|
301
|
-
As a rule of thumb, for **component tests**, before each test, templates are copied onto the tests-app, and be tested by playwright and the rails server should remain running at the end of each component test.
|
302
|
-
On that way the templates easily can be developped and tested, the end user has maximum function stability and the developer always see the latest changes.
|
303
|
-
|
304
|
-
Idea is to have all working examples within the template and included in the testing scope as in the hello world component.
|
305
|
-
|
306
|
-
... for having a 100% WYSIWYG and a easy maintainable package so that contributors are motivated to come into my project.
|
293
|
+
create a completely new rails app, running the full installer and check if a hello World component is visible and javascript is working.
|
294
|
+
run assets:precompile within a rails app and check if the gem does its precompiling too.
|
307
295
|
|
308
296
|
## Licence
|
309
297
|
|
@@ -5,6 +5,7 @@ module SvelteOnRails
|
|
5
5
|
class InstallGenerator < Rails::Generators::Base
|
6
6
|
|
7
7
|
class_option :full, type: :boolean, default: false, desc: "Run full installation with additional setup"
|
8
|
+
class_option :force, type: :boolean, default: false, desc: "Do not ask for overwriting files"
|
8
9
|
class_option :vite, type: :boolean, default: false, desc: "Use Vite"
|
9
10
|
class_option :haml, type: :boolean, default: false, desc: "Use Haml"
|
10
11
|
class_option :turbo, type: :boolean, default: false, desc: "Use @hotwired/turbo-rails"
|
@@ -20,24 +21,24 @@ module SvelteOnRails
|
|
20
21
|
validate_raw_options!(args)
|
21
22
|
puts '-' * 80
|
22
23
|
puts 'STARTING SVELTE-ON-RAILS INSTALLATION'
|
24
|
+
puts "FORCED (option --force was given)" if options[:force]
|
23
25
|
end
|
24
26
|
|
25
27
|
def vite
|
26
28
|
return unless options[:full] || options[:vite]
|
29
|
+
puts '-' * 80
|
30
|
+
puts '• INSTALLING VITE-RAILS'
|
27
31
|
vite_i = SvelteOnRails::Installer::Vite
|
28
32
|
vite_i.install_vite
|
29
33
|
end
|
30
34
|
|
31
|
-
def haml
|
32
|
-
return unless options[:full] || options[:haml]
|
33
|
-
haml_i = SvelteOnRails::Installer::Haml
|
34
|
-
haml_i.install_haml_and_convert
|
35
|
-
end
|
36
|
-
|
37
35
|
def svelte_on_rails
|
36
|
+
puts '-' * 80
|
37
|
+
puts ' ▶︎▶︎▶︎ INSTALLING SVELTE-ON-RAILS GEM'
|
38
|
+
|
38
39
|
utils = SvelteOnRails::Installer::Utils
|
39
40
|
npm_i = SvelteOnRails::Installer::Npm
|
40
|
-
utils.write_templates(['svelte_on_rails_vite_base'])
|
41
|
+
utils.write_templates(['svelte_on_rails_vite_base'], ask_for_overwrite: !options[:force])
|
41
42
|
npm_i.install_or_update_package('@csedl/svelte-on-rails')
|
42
43
|
# insert_initializer
|
43
44
|
uts = SvelteOnRails::Installer::Utils
|
@@ -50,6 +51,8 @@ module SvelteOnRails
|
|
50
51
|
def turbo
|
51
52
|
return unless options[:full] || options[:turbo]
|
52
53
|
|
54
|
+
puts '-' * 80
|
55
|
+
puts ' ▶︎▶︎▶︎ INSTALLING @hotwired/turbo-rails'
|
53
56
|
puts '-' * 80
|
54
57
|
npm_i = SvelteOnRails::Installer::Npm
|
55
58
|
tr_pkg = '@hotwired/turbo-rails'
|
@@ -62,6 +65,9 @@ module SvelteOnRails
|
|
62
65
|
def svelte
|
63
66
|
return unless options[:svelte] || options[:full]
|
64
67
|
|
68
|
+
puts '-' * 80
|
69
|
+
puts ' ▶︎▶︎▶︎ INSTALLING svelte (npm package)'
|
70
|
+
|
65
71
|
puts '-' * 80
|
66
72
|
svelte_i = SvelteOnRails::Installer::Svelte
|
67
73
|
svelte_i.install_svelte
|
@@ -70,15 +76,28 @@ module SvelteOnRails
|
|
70
76
|
def hello_world
|
71
77
|
return unless options[:hello_world] || options[:full]
|
72
78
|
|
79
|
+
puts '-' * 80
|
80
|
+
puts ' ▶︎▶︎▶︎︎ INSTALLING Hello World component'
|
73
81
|
puts '-' * 80
|
74
82
|
|
75
83
|
hw_i = SvelteOnRails::Installer::HelloWorld
|
76
84
|
@hello_world_path = hw_i.install_hello_world(['rails_vite_hello_world'], app_root: nil, force: true, silent: true)
|
77
85
|
end
|
78
86
|
|
87
|
+
def haml_and_convert
|
88
|
+
return unless options[:full] || options[:haml]
|
89
|
+
|
90
|
+
puts '-' * 80
|
91
|
+
puts ' ▶︎▶︎▶︎ INSTALLING Haml and converting existing .erb files to .haml'
|
92
|
+
|
93
|
+
haml_i = SvelteOnRails::Installer::Haml
|
94
|
+
haml_i.install_haml_and_convert(force: options[:force])
|
95
|
+
#haml_i.empty_test_methode
|
96
|
+
end
|
97
|
+
|
79
98
|
def finish
|
80
99
|
puts '-' * 80
|
81
|
-
puts 'FINISHED SVELTE INSTALLATION'
|
100
|
+
puts ' 👍 FINISHED SVELTE INSTALLATION 👍'
|
82
101
|
puts '-' * 80
|
83
102
|
|
84
103
|
puts "SvelteOnRails installed successfully!"
|
data/lib/svelte-on-rails.rb
CHANGED
@@ -37,14 +37,4 @@ module SvelteOnRails
|
|
37
37
|
puts "Error running create_test_app task: #{e.message}"
|
38
38
|
end
|
39
39
|
|
40
|
-
def self.run_replace_hello_world_task
|
41
|
-
# Ensure Rake tasks are loaded
|
42
|
-
Rake::Task.define_task(:environment) # Define a dummy environment task (if needed)
|
43
|
-
load File.expand_path('../rakefile', __FILE__) # Load the gem's Rakefile
|
44
|
-
|
45
|
-
# Invoke the task
|
46
|
-
Rake::Task['svelte_on_rails:replace_test_app_hello_world'].invoke
|
47
|
-
rescue StandardError => e
|
48
|
-
puts "Error running replace_test_app_hello_world task: #{e.message}"
|
49
|
-
end
|
50
40
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module SvelteOnRails
|
2
2
|
module Installer
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
class Haml
|
5
|
+
|
6
|
+
def self.install_haml_and_convert(force: false)
|
5
7
|
|
6
8
|
# install haml-rails
|
7
9
|
|
@@ -36,17 +38,19 @@ module SvelteOnRails
|
|
36
38
|
|
37
39
|
# ask if haml already exist
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
unless force
|
42
|
+
if existing_haml_files.any?
|
43
|
+
puts '-' * 80
|
44
|
+
begin
|
45
|
+
puts "Theare are already .haml files:"
|
46
|
+
puts existing_haml_files
|
47
|
+
puts "Would you like to continue? (y/n)"
|
48
|
+
continue = STDIN.gets.chomp.downcase[0]
|
49
|
+
end until ['y', 'n'].include?(continue)
|
50
|
+
if continue == 'n'
|
51
|
+
puts 'skipping convert to haml'
|
52
|
+
return
|
53
|
+
end
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
@@ -104,6 +108,8 @@ module SvelteOnRails
|
|
104
108
|
end
|
105
109
|
|
106
110
|
end
|
111
|
+
|
107
112
|
end
|
113
|
+
|
108
114
|
end
|
109
115
|
end
|
@@ -41,8 +41,7 @@ module SvelteOnRails
|
|
41
41
|
|
42
42
|
existing_files = files.dup.select { |f| File.exist?(f[2]) }
|
43
43
|
|
44
|
-
|
45
|
-
if ask
|
44
|
+
if ask && existing_files.any?
|
46
45
|
question = "Remove Hello World component?\nThe following files will be removed:\n#{existing_files.map { |f| f[1] }.join("\n")}"
|
47
46
|
return unless utils.ask_yn(question)
|
48
47
|
end
|
@@ -51,6 +50,13 @@ module SvelteOnRails
|
|
51
50
|
File.delete(f[2])
|
52
51
|
end
|
53
52
|
puts "Removed Hello World component files."
|
53
|
+
|
54
|
+
utils.remove_line_from_file(
|
55
|
+
utils.app_root_path(app_root).join('config/routes.rb'),
|
56
|
+
"svelte_on_rails_hello_world",
|
57
|
+
force: !ask,
|
58
|
+
)
|
59
|
+
|
54
60
|
end
|
55
61
|
|
56
62
|
end
|
@@ -173,13 +173,10 @@ module SvelteOnRails
|
|
173
173
|
|
174
174
|
def self.write_templates(templates, ask_for_overwrite: true, app_root: nil, silent: false)
|
175
175
|
|
176
|
-
|
177
176
|
paths = template_paths(templates, app_root: app_root)
|
178
177
|
|
179
|
-
|
180
178
|
existing = paths.dup.select { |p| File.exist?(p[2]) }
|
181
179
|
|
182
|
-
|
183
180
|
if existing.present? && ask_for_overwrite
|
184
181
|
begin
|
185
182
|
puts "#{'File'.pluralize(existing.length)} already exists:\n#{existing.map { |p| p[1] }.join("\n")}.\nOverwrite? (y/n)"
|
@@ -318,7 +315,7 @@ module SvelteOnRails
|
|
318
315
|
end
|
319
316
|
end
|
320
317
|
|
321
|
-
def self.remove_line_from_file(file_path, string_to_find)
|
318
|
+
def self.remove_line_from_file(file_path, string_to_find, force: false)
|
322
319
|
|
323
320
|
# Read the file content
|
324
321
|
content = File.read(file_path)
|
@@ -337,7 +334,10 @@ module SvelteOnRails
|
|
337
334
|
end
|
338
335
|
|
339
336
|
utils = SvelteOnRails::Installer::Utils
|
340
|
-
|
337
|
+
|
338
|
+
if found_lines.present?
|
339
|
+
return if !force && utils.ask_yn("Remove lines\n • #{found_lines.join("\n • ")}\n from #{file_path}?")
|
340
|
+
|
341
341
|
# Write the modified content back to the file
|
342
342
|
begin
|
343
343
|
File.write(file_path, modified_content.map { |l| l.gsub(/\n/, '') }.join("\n"))
|
@@ -20,8 +20,7 @@ namespace :svelte_on_rails do
|
|
20
20
|
task :remove_hello_world do
|
21
21
|
|
22
22
|
hw_i = SvelteOnRails::Installer::HelloWorld
|
23
|
-
|
24
|
-
hw_i.remove_hello_world(f.uniq)
|
23
|
+
hw_i.remove_hello_world(['rails_vite_hello_world'])
|
25
24
|
|
26
25
|
end
|
27
26
|
|
@@ -30,7 +29,7 @@ namespace :svelte_on_rails do
|
|
30
29
|
|
31
30
|
puts '-' * 80
|
32
31
|
hw_i = SvelteOnRails::Installer::HelloWorld
|
33
|
-
hello_world_path = hw_i.install_hello_world(
|
32
|
+
hello_world_path = hw_i.install_hello_world(['rails_vite_hello_world'])
|
34
33
|
puts "You can now see the Hello World component on: #{hello_world_path}."
|
35
34
|
|
36
35
|
end
|
@@ -72,33 +71,4 @@ namespace :svelte_on_rails do
|
|
72
71
|
SvelteOnRails::Compiler.reset_and_compile_all
|
73
72
|
end
|
74
73
|
|
75
|
-
desc "Build test app within spec/installer_tests"
|
76
|
-
task :create_test_app do
|
77
|
-
TestHelpers.cleanup_rails_app
|
78
|
-
TestHelpers.create_rails_app
|
79
|
-
TestHelpers.gem_setup("rails g svelte_on_rails:install --full")
|
80
|
-
puts '-'*80
|
81
|
-
puts "Built test app successfully!"
|
82
|
-
puts "You can now run the server by:"
|
83
|
-
puts "$ cd #{TestHelpers.installer_test_app_path} && rails s"
|
84
|
-
end
|
85
|
-
|
86
|
-
desc "Build test app within spec/installer_tests"
|
87
|
-
task :replace_test_app_hello_world do
|
88
|
-
#require_relative '../../lib/svelte_on_rails/lib/utils'
|
89
|
-
require_relative '../../spec/test_helpers'
|
90
|
-
th = TestHelpers
|
91
|
-
puts '-'*80
|
92
|
-
hw_i = SvelteOnRails::Installer::HelloWorld
|
93
|
-
#utils = SvelteOnRails::Lib::Utils
|
94
|
-
@hello_world_path = hw_i.install_hello_world(
|
95
|
-
SvelteOnRails::Generators::InstallGenerator::HELLO_WORLD_FILES,
|
96
|
-
app_root: th.installer_test_app_path,
|
97
|
-
force: true,
|
98
|
-
)
|
99
|
-
|
100
|
-
puts '-'*80
|
101
|
-
puts "replaced Hello World component with new one"
|
102
|
-
end
|
103
|
-
|
104
74
|
end
|