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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fdbb3868bbac50f65971957df0748db4c578fc317bab77065e64155b5d9c2d9
4
- data.tar.gz: b30194ddee3daf2742d1d21e3d63ca835ff60123f6514dade9c5b6d930e0bc82
3
+ metadata.gz: 40380d23e1e5115506e76b3a03f7024ffe7817d28ef2ea807c555ef565547cb2
4
+ data.tar.gz: 8e20a2c5620788b190b43c5f0d072af21c0d96573dce9e5d15217d7027f65598
5
5
  SHA512:
6
- metadata.gz: dbf57486fba0f80bb50077243d7781b3d4ea3e21adf8c98dd54a6df7e71c416db846072e515c85296652db815d8b0423c528491ec5560edd998bdd614d28ad76
7
- data.tar.gz: 9db84e5d1ad4f60cc0a9bb1e5c69c81f40a1c2466fc67f4f27faa8a53148f66f2cfe5636884960573db1e8f99d8d4e8223fe3534f1083d0297732970b4172df1
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 the app folder
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
- rails svelte_on_rails:toggle_hello_world_svg
235
- ```
234
+ [//]: # (```bash)
235
+
236
+ [//]: # (rails svelte_on_rails:toggle_hello_world_svg)
237
+
238
+ [//]: # (```)
236
239
 
237
- toggles the svg nested to the hello world component for check if thee svg is refreshed when imported image changes
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
- ## Testing
264
+ ## Developers Guide
261
265
 
262
- Testings are within the gem by `rspec`. Mainly there are 2 types of tests:
266
+ Tests are based on the included templates, like the `hello world template` and on the installer.
263
267
 
264
- **compiler tests**
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
- The folder `spec/rails_vite_test_app` holds a package.json
267
- with the `@csedl/svelte-on-rails` package, mainly because of the
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
- **Fully complete tests**
272
-
273
- The folder `spec/installer_tests`, mainly, is emptied
274
- before test. Tests there are starting by `rails new` followed
275
- by running the installer.
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 woring on `rvm` If you work on a different environment, tests may have to be adopted.
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
- - create a completely new rails app, running the full installer and check if a `hello World` component is visible and javascript is working.
283
- - run `assets:precompile` within a rails app and check if the gem does its precompiling too.
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!"
@@ -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
- module Haml
4
- def self.install_haml_and_convert
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
- if existing_haml_files.any?
40
- puts '-' * 80
41
- begin
42
- puts "Theare are already .haml files:"
43
- puts existing_haml_files
44
- puts "Would you like to continue? (y/n)"
45
- continue = STDIN.gets.chomp.downcase[0]
46
- end until ['y', 'n'].include?(continue)
47
- if continue == 'n'
48
- puts 'skipping convert to haml'
49
- return
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
- return unless existing_files.any?
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
@@ -2,7 +2,7 @@ module SvelteOnRails
2
2
  module Installer
3
3
  module Svelte
4
4
 
5
- def self.install_svelte
5
+ def self.install_svelte(force: false)
6
6
  puts '-' * 80
7
7
 
8
8
  # check npm package version
@@ -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
- if found_lines.present? && utils.ask_yn("Remove lines\n • #{found_lines.join("\n • ")}\n from #{file_path}?")
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"))
@@ -48,7 +48,7 @@ module SvelteOnRails
48
48
 
49
49
  end
50
50
 
51
- def self.configure_for_svelte
51
+ def self.configure_for_svelte(force: false)
52
52
 
53
53
  # add import statement
54
54
 
@@ -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
- f = hello_world_files + toggle_hello_world_files
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(hello_world_files)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svelte-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.34
4
+ version: 0.0.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair