svelte-on-rails 0.0.35 → 0.0.38
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 +70 -54
- data/lib/generators/svelte_on_rails/install/install_generator.rb +58 -23
- data/lib/svelte_on_rails/installer/haml.rb +29 -23
- data/lib/svelte_on_rails/installer/hello_world.rb +8 -2
- data/lib/svelte_on_rails/installer/npm.rb +20 -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 -3
- 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: 3ea01d9d31034ea4eb76064bd7947394193f3dc3c91490b1277ea3a1be19c80d
|
4
|
+
data.tar.gz: 07acb2b48f892a11aadab9f947842eabe7e100ab422a1afb54ace9fa3d1747d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd78111558fc3bf309395060ebff3cce856ae0e8e60436f923733c7fa818cdd9b5d8171fb8301be72e44c5ad287593e2c8c822a52342f2fd563386b3bc34b181
|
7
|
+
data.tar.gz: 14ba621d1cbf026908d90834f2a99b98953d218f60cd87ed3e14fa40c2bb5c3acc876950a7b7bb35c366cee62f801f281eeef3f9f63daf06b97dbdd722e11da1
|
data/README.md
CHANGED
@@ -6,12 +6,12 @@ By default, and when installed together with `@hotwired/turbo-rails`, it renders
|
|
6
6
|
svelte components on first request server side («SSR») and for subsequent
|
7
7
|
requests it provides a empty tag that will be mounted on the frontend by the associated npm package [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails) on the frontend.
|
8
8
|
|
9
|
-
This way svelte works perfectly together with turbo. You will never notice
|
9
|
+
This way svelte works perfectly together with turbo. You will never notice
|
10
10
|
this unpleasant «blink» on the frontend and it is maximum performance
|
11
11
|
optimized. SSR compilation is handled by rollup.
|
12
12
|
|
13
|
-
Server-side rendering is the bottleneck on such a pipeline.
|
14
|
-
Although rollup is powerful, this gem is in an early state
|
13
|
+
Server-side rendering is the bottleneck on such a pipeline.
|
14
|
+
Although rollup is powerful, this gem is in an early state
|
15
15
|
and there may be limitations.
|
16
16
|
|
17
17
|
Javascript is written in ESM syntax, orientated by the functionality of vite.
|
@@ -22,7 +22,7 @@ But we have done everything we can to make your setup work smoothly.
|
|
22
22
|
|
23
23
|
This all is developed on Rails-7 together with `vite_rails`.
|
24
24
|
|
25
|
-
Thanks to [shakacode](https://github.com/shakacode/react_on_rails)
|
25
|
+
Thanks to [shakacode](https://github.com/shakacode/react_on_rails)
|
26
26
|
and [ElMassimo](https://github.com/ElMassimo) because they all helped me with theyr gems.
|
27
27
|
|
28
28
|
If you have issues, please open one and contributors are welcome!
|
@@ -33,7 +33,7 @@ If you have issues, please open one and contributors are welcome!
|
|
33
33
|
- tested on ruby 3.2.2 and rails 7.1
|
34
34
|
- svelte v5 (see: [how to install svelte on rails/vite](https://dev.to/chmich/setup-inertia-and-svelte-on-rails-7-3glk))
|
35
35
|
- turbo (recommended / [how to install turbo on rails](https://github.com/hotwired/turbo-rails?tab=readme-ov-file#installation))
|
36
|
-
- if you use special packages (like pug) that requires commonjs, you may need
|
36
|
+
- if you use special packages (like pug) that requires commonjs, you may need
|
37
37
|
|
38
38
|
## Installation from cero
|
39
39
|
|
@@ -59,20 +59,27 @@ rails g svelte_on_rails:install --full
|
|
59
59
|
|
60
60
|
The `--full` contains:
|
61
61
|
|
62
|
-
- `--vite`
|
62
|
+
- `--vite`
|
63
63
|
- adds vite_rails gem and running the installer
|
64
|
-
- `--haml`
|
64
|
+
- `--haml`
|
65
65
|
- adds the gem and converts existing views
|
66
|
-
- `svelte_on_rails`
|
66
|
+
- `svelte_on_rails`
|
67
67
|
- This is not a option, this is always done: Adds a config file and installs `@csedl/svelte-on-rails` by npm
|
68
|
-
- `--turbo`
|
68
|
+
- `--turbo`
|
69
69
|
- installs `@hotwired/turbo-rails` and adds import statement to application.js
|
70
|
-
- `--svelte`
|
70
|
+
- `--svelte`
|
71
71
|
- adds or updates `svelte`
|
72
|
-
- `--hello-world`
|
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
|
@@ -122,17 +123,17 @@ On loading you will see
|
|
122
123
|
|
123
124
|
- Rendered HelloWorld.svelte server-side: 0.075ms
|
124
125
|
|
125
|
-
On the rails console and you will see «Greetings from svelte»
|
126
|
+
On the rails console and you will see «Greetings from svelte»
|
126
127
|
on your view with a styled «Increment» button.
|
127
128
|
Styles you find within the svelte component.
|
128
129
|
Click this button and see that the component is alive.
|
129
130
|
|
130
|
-
On [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails)
|
131
|
+
On [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails)
|
131
132
|
are details how the frontend part is working.
|
132
133
|
|
133
|
-
Without the npm package installed,
|
134
|
+
Without the npm package installed,
|
134
135
|
or by passing `ssr: true` and `hydrate: false` to the view helper,
|
135
|
-
you would see the same html, and the styled button,
|
136
|
+
you would see the same html, and the styled button,
|
136
137
|
but the increment button would not work.
|
137
138
|
|
138
139
|
I inserted very detailed error messages on rails and on the
|
@@ -141,7 +142,7 @@ So please check the logs on your browser.
|
|
141
142
|
|
142
143
|
### Import statements
|
143
144
|
|
144
|
-
For check which statements are working and actively tested, please check the
|
145
|
+
For check which statements are working and actively tested, please check the
|
145
146
|
[components folder](https://gitlab.com/sedl/svelte-on-rails/-/tree/main/spec/rails-vite-test-app/app/frontend/javascript/components?ref_type=heads) within the gem specs.
|
146
147
|
|
147
148
|
Among others there are
|
@@ -155,7 +156,7 @@ Among others there are
|
|
155
156
|
|
156
157
|
When the rails app runs `assets:precompile` a additional rake task is triggered: `rails svelte_on_rails:reset_and_compile_all`.
|
157
158
|
|
158
|
-
This is not absolutely necessary but it reduces the loading time of the very first calling of the first component.
|
159
|
+
This is not absolutely necessary but it reduces the loading time of the very first calling of the first component.
|
159
160
|
So, on deploying or doing `rails assets:precompile` you shoud see something like:
|
160
161
|
|
161
162
|
```
|
@@ -175,7 +176,7 @@ on the console.
|
|
175
176
|
|
176
177
|
Works with `hotwired/turbo` only
|
177
178
|
|
178
|
-
By passing the `ssr: :auto` option to the view helper,
|
179
|
+
By passing the `ssr: :auto` option to the view helper,
|
179
180
|
it checks if the request is an initial request (request header `X-Turbo-Request-ID` is present):
|
180
181
|
|
181
182
|
On Initial-Request, it adds the attribute `data-svelte-on-rails-initialize-action="hydrate"` and
|
@@ -199,23 +200,23 @@ You can simply work with global styles as well as styles within the svelte compo
|
|
199
200
|
|
200
201
|
A server-side rendered svelte component has 2 states:
|
201
202
|
|
202
|
-
#### Before hydration
|
203
|
+
#### Before hydration
|
203
204
|
|
204
|
-
- The `svelte_component` view helper renders the styles contained within the component
|
205
|
-
into a style tag within the component's wrapper element. This has to be done this way because of Turbo.
|
205
|
+
- The `svelte_component` view helper renders the styles contained within the component
|
206
|
+
into a style tag within the component's wrapper element. This has to be done this way because of Turbo.
|
206
207
|
- In very, very rare cases, global styles are not applied in the same way as after hydration.
|
207
208
|
|
208
|
-
#### After hydration
|
209
|
+
#### After hydration
|
209
210
|
|
210
|
-
- Svelte adds a style tag inside the header
|
211
|
+
- Svelte adds a style tag inside the header
|
211
212
|
- Svelte renders the component again, which removes the style tag inside the component wrapper.
|
212
213
|
|
213
|
-
#### If you notice a "blink"
|
214
|
+
#### If you notice a "blink"
|
214
215
|
|
215
|
-
For the app to look stable, both states must appear in the same way.
|
216
|
-
Normally this is the case. But if there are problems,
|
217
|
-
or you want to see the state before hydration, for development purposes, you can pass
|
218
|
-
the `hydrate: false` option to the view helper,
|
216
|
+
For the app to look stable, both states must appear in the same way.
|
217
|
+
Normally this is the case. But if there are problems,
|
218
|
+
or you want to see the state before hydration, for development purposes, you can pass
|
219
|
+
the `hydrate: false` option to the view helper,
|
219
220
|
and no hydration will happen for this component.
|
220
221
|
|
221
222
|
## More rake tasks
|
@@ -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
|
@@ -242,7 +246,7 @@ rails svelte_on_rails:reset_and_compile_all
|
|
242
246
|
|
243
247
|
This does the same step that ist triggered together with the
|
244
248
|
`rails assets:precompile` step together with the deployment pipeline:
|
245
|
-
it removes all contents of the svelte-on-rails compiled
|
249
|
+
it removes all contents of the svelte-on-rails compiled
|
246
250
|
assets and compiles them all new.
|
247
251
|
|
248
252
|
## Performance
|
@@ -257,24 +261,29 @@ 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
|
+
## Contributors Guide
|
261
265
|
|
262
266
|
Tests are based on the included templates, like the `hello world template` and on the installer.
|
263
267
|
|
264
|
-
|
265
|
-
|
266
|
-
The string there must represent a full path to a existing folder.
|
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.
|
267
270
|
|
268
|
-
|
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.
|
273
|
+
|
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.
|
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`.
|
269
286
|
|
270
|
-
- run a component test
|
271
|
-
- the first run is slow because the installer must build the app
|
272
|
-
- the second run is fast because the app is already built
|
273
|
-
- open the browser by localhost:3000
|
274
|
-
- change the component
|
275
|
-
- run the component test again
|
276
|
-
- see the changes in the browser
|
277
|
-
|
278
287
|
NOTE: Theese tests are dependend on your environment, including the running ruby version!
|
279
288
|
I am working on rvm. If you work on a different environment, some (not many) changes may be necessary.
|
280
289
|
Thats your part :)
|
@@ -284,6 +293,13 @@ The current test cases including (among others):
|
|
284
293
|
create a completely new rails app, running the full installer and check if a hello World component is visible and javascript is working.
|
285
294
|
run assets:precompile within a rails app and check if the gem does its precompiling too.
|
286
295
|
|
296
|
+
For development of the **npm package @csedl/svelte-on-rails** you can add the file
|
297
|
+
`local_npm_package_path` and insert the path to the npm package on your local machine.
|
298
|
+
This will cause the installer, not to install the npm package from npm, but to use the local one.
|
299
|
+
|
300
|
+
‼️ **ATTENTION:** Please do never commit the file `local_npm_package_path` to the repo! This is only for developers!
|
301
|
+
Otherwise a user would, on running the installer, get an error, because the npm package is not found.
|
302
|
+
|
287
303
|
## Licence
|
288
304
|
|
289
305
|
License is MIT
|
@@ -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"
|
@@ -15,32 +16,62 @@ module SvelteOnRails
|
|
15
16
|
require 'svelte_on_rails/installer/haml'
|
16
17
|
require_relative '../../../../spec/test_helpers'
|
17
18
|
|
19
|
+
NPM_PACKAGE_NAME = '@csedl/svelte-on-rails'
|
20
|
+
|
18
21
|
def initialize(*args)
|
19
22
|
super
|
20
23
|
validate_raw_options!(args)
|
21
24
|
puts '-' * 80
|
25
|
+
puts '-' * 80
|
22
26
|
puts 'STARTING SVELTE-ON-RAILS INSTALLATION'
|
27
|
+
puts " • FORCED (option --force was given)" if options[:force]
|
28
|
+
if TestHelpers.local_npm_package_url
|
29
|
+
puts " • Local Npm Package used: #{NPM_PACKAGE_NAME} used: #{TestHelpers.local_npm_package_url}"
|
30
|
+
end
|
31
|
+
puts '-' * 80
|
32
|
+
|
23
33
|
end
|
24
34
|
|
25
35
|
def vite
|
26
36
|
return unless options[:full] || options[:vite]
|
37
|
+
puts '-' * 80
|
38
|
+
puts '• INSTALLING VITE-RAILS'
|
27
39
|
vite_i = SvelteOnRails::Installer::Vite
|
28
40
|
vite_i.install_vite
|
29
41
|
end
|
30
42
|
|
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
43
|
def svelte_on_rails
|
44
|
+
|
45
|
+
puts '-' * 80
|
46
|
+
puts ' ▶︎▶︎▶︎ INSTALLING SVELTE-ON-RAILS GEM'
|
47
|
+
|
38
48
|
utils = SvelteOnRails::Installer::Utils
|
39
49
|
npm_i = SvelteOnRails::Installer::Npm
|
40
|
-
utils.write_templates(['svelte_on_rails_vite_base'])
|
41
|
-
|
50
|
+
utils.write_templates(['svelte_on_rails_vite_base'], ask_for_overwrite: !options[:force])
|
51
|
+
if TestHelpers.local_npm_package_url
|
52
|
+
puts '☝️ <<<'
|
53
|
+
puts 'LINK LOCAL PACKAGE'
|
54
|
+
puts 'BUGFIX: npm does not install peer dependencies of local linked packages!'
|
55
|
+
puts ' For packages from the registry, this does since newer versins of npm.'
|
56
|
+
puts ' So we need to install the peer dependencies manually.'
|
57
|
+
npm_i.install_or_update_package('rollup-plugin-svelte', dev_dependency: true)
|
58
|
+
npm_i.install_or_update_package('rollup', dev_dependency: true)
|
59
|
+
npm_i.install_or_update_package('@rollup/plugin-node-resolve', dev_dependency: true)
|
60
|
+
npm_i.install_or_update_package('@rollup/plugin-commonjs', dev_dependency: true)
|
61
|
+
npm_i.install_or_update_package('@rollup/plugin-url', dev_dependency: true)
|
62
|
+
npm_i.install_or_update_package('rollup-plugin-css-only', dev_dependency: true)
|
63
|
+
npm_i.install_or_update_package('rollup-plugin-string', dev_dependency: true)
|
64
|
+
npm_i.install_or_update_package('svelte-preprocess', dev_dependency: true)
|
65
|
+
npm_i.install_or_update_package('pug', dev_dependency: true)
|
66
|
+
npm_i.install_or_update_package('typescript', dev_dependency: true)
|
67
|
+
puts '☝️ >>>'
|
68
|
+
npm_i.link_local_package(NPM_PACKAGE_NAME, TestHelpers.local_npm_package_url)
|
69
|
+
else
|
70
|
+
npm_i.install_or_update_package(NPM_PACKAGE_NAME)
|
71
|
+
end
|
72
|
+
|
42
73
|
# insert_initializer
|
43
|
-
uts = SvelteOnRails::Installer::Utils
|
74
|
+
#uts = SvelteOnRails::Installer::Utils
|
44
75
|
# add import statements
|
45
76
|
js_i = SvelteOnRails::Installer::Javascript
|
46
77
|
init_stat = '../initializers/svelte.js'
|
@@ -50,6 +81,8 @@ module SvelteOnRails
|
|
50
81
|
def turbo
|
51
82
|
return unless options[:full] || options[:turbo]
|
52
83
|
|
84
|
+
puts '-' * 80
|
85
|
+
puts ' ▶︎▶︎▶︎ INSTALLING @hotwired/turbo-rails'
|
53
86
|
puts '-' * 80
|
54
87
|
npm_i = SvelteOnRails::Installer::Npm
|
55
88
|
tr_pkg = '@hotwired/turbo-rails'
|
@@ -62,6 +95,9 @@ module SvelteOnRails
|
|
62
95
|
def svelte
|
63
96
|
return unless options[:svelte] || options[:full]
|
64
97
|
|
98
|
+
puts '-' * 80
|
99
|
+
puts ' ▶︎▶︎▶︎ INSTALLING svelte (npm package)'
|
100
|
+
|
65
101
|
puts '-' * 80
|
66
102
|
svelte_i = SvelteOnRails::Installer::Svelte
|
67
103
|
svelte_i.install_svelte
|
@@ -70,15 +106,27 @@ module SvelteOnRails
|
|
70
106
|
def hello_world
|
71
107
|
return unless options[:hello_world] || options[:full]
|
72
108
|
|
109
|
+
puts '-' * 80
|
110
|
+
puts ' ▶︎▶︎▶︎︎ INSTALLING Hello World component'
|
73
111
|
puts '-' * 80
|
74
112
|
|
75
113
|
hw_i = SvelteOnRails::Installer::HelloWorld
|
76
114
|
@hello_world_path = hw_i.install_hello_world(['rails_vite_hello_world'], app_root: nil, force: true, silent: true)
|
77
115
|
end
|
78
116
|
|
117
|
+
def haml_and_convert
|
118
|
+
return unless options[:full] || options[:haml]
|
119
|
+
|
120
|
+
puts '-' * 80
|
121
|
+
puts ' ▶︎▶︎▶︎ INSTALLING Haml and converting existing .erb files to .haml'
|
122
|
+
|
123
|
+
haml_i = SvelteOnRails::Installer::Haml
|
124
|
+
haml_i.install_haml_and_convert(force: options[:force])
|
125
|
+
end
|
126
|
+
|
79
127
|
def finish
|
80
128
|
puts '-' * 80
|
81
|
-
puts 'FINISHED SVELTE INSTALLATION'
|
129
|
+
puts ' 👍 FINISHED SVELTE INSTALLATION 👍'
|
82
130
|
puts '-' * 80
|
83
131
|
|
84
132
|
puts "SvelteOnRails installed successfully!"
|
@@ -89,19 +137,6 @@ module SvelteOnRails
|
|
89
137
|
puts "Happy coding!"
|
90
138
|
end
|
91
139
|
|
92
|
-
# HELLO_WORLD_FILES = %w[
|
93
|
-
# app/controllers/svelte_on_rails_hello_world_controller.rb
|
94
|
-
# app/views/svelte_on_rails_hello_world/index.haml
|
95
|
-
# app/frontend/javascript/components/SvelteOnRailsHelloWorld.svelte
|
96
|
-
# app/frontend/javascript/components/Pug.svelte
|
97
|
-
# app/frontend/javascript/components/sub/NestedComponent.svelte
|
98
|
-
# app/frontend/javascript/nestedJavascript.js
|
99
|
-
# app/frontend/javascript/nestedJavascriptToggled.js
|
100
|
-
# app/frontend/javascript/components/sub/NestedComponent.svelte
|
101
|
-
# app/frontend/images/svg.svg
|
102
|
-
# app/frontend/images/check-circle-green.png
|
103
|
-
# ]
|
104
|
-
|
105
140
|
private
|
106
141
|
|
107
142
|
def toggle_hello_world_files
|
@@ -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,30 +38,32 @@ 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
|
-
end
|
52
55
|
|
53
|
-
|
56
|
+
# ask if overwrite
|
54
57
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
if overwrite_files.any?
|
59
|
+
puts '-' * 80
|
60
|
+
begin
|
61
|
+
puts "The following files already exist and would be overwritten:"
|
62
|
+
puts overwrite_files
|
63
|
+
puts "Would you like to overwrite these .haml files? (y/n)"
|
64
|
+
should_overwrite = STDIN.gets.chomp.downcase[0]
|
65
|
+
end until ['y', 'n'].include?(should_overwrite)
|
66
|
+
end
|
63
67
|
end
|
64
68
|
|
65
69
|
puts '-' * 80
|
@@ -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
|
@@ -2,13 +2,14 @@ module SvelteOnRails
|
|
2
2
|
module Installer
|
3
3
|
module Npm
|
4
4
|
|
5
|
-
def self.install_or_update_package(package_name, minimal_version: nil, update_to_latest: true)
|
5
|
+
def self.install_or_update_package(package_name, minimal_version: nil, update_to_latest: true, dev_dependency: false )
|
6
6
|
pkg = inspect_package(package_name)
|
7
7
|
to_do = !check_version((pkg ? pkg[:version] : nil), minimal_version)
|
8
|
+
save_dev = (dev_dependency ? ' --save-dev' : '')
|
8
9
|
if to_do
|
9
10
|
|
10
11
|
cmd = if update_to_latest
|
11
|
-
"npm install #{package_name}@latest"
|
12
|
+
"npm install #{package_name}@latest#{save_dev}"
|
12
13
|
else
|
13
14
|
raise "ERROR: not implemented"
|
14
15
|
end
|
@@ -34,6 +35,23 @@ module SvelteOnRails
|
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
38
|
+
def self.link_local_package(package_name, local_package_url)
|
39
|
+
Dir.chdir(local_package_url) do
|
40
|
+
`npm link`
|
41
|
+
end
|
42
|
+
Dir.chdir(Rails.root) do
|
43
|
+
# Instead of just `npm link`, use `npm install` to add the local package to package.json
|
44
|
+
`npm install #{local_package_url} --save`
|
45
|
+
stdout, stderr, status = Open3.capture3("npm ls #{package_name}")
|
46
|
+
if stderr.present?
|
47
|
+
raise "ERROR: npm link failed for #{package_name} => #{stderr}"
|
48
|
+
end
|
49
|
+
puts "Successfully linked #{package_name} to #{local_package_url}"
|
50
|
+
puts " • `npm ls #{package_name}` => «#{stdout}»"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
37
55
|
def self.inspect_package(package_name)
|
38
56
|
pkg = nil
|
39
57
|
version = nil
|
@@ -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
|